वीडियो जनरेट करने के बारे में जानने के लिए, Veo की गाइड देखें.
Gemini मॉडल, वीडियो प्रोसेस कर सकते हैं. इससे डेवलपर, कई ऐसे इस्तेमाल के मामले में काम कर सकते हैं जिनके लिए पहले, डोमेन के हिसाब से मॉडल की ज़रूरत होती थी. Gemini की विज़न से जुड़ी कुछ क्षमताओं में ये शामिल हैं: वीडियो के बारे में बताना, वीडियो को सेगमेंट में बांटना, वीडियो से जानकारी निकालना, वीडियो के कॉन्टेंट के बारे में सवालों के जवाब देना, और वीडियो में मौजूद किसी खास टाइमस्टैंप के बारे में बताना.
Gemini को इन तरीकों से वीडियो इनपुट के तौर पर दिया जा सकता है:
| इनपुट विधि | सबसे बड़ा साइज़ | सुझाया गया इस्तेमाल का मामला |
|---|---|---|
| फ़ाइल एपीआई | 20 जीबी (पैसे चुकाकर) / 2 जीबी (मुफ़्त) | बड़ी फ़ाइलें (100 एमबी से ज़्यादा), लंबे वीडियो (10 मिनट से ज़्यादा), बार-बार इस्तेमाल की जा सकने वाली फ़ाइलें. |
| Cloud Storage में रजिस्टर करना | हर फ़ाइल के लिए 2 जीबी (स्टोरेज की कोई सीमा नहीं) | बड़ी फ़ाइलें (100 एमबी से ज़्यादा), लंबे वीडियो (10 मिनट से ज़्यादा), बार-बार इस्तेमाल की जा सकने वाली फ़ाइलें. |
| इनलाइन डेटा | 100 एमबी से कम | छोटी फ़ाइलें (100 एमबी से कम), कम अवधि वाले वीडियो (एक मिनट से कम), एक बार इस्तेमाल किए जाने वाले इनपुट. |
| YouTube के यूआरएल | लागू नहीं | YouTube पर सार्वजनिक तौर पर उपलब्ध वीडियो. |
ध्यान दें: ज़्यादातर इस्तेमाल के मामलों के लिए, फ़ाइल एपीआई का इस्तेमाल करने का सुझाव दिया जाता है. खास तौर पर, 100 एमबी से बड़ी फ़ाइलों के लिए या जब आपको एक से ज़्यादा अनुरोधों में फ़ाइल का फिर से इस्तेमाल करना हो.
वीडियो फ़ाइल अपलोड करना
यहां दिया गया कोड, एक सैंपल वीडियो डाउनलोड करता है. इसके बाद, Files API का इस्तेमाल करके उसे अपलोड करता है. फिर, वीडियो के प्रोसेस होने का इंतज़ार करता है. इसके बाद, अपलोड की गई फ़ाइल के रेफ़रंस का इस्तेमाल करके, वीडियो की खास जानकारी देता है.
Python
from google import genai
import base64
import time
client = genai.Client()
myfile = client.files.upload(file="path/to/sample.mp4")
while not myfile.state or myfile.state.name != "ACTIVE":
print("Processing video...")
time.sleep(5)
myfile = client.files.get(name=myfile.name)
interaction = client.interactions.create(
model="gemini-3.6-flash",
input=[
{"type": "video", "uri": myfile.uri, "mime_type": myfile.mime_type},
{"type": "text", "text": "Summarize this video. Then create a quiz with an answer key based on the information in this video."}
]
)
print(interaction.output_text)
JavaScript
import { GoogleGenAI } from "@google/genai";
const ai = new GoogleGenAI({});
async function main() {
const myfile = await ai.files.upload({
file: "path/to/sample.mp4",
config: { mimeType: "video/mp4" },
});
let getFile = await ai.files.get({ name: myfile.name });
while (getFile.state === 'PROCESSING') {
getFile = await ai.files.get({ name: myfile.name });
console.log(`current file status: ${getFile.state}`);
console.log('File is still processing, retrying in 5 seconds');
await new Promise((resolve) => {
setTimeout(resolve, 5000);
});
}
if (getFile.state === 'FAILED') {
throw new Error('File processing failed.');
}
const interaction = await ai.interactions.create({
model: "gemini-3.6-flash",
input: [
{ type: "video", uri: myfile.uri, mime_type: myfile.mimeType },
{ type: "text", text: "Summarize this video. Then create a quiz with an answer key based on the information in this video." }
],
});
console.log(interaction.output_text);
}
await main();
REST
VIDEO_PATH="path/to/sample.mp4"
MIME_TYPE=$(file -b --mime-type "${VIDEO_PATH}")
NUM_BYTES=$(wc -c < "${VIDEO_PATH}")
DISPLAY_NAME=VIDEO
tmp_header_file=upload-header.tmp
echo "Starting file upload..."
curl "https://generativelanguage.googleapis.com/upload/v1beta/files" \
-H "x-goog-api-key: $GEMINI_API_KEY" \
-D ${tmp_header_file} \
-H "X-Goog-Upload-Protocol: resumable" \
-H "X-Goog-Upload-Command: start" \
-H "X-Goog-Upload-Header-Content-Length: ${NUM_BYTES}" \
-H "X-Goog-Upload-Header-Content-Type: ${MIME_TYPE}" \
-H "Content-Type: application/json" \
-d "{'file': {'display_name': '${DISPLAY_NAME}'}}" 2> /dev/null
upload_url=$(grep -i "x-goog-upload-url: " "${tmp_header_file}" | cut -d" " -f2 | tr -d "\r")
rm "${tmp_header_file}"
echo "Uploading video data..."
curl "${upload_url}" \
-H "Content-Length: ${NUM_BYTES}" \
-H "X-Goog-Upload-Offset: 0" \
-H "X-Goog-Upload-Command: upload, finalize" \
--data-binary "@${VIDEO_PATH}" 2> /dev/null > file_info.json
file_uri=$(jq -r ".file.uri" file_info.json)
file_name=$(jq -r ".file.name" file_info.json)
echo file_uri=$file_uri
echo "File uploaded successfully. File URI: ${file_uri}"
# Polling loop
echo "Waiting for file to be processed..."
while true; do
curl -s "https://generativelanguage.googleapis.com/v1beta/${file_name}" \
-H "x-goog-api-key: $GEMINI_API_KEY" > file_status.json
state=$(jq -r ".state" file_status.json)
echo "Current state: $state"
if [ "$state" == "ACTIVE" ]; then
break
elif [ "$state" == "FAILED" ]; then
echo "File processing failed."
exit 1
fi
sleep 5
done
echo "Generating content from video..."
curl -X POST "https://generativelanguage.googleapis.com/v1beta/interactions" \
-H "x-goog-api-key: $GEMINI_API_KEY" \
-H 'Content-Type: application/json' \
-d '{
"model": "gemini-3.6-flash",
"input": [
{"type": "video", "uri": "'${file_uri}'", "mime_type": "'${MIME_TYPE}'"},
{"type": "text", "text": "Summarize this video. Then create a quiz with an answer key based on the information in this video."}
]
}' 2> /dev/null > response.json
jq ".steps[].content[0].text" response.json
Files API का इस्तेमाल हमेशा तब करें, जब अनुरोध का कुल साइज़ (इसमें फ़ाइल, टेक्स्ट प्रॉम्प्ट, सिस्टम के निर्देश वगैरह शामिल हैं) 20 एमबी से ज़्यादा हो, वीडियो की अवधि ज़्यादा हो या अगर आपको एक ही वीडियो का इस्तेमाल, एक से ज़्यादा प्रॉम्प्ट में करना हो. File API, वीडियो फ़ाइल फ़ॉर्मैट को सीधे स्वीकार करता है.
मीडिया फ़ाइलों के साथ काम करने के बारे में ज़्यादा जानने के लिए, Files API देखें.
वीडियो डेटा को इनलाइन पास करना
File API का इस्तेमाल करके वीडियो फ़ाइल अपलोड करने के बजाय, छोटे वीडियो को सीधे अनुरोध में पास किया जा सकता है. यह सुविधा, 20 एमबी से कम साइज़ वाले छोटे वीडियो के लिए सही है.
यहां, इनलाइन वीडियो डेटा देने का एक उदाहरण दिया गया है:
Python
from google import genai
import base64
video_file_name = "/path/to/your/video.mp4"
video_bytes = open(video_file_name, 'rb').read()
client = genai.Client()
interaction = client.interactions.create(
model='gemini-3.6-flash',
input=[
{"type": "text", "text": "Please summarize the video in 3 sentences."},
{
"type": "video",
"data": base64.b64encode(video_bytes).decode('utf-8'),
"mime_type": "video/mp4"
}
]
)
print(interaction.output_text)
JavaScript
import { GoogleGenAI } from "@google/genai";
import * as fs from "node:fs";
const ai = new GoogleGenAI({});
const base64VideoFile = fs.readFileSync("path/to/small-sample.mp4", {
encoding: "base64",
});
const interaction = await ai.interactions.create({
model: "gemini-3.6-flash",
input: [
{ type: "text", text: "Please summarize the video in 3 sentences." },
{
type: "video",
data: base64VideoFile,
mime_type: "video/mp4",
}
],
});
console.log(interaction.output_text);
REST
VIDEO_PATH=/path/to/your/video.mp4
if [[ "$(base64 --version 2>&1)" = *"FreeBSD"* ]]; then
B64FLAGS="--input"
else
B64FLAGS="-w0"
fi
curl -X POST "https://generativelanguage.googleapis.com/v1beta/interactions" \
-H "x-goog-api-key: $GEMINI_API_KEY" \
-H 'Content-Type: application/json' \
-d '{
"model": "gemini-3.6-flash",
"input": [
{"type": "text", "text": "Please summarize the video in 3 sentences."},
{
"type": "video",
"data": "'$(base64 $B64FLAGS $VIDEO_PATH)'",
"mime_type": "video/mp4"
}
]
}' 2> /dev/null
YouTube के यूआरएल पास करना
YouTube के यूआरएल को, Gemini API में सीधे तौर पर अपने अनुरोध के हिस्से के तौर पर पास किया जा सकता है. इसके लिए, यह तरीका अपनाएं:
Python
from google import genai
client = genai.Client()
interaction = client.interactions.create(
model='gemini-3.6-flash',
input=[
{"type": "text", "text": "Please summarize the video in 3 sentences."},
{
"type": "video",
"uri": "https://www.youtube.com/watch?v=9hE5-98ZeCg"
}
]
)
print(interaction.output_text)
JavaScript
import { GoogleGenAI } from "@google/genai";
const ai = new GoogleGenAI({});
const interaction = await ai.interactions.create({
model: "gemini-3.6-flash",
input: [
{ type: "text", text: "Please summarize the video in 3 sentences." },
{
type: "video",
uri: "https://www.youtube.com/watch?v=9hE5-98ZeCg",
}
],
});
console