वीडियो जनरेट करने के बारे में जानने के लिए, Gemini Omni Flash की गाइड देखें.
Gemini मॉडल, वीडियो को प्रोसेस कर सकते हैं. इससे डेवलपर, वीडियो से जुड़े कई ऐसे काम कर सकते हैं जिनके लिए पहले, खास डोमेन वाले मॉडल की ज़रूरत होती थी. Gemini की विज़न क्षमताओं में ये काम शामिल हैं: वीडियो के बारे में बताना, वीडियो को सेगमेंट में बांटना, वीडियो से जानकारी निकालना, वीडियो के कॉन्टेंट के बारे में सवालों के जवाब देना, और वीडियो में मौजूद किसी खास टाइमस्टैंप के बारे में बताना.
Gemini को इन तरीकों से वीडियो इनपुट के तौर पर दिए जा सकते हैं:
| इनपुट विधि | सबसे बड़ा साइज़ | सुझाया गया इस्तेमाल |
|---|---|---|
| File API | 20 जीबी (पैसे चुकाकर) / 2 जीबी (मुफ़्त) | बड़ी फ़ाइलें (100 एमबी से ज़्यादा), लंबे वीडियो (10 मिनट से ज़्यादा), बार-बार इस्तेमाल की जा सकने वाली फ़ाइलें. |
| Cloud Storage में रजिस्टर करना | हर फ़ाइल के लिए 2 जीबी (स्टोरेज की कोई सीमा नहीं) | बड़ी फ़ाइलें (100 एमबी से ज़्यादा), लंबे वीडियो (10 मिनट से ज़्यादा), बार-बार इस्तेमाल की जा सकने वाली फ़ाइलें. |
| इनलाइन डेटा | 100 एमबी से कम | छोटी फ़ाइलें (100 एमबी से कम), कम अवधि वाले वीडियो (एक मिनट से कम), एक बार इस्तेमाल किए जाने वाले इनपुट. |
| YouTube के यूआरएल | लागू नहीं | YouTube के सार्वजनिक वीडियो. |
ध्यान दें: ज़्यादातर मामलों में, File API का इस्तेमाल करने का सुझाव दिया जाता है. खास तौर पर, 100 एमबी से बड़ी फ़ाइलों के लिए या जब आपको एक ही फ़ाइल को कई अनुरोधों में इस्तेमाल करना हो.
फ़ाइल इनपुट के अन्य तरीकों के बारे में जानने के लिए, जैसे कि बाहरी यूआरएल या Google Cloud में सेव की गई फ़ाइलों का इस्तेमाल करना, फ़ाइल इनपुट के तरीके वाली गाइड देखें.
वीडियो फ़ाइल अपलोड करना
यहां दिए गए कोड से, एक सैंपल वीडियो डाउनलोड किया जाता है. इसके बाद, Files API का इस्तेमाल करके उसे अपलोड किया जाता है. फिर, वीडियो की प्रोसेसिंग पूरी होने का इंतज़ार किया जाता है. इसके बाद, अपलोड की गई फ़ाइल के रेफ़रंस का इस्तेमाल करके, वीडियो का सारांश तैयार किया जाता है.
Python
from google import genai
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.8-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.8-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();
Java
import com.google.genai.Client;
import com.google.genai.gaos.models.interactions.Content;
import com.google.genai.gaos.models.interactions.CreateModelInteraction;
import com.google.genai.gaos.models.interactions.Interaction;
import com.google.genai.gaos.models.interactions.InteractionsInput;
import com.google.genai.gaos.models.interactions.Model;
import com.google.genai.gaos.models.interactions.TextContent;
import com.google.genai.gaos.models.interactions.VideoContent;
import com.google.genai.gaos.models.interactions.VideoContentMimeType;
import com.google.genai.gaos.models.operations.CreateInteractionRequestBody;
import java.util.Arrays;
import java.util.List;
Client client = new Client();
Content textContent = TextContent.builder().text("Summarize the key events in this video.").build();
Content videoContent =
VideoContent.builder()
.uri("gs://cloud-samples-data/generative-ai/video/pixel8.mp4")
.mimeType(VideoContentMimeType.VIDEO_MP4)
.build();
List<Content> contents = Arrays.asList(textContent, videoContent);
CreateModelInteraction params =
CreateModelInteraction.builder()
.model(Model.of("gemini-3.8-flash"))
.input(InteractionsInput.ofContent(contents))
.build();
Interaction interaction =
client.interactions.create(CreateInteractionRequestBody.of(params)).interaction().get();
System.out.println(interaction.outputText().orElse(""));
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.8-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.8-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.8-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);
Java
import com.google.genai.Client;
import com.google.genai.gaos.models.interactions.Content;
import com.google.genai.gaos.models.interactions.CreateModelInteraction;
import com.google.genai.gaos.models.interactions.Interaction;
import com.google.genai.gaos.models.interactions.InteractionsInput;
import com.google.genai.gaos.models.interactions.Model;
import com.google.genai.gaos.models.interactions.TextContent;
import com.google.genai.gaos.models.interactions.VideoContent;
import com.google.genai.gaos.models.interactions.VideoContentMimeType;
import com.google.genai.gaos.models.operations.CreateInteractionRequestBody;
import java.util.Arrays;
import java.util.List;
Client client = new Client();
Content textContent = TextContent.builder().text("Summarize the key events in this video.").build();
Content videoContent =
VideoContent.builder()
.uri("gs://cloud-samples-data/generative-ai/video/pixel8.mp4")
.mimeType(VideoContentMimeType.VIDEO_MP4)
.build();
List<Content> contents = Arrays.asList(textContent, videoContent);
CreateModelInteraction params =
CreateModelInteraction.builder()
.model(Model.of("gemini-3.8-flash"))
.input(InteractionsInput.ofContent(contents))
.build();
Interaction interaction =
client.interactions.create(CreateInteractionRequestBody.of(params)).interaction().get();
System.out.println(interaction.outputText().orElse(""));
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.8-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.8-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.8-flash",
input: [
{ type: "text", text: "Please summarize the video in 3 sentences." },
{
type: "video",
uri: "https://www.youtube.com/watch?v=9hE5-98ZeCg",
}
],
});
console.log(interaction.output_text);
Java
import com.google.genai.Client;
import com.google.genai.gaos.models.interactions.Content;
import com.google.genai.gaos.models.interactions.CreateModelInteraction;
import com.google.genai.gaos.models.interactions.Interaction;
import com.google.genai.gaos.models.interactions.InteractionsInput;
import com.google.genai.gaos.models.interactions.Model;
import com.google.genai.gaos.models.interactions.TextContent;
import com.google.genai.gaos.models.interactions.VideoContent;
import com.google.genai.gaos.models.interactions.VideoContentMimeType;
import com.google.genai.gaos.models.operations.CreateInteractionRequestBody;
import java.util.Arrays;
import java.util.List;
Client client = new Client();
Content textContent = TextContent.builder().text("Summarize the key events in this video.").build();
Content videoContent =
VideoContent.builder()
.uri("gs://cloud-samples-data/generative-ai/video/pixel8.mp4")
.mimeType(VideoContentMimeType.VIDEO_MP4)
.build();
List<Content> contents = Arrays.asList(textContent, videoContent);
CreateModelInteraction params =
CreateModelInteraction.builder()
.model(Model.of("gemini-3.8-flash"))
.input(InteractionsInput.ofContent(contents))
.build();
Interaction interaction =
client.interactions.create(CreateInteractionRequestBody.of(params)).interaction().get();
System.out.println(interaction.outputText().orElse(""));
REST
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.8-flash",
"input": [
{"type": "text", "text": "Please summarize the video in 3 sentences."},
{
"type": "video",
"uri": "https://www.youtube.com/watch?v=9hE5-98ZeCg"
}
]
}' 2> /dev/null
सीमाएं:
- मुफ़्त टियर के लिए, हर दिन YouTube के आठ घंटे से ज़्यादा के वीडियो अपलोड नहीं किए जा सकते.
- पैसे चुकाकर इस्तेमाल किए जाने वाले टियर के लिए, वीडियो की अवधि के हिसाब से कोई सीमा नहीं है.
- Gemini 2.5 से पहले के मॉडल के लिए, हर अनुरोध में सिर्फ़ एक वीडियो अपलोड किया जा सकता है. Gemini 2.5 और उसके बाद के मॉडल के लिए, हर अनुरोध में ज़्यादा से ज़्यादा 10 वीडियो अपलोड किए जा सकते हैं.
- सिर्फ़ सार्वजनिक वीडियो अपलोड किए जा सकते हैं. निजी या 'सबके लिए मौजूद नहीं' के तौर पर उपलब्ध वीडियो अपलोड नहीं किए जा सकते.
एजेंटिक वीडियो समझने की सुविधा
डिफ़ॉल्ट रूप से, वीडियो इनपुट के लिए स्टैटिक प्रोसेसिंग का इस्तेमाल किया जाता है. इसमें एक सेकंड में एक फ़्रेम के हिसाब से फ़्रेम निकाले जाते हैं. Gemini 3.8 Flash, 3.7 Flash, 3.6 Flash, और 3.5 Flash Lite मॉडल, एजेंटिक वीडियो समझने की सुविधा भी देते हैं. इसमें मॉडल, वीडियो की टाइमलाइन को डाइनैमिक तरीके से एक्सप्लोर करता है. साथ ही, प्रॉम्प्ट के आधार पर, वीडियो के ट्रांसक्रिप्ट को चुनिंदा तौर पर देखता है. इसके अलावा, फ़्रेम रेट और रिज़ॉल्यूशन को ज़रूरत के हिसाब से अडजस्ट करता है.
| मोड | ब्यौरा | इस्तेमाल किए जा सकने वाले मॉडल |
|---|---|---|
| स्टैटिक (डिफ़ॉल्ट) | इसमें एक तय दर (एक सेकंड में एक फ़्रेम) से फ़्रेम निकाले जाते हैं और उन्हें एक ही बार में कॉन्टेक्स्ट में रखा जाता है. यह सुविधा, छोटी क्लिप के लिए अच्छी तरह काम करती है. | Gemini के सभी मॉडल |
| एजेंटिक | मॉडल, वीडियो की टाइमलाइन को डाइनैमिक तरीके से नेविगेट करता है. साथ ही, प्रॉम्प्ट के आधार पर सिर्फ़ ज़रूरी कॉन्टेंट लोड करता है. यह सुविधा, लंबी अवधि के कॉन्टेंट के लिए 88% तक ज़्यादा टोकन-एफ़िशिएंट है और इसकी क्वालिटी ~7% बेहतर है. | Gemini 3.8 Flash, 3.7 Flash, 3.6 Flash, 3.5 Flash Lite |
प्रोसेसिंग मोड चुनना
सामान्य तौर पर, एजेंटिक मोड से शुरुआत करें. खास तौर पर, जवाब की क्वालिटी या टोकन की बचत के लिए ऑप्टिमाइज़ करते समय.
- एजेंटिक: लंबी अवधि के वीडियो या खास पलों को टारगेट करने वाले क्वेरी. मॉडल, कॉन्टेक्स्ट विंडो को भरे बिना, कॉन्टेक्चुअली काम की जानकारी को टारगेट करने के लिए, टाइमलाइन को डाइनैमिक तरीके से नेविगेट करता है.
- स्टैटिक: पांच मिनट से कम की छोटी क्लिप पर, कम समय में जवाब देने वाली क्वेरी या ऐसे मामले जहां पूरी क्लिप में फ़्रेम-लेवल की सटीक जानकारी की ज़रूरत होती है.
ध्यान दें: लंबे वीडियो या मुश्किल प्रॉम्प्ट के लिए, एजेंटिक प्रोसेसिंग में ज़्यादा समय लगता है. ऐसे में, स्ट्रीमिंग (
stream=True) या बैकग्राउंड में प्रोसेस करने (background=True) का इस्तेमाल करें. इससे कनेक्शन चालू रहता है, बीच-बीच में तर्क देने के चरण दिखते हैं, और कनेक्शन या पुष्टि करने के लिए तय समय खत्म होने से जुड़ी गड़बड़ियां नहीं आती हैं.
प्रोसेसिंग मोड सेट करना
Python
import time
from google import genai
client = genai.Client()
# Upload a long video
video_file = client.files.upload(file="path/to/lecture.mp4")
while video_file.state.name == "PROCESSING":
time.sleep(2)
video_file = client.files.get(name=video_file.name)
# Use agentic processing
interaction = client.interactions.create(
model="gemini-3.8-flash",
input=[
{
"type": "video",
"uri": video_file.uri,
"mime_type": video_file.mime_type,
"processing": "agentic"
},
{"type": "text", "text": "What are the three main arguments presented?"}
]
)
print(interaction.output_text)
JavaScript
import { GoogleGenAI } from "@google/genai";
const ai = new GoogleGenAI({});
// Upload a long video
let videoFile = await ai.files.upload({
file: "path/to/lecture.mp4",
config: { mimeType: "video/mp4" }
});
while (videoFile.state === "PROCESSING") {
await new Promise((resolve) => setTimeout(resolve, 2000));
videoFile = await ai.files.get({ name: videoFile.name });
}
// Use agentic processing
const interaction = await ai.interactions.create({
model: "gemini-3.8-flash",
input: [
{
type: "video",
uri: videoFile.uri,
mime_type: videoFile.mimeType,
processing: "agentic"
},
{ type: "text", text: "What are the three main arguments presented?" }
]
});
console.log(interaction.output_text);
REST
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.8-flash",
"input": [
{
"type": "video",
"uri": "'${file_uri}'",
"mime_type": "video/mp4",
"processing": "agentic"
},
{"type": "text", "text": "What are the three main arguments presented?"}
]
}' 2> /dev/null
ध्यान दें: यह पुष्टि करने के लिए कि एजेंटिक प्रोसेसिंग का इस्तेमाल किया गया है,
interaction.stepsदेखें.processing_callऔरprocessing_resultकी मौजूदगी से पता चलता है कि मॉडल ने वीडियो को डाइनैमिक तरीके से नेविगेट किया है.
जवाब देने के चरण
एजेंटिक प्रोसेसिंग, steps कलेक्शन में दो नए चरण के टाइप जोड़ती है:
processing_call: मॉडल ने वीडियो के किसी सेगमेंट या ऑडियो ट्रांसक्रिप्ट का अनुरोध किया है. इसकी पहचानidसे होती है.processing_result: यह उस लोड का नतीजा है, जोcall_idसे लिंक है.
ये thought चरणों के साथ इंटरलीव किए जाते हैं. ऐसा तब होता है, जब सारांश की सुविधा चालू होती है. साथ ही, ये चरण, फ़ाइनल model_output चरण से पहले दिखते हैं. इनका इस्तेमाल, यूज़र इंटरफ़ेस (यूआई) में प्रोग्रेस ट्रेस दिखाने के लिए किया जा सकता है. हालांकि, इनके लिए जवाब की ज़रूरत नहीं होती.
यहां दिए गए उदाहरण में, इंटरलीव किए गए प्रोसेसिंग चरणों के साथ जवाब का पेलोड दिखाया गया है:
{
"steps": [
{
"type": "thought",
"signature": "sig_thought_1",
"summary": [
{
"type": "text",
"text": "Inspecting transcript for key discussion topics..."
}
]
},
{
"type": "processing_call",
"id": "call_01",
"signature": "sig_call_01"
},
{
"type": "processing_result",
"call_id": "call_01",
"signature": "sig_result_01"
},
{
"type": "thought",
"signature": "sig_thought_2",
"summary": [
{
"type": "text",
"text": "Loading visual frames to verify slide content..."
}
]
},
{
"type": "processing_call",
"id": "call_02",
"signature": "sig_call_02"
},
{
"type": "processing_result",
"call_id": "call_02",
"signature": "sig_result_02"
},
{
"type": "thought",
"signature": "sig_thought_3",
"summary": [
{
"type": "text",
"text": "Synthesizing answer from gathered evidence..."
}
]
},
{
"type": "model_output",
"content": [
{
"type": "text",
"text": "The three main arguments presented in the lecture are..."
}
]
}
]
}
अलग-अलग वीडियो के लिए अलग-अलग प्रोसेसिंग मोड इस्तेमाल करना
एक ही अनुरोध में, हर वीडियो के लिए अलग-अलग प्रोसेसिंग मोड सेट किए जा सकते हैं:
Python
from google import genai
client = genai.Client()
lecture = client.files.upload(file="path/to/long-lecture.mp4")
experiment = client.files.upload(file="path/to/short-experiment.mp4")
interaction = client.interactions.create(
model="gemini-3.8-flash",
input=[
{
"type": "video",
"uri": lecture.uri,
"mime_type": lecture.mime_type,
"processing": "agentic" # Use agentic video understanding
},
{
"type": "video",
"uri": experiment.uri,
"mime_type": experiment.mime_type,
"processing": "static" # Use static processing
},
{"type": "text", "text": "Compare the lecture content with the experiment results."}
]
)
print(interaction.output_text)
JavaScript
import { GoogleGenAI } from "@google/genai";
const ai = new GoogleGenAI({});
const lecture = await ai.files.upload({
file: "path/to/long-lecture.mp4",
config: { mimeType: "video/mp4" }
});
const experiment = await ai.files.upload({
file: "path/to/short-experiment.mp4",
config: { mimeType: "video/mp4" }
});
const interaction = await ai.interactions.create({
model: "gemini-3.8-flash",
input: [
{
type: "video",
uri: lecture.uri,
mime_type: lecture.mimeType,
processing: "agentic" // Use agentic video understanding
},
{
type: "video",
uri: experiment.uri,
mime_type: experiment.mimeType,
processing: "static" // Use static processing
},
{ type: "text", text: "Compare the lecture content with the experiment results." }
]
});
console.log(interaction.output_text);
REST
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.8-flash",
"input": [
{
"type": "video",
"uri": "'${lecture_uri}'",
"mime_type": "video/mp4",
"processing": "agentic"
},
{
"type": "video",
"uri": "'${experiment_uri}'",
"mime_type": "video/mp4",
"processing": "static"
},
{"type": "text", "text": "Compare the lecture content with the experiment results."}
]
}' 2> /dev/null
वीडियो से जुड़ी सिलसिलेवार बातचीत
बातचीत के दौरान, वीडियो का कॉन्टेक्स्ट बना रहता है. एजेंटिक प्रोसेसिंग का इस्तेमाल करते समय:
- स्टेटफ़ुल मोड (
previous_interaction_idका इस्तेमाल करके): सर्वर, वीडियो का कॉन्टेक्स्ट बनाए रखता है. इसके लिए, किसी अतिरिक्त हैंडलिंग की ज़रूरत नहीं होती. - स्टेटलेस मोड (
step_listका इस्तेमाल करके): स्टेटलेस मोड में, जवाब मेंprocessing_callऔरprocessing_resultचरण शामिल होते हैं. इनमें वीडियो का कॉन्टेक्स्ट एन्कोड होता है. वीडियो का कॉन्टेक्स्ट बनाए रखने के लिए, आपको अपने अगले अनुरोध केstep_listमें, जवाब के सभी चरण शामिल करने होंगे. फ़िलहाल, इन्हें शामिल न करने पर, एपीआई से जुड़ी कोई गड़बड़ी नहीं दिखती. हालांकि, वीडियो का कॉन्टेक्स्ट खत्म हो जाता है. इससे, फ़ॉलो-अप सवालों के जवाब की क्वालिटी काफ़ी कम हो जाती है. ध्यान दें कि बाद के अनुरोधों में भेजे गए चरण, इनपुट टोकन की गिनती में शामिल होते हैं.
कॉन्टेंट में मौजूद टाइमस्टैंप के बारे में बताना
MM:SS फ़ॉर्मैट वाले टाइमस्टैंप का इस्तेमाल करके, वीडियो में मौजूद किसी खास समय के बारे में सवाल पूछे जा सकते हैं.
Python
prompt = "What are the examples given at 00:05 and 00:10 supposed to show us?"
JavaScript
const prompt = "What are the examples given at 00:05 and 00:10 supposed to show us?";
Java
import com.google.genai.Client;
import com.google.genai.gaos.models.interactions.Content;
import com.google.genai.gaos.models.interactions.CreateModelInteraction;
import com.google.genai.gaos.models.interactions.Interaction;
import com.google.genai.gaos.models.interactions.InteractionsInput;
import com.google.genai.gaos.models.interactions.Model;
import com.google.genai.gaos.models.interactions.TextContent;
import com.google.genai.gaos.models.interactions.VideoContent;
import com.google.genai.gaos.models.interactions.VideoContentMimeType;
import com.google.genai.gaos.models.operations.CreateInteractionRequestBody;
import java.util.Arrays;
import java.util.List;
Client client = new Client();
Content textContent = TextContent.builder().text("Summarize the key events in this video.").build();
Content videoContent =
VideoContent.builder()
.uri("gs://cloud-samples-data/generative-ai/video/pixel8.mp4")
.mimeType(VideoContentMimeType.VIDEO_MP4)
.build();
List<Content> contents = Arrays.asList(textContent, videoContent);
CreateModelInteraction params =
CreateModelInteraction.builder()
.model(Model.of("gemini-3.8-flash"))
.input(InteractionsInput.ofContent(contents))
.build();
Interaction interaction =
client.interactions.create(CreateInteractionRequestBody.of(params)).interaction().get();
System.out.println(interaction.outputText().orElse(""));
REST
PROMPT="What are the examples given at 00:05 and 00:10 supposed to show us?"
वीडियो से अहम जानकारी निकालना
Gemini मॉडल, ऑडियो और विज़ुअल, दोनों स्ट्रीम से जानकारी प्रोसेस करके, वीडियो के कॉन्टेंट को समझने की बेहतरीन क्षमताएं देते हैं. इससे, वीडियो के बारे में कई तरह की जानकारी निकाली जा सकती है. इसमें वीडियो में क्या हो रहा है, इसकी जानकारी जनरेट करना और वीडियो के कॉन्टेंट के बारे में सवालों के जवाब देना शामिल है.
विज़ुअल जानकारी के लिए, मॉडल एक सेकंड में एक फ़्रेम (एफ़पीएस) की दर से वीडियो का सैंपल लेता है. सैंपल लेने की यह डिफ़ॉल्ट दर, ज़्यादातर कॉन्टेंट के लिए अच्छी तरह काम करती है. हालांकि, ध्यान दें कि तेज़ी से चलने वाले वीडियो या सीन में तेज़ी से बदलाव होने वाले वीडियो में, यह दर जानकारी को कैप्चर नहीं कर पाती.
Python
prompt = "Describe the key events in this video, providing both audio and visual details. Include timestamps for salient moments."
JavaScript
const prompt = "Describe the key events in this video, providing both audio and visual details. Include timestamps for salient moments.";
Java
import com.google.genai.Client;
import com.google.genai.gaos.models.interactions.Content;
import com.google.genai.gaos.models.interactions.CreateModelInteraction;
import com.google.genai.gaos.models.interactions.Interaction;
import com.google.genai.gaos.models.interactions.InteractionsInput;
import com.google.genai.gaos.models.interactions.Model;
import com.google.genai.gaos.models.interactions.TextContent;
import com.google.genai.gaos.models.interactions.VideoContent;
import com.google.genai.gaos.models.interactions.VideoContentMimeType;
import com.google.genai.gaos.models.operations.CreateInteractionRequestBody;
import java.util.Arrays;
import java.util.List;
Client client = new Client();
Content textContent = TextContent.builder().text("Summarize the key events in this video.").build();
Content videoContent =
VideoContent.builder()
.uri("gs://cloud-samples-data/generative-ai/video/pixel8.mp4")
.mimeType(VideoContentMimeType.VIDEO_MP4)
.build();
List<Content> contents = Arrays.asList(textContent, videoContent);
CreateModelInteraction params =
CreateModelInteraction.builder()
.model(Model.of("gemini-3.8-flash"))
.input(InteractionsInput.ofContent(contents))
.build();
Interaction interaction =
client.interactions.create(CreateInteractionRequestBody.of(params)).interaction().get();
System.out.println(interaction.outputText().orElse(""));
REST
PROMPT="Describe the key events in this video, providing both audio and visual details. Include timestamps for salient moments."
वीडियो प्रोसेसिंग को पसंद के मुताबिक बनाना
Gemini API में, वीडियो प्रोसेसिंग को पसंद के मुताबिक बनाया जा सकता है. इसके लिए, क्लिपिंग इंटरवल सेट किए जा सकते हैं या फ़्रेम रेट के हिसाब से सैंपल लेने की कस्टम दर दी जा सकती है. कस्टमाइज़ेशन के ये विकल्प
वीडियो को "static" मोड में प्रोसेस करने पर ही काम करते हैं.
क्लिपिंग इंटरवल सेट करना
processing कॉन्फ़िगरेशन ऑब्जेक्ट में start_offset और end_offset तय करके, वीडियो को क्लिप किया जा सकता है.
Python
interaction = client.interactions.create(
model="gemini-3.8-flash",
input=[
{
"type": "video",
"uri": video_file.uri,
"mime_type": video_file.mime_type,
"processing": {
"type": "static",
"start_offset": 1200,
"end_offset": 1500,
},
},
{"type": "text", "text": "Summarize this section of the video."},
],
)
print(interaction.output_text)
JavaScript
const interaction = await ai.interactions.create({
model: "gemini-3.8-flash",
input: [
{
type: "video",
uri: videoFile.uri,
mime_type: videoFile.mimeType,
processing: {
type: "static",
start_offset: 1200,
end_offset: 1500,
},
},
{ type: "text", text: "Summarize this section of the video." },
],
});
console.log(interaction.output_text);
REST
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.8-flash",
"input": [
{
"type": "video",
"uri": "'${file_uri}'",
"mime_type": "video/mp4",
"processing": {
"type": "static",
"start_offset": 1200,
"end_offset": 1500
}
},
{"type": "text", "text": "Summarize this section of the video."}
]
}' 2> /dev/null
फ़्रेम रेट के हिसाब से सैंपल लेने की कस्टम दर सेट करना
processing कॉन्फ़िगरेशन ऑब्जेक्ट में fps आर्ग्युमेंट पास करके, फ़्रेम रेट के हिसाब से सैंपल लेने की कस्टम दर सेट की जा सकती है.
Python
interaction = client.interactions.create(
model="gemini-3.8-flash",
input=[
{
"type": "video",
"uri": video_file.uri,
"mime_type": video_file.mime_type,
"processing": {
"type": "static",
"fps": 0.5, # Sample 1 frame every 2 seconds
},
},
{"type": "text", "text": "Describe the scene changes in this video."},
],
)
print(interaction.output_text)
JavaScript
const interaction = await ai.interactions.create({
model: "gemini-3.8-flash",
input: [
{
type: "video",
uri: videoFile.uri,
mime_type: videoFile.mimeType,
processing: {
type: "static",
fps: 0.5, // Sample 1 frame every 2 seconds
},
},
{ type: "text", text: "Describe the scene changes in this video." },
],
});
console.log(interaction.output_text);
REST
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.8-flash",
"input": [
{
"type": "video",
"uri": "'${file_uri}'",
"mime_type": "video/mp4",
"processing": {
"type": "static",
"fps": 0.5
}
},
{"type": "text", "text": "Describe the scene changes in this video."}
]
}' 2> /dev/null
काम करने वाले वीडियो फ़ॉर्मैट
Gemini, वीडियो के इन MIME टाइप के साथ काम करता है:
video/mp4video/mpegvideo/movvideo/avivideo/x-flvvideo/mpgvideo/webmvideo/wmvvideo/3gpp
वीडियो के बारे में तकनीकी जानकारी
- इस्तेमाल किए जा सकने वाले मॉडल और कॉन्टेक्स्ट: Gemini के सभी मॉडल, वीडियो डेटा को प्रोसेस कर सकते हैं.
- 10 लाख टोकन कॉन्टेक्स्ट विंडो वाले मॉडल, डिफ़ॉल्ट रूप से तीन घंटे तक के वीडियो प्रोसेस कर सकते हैं. हालांकि, यह तब होता है, जब मीडिया का रिज़ॉल्यूशन कम हो. अगर मीडिया का रिज़ॉल्यूशन ज़्यादा है, तो ये मॉडल एक घंटे तक के वीडियो प्रोसेस कर सकते हैं.
- प्रोसेसिंग मोड: Gemini 3.8 Flash, 3.7 Flash, 3.6 Flash, 3.5 Flash Lite,
और इसके बाद के मॉडल, वीडियो प्रोसेसिंग के दो मोड के साथ काम करते हैं:
- स्टैटिक: इसमें एक सेकंड में एक फ़्रेम के हिसाब से फ़्रेम निकाले जाते हैं और उन्हें कॉन्टेक्स्ट में रखा जाता है. यह सभी मॉडल के लिए डिफ़ॉल्ट सेटिंग है . ऑडियो को एक केबीपीएस (सिंगल चैनल) पर प्रोसेस किया जाता है. हर सेकंड में टाइमस्टैंप जोड़े जाते हैं. यह सुविधा, छोटी क्लिप के लिए या तब सबसे सही है, जब हर फ़्रेम अहम हो. जैसे, फ़्रेम-बाय-फ़्रेम जांच. ध्यान दें कि एक सेकंड में एक फ़्रेम के हिसाब से सैंपल लेने की दर की वजह से, तेज़ी से होने वाली कार्रवाइयों के क्रम में जानकारी छूट सकती है.
- एजेंटिक: मॉडल, वीडियो को डाइनैमिक तरीके से नेविगेट करता है. साथ ही, ज़रूरत के हिसाब से ट्रांसक्रिप्ट और/या फ़्रेम और/या ऑडियो लोड करता है. यह सुविधा, लंबी अवधि के कॉन्टेंट के लिए 88% तक कम टोकन इस्तेमाल करती है. हालांकि, जनरेशन शुरू होने से पहले, इंटरनल गहराई से विश्लेषण और टूल राउंड-ट्रिप की वजह से, पांच मिनट से कम की छोटी क्लिप के लिए, फ़र्स्ट टोकन मिलने में लगने वाला समय (टीटीएफ़टी) थोड़ा बढ़ सकता है. टोकन की लागत और जवाब की क्वालिटी को ऑप्टिमाइज़ करने के लिए, लंबी अवधि के वीडियो के लिए यह सुविधा सबसे सही है. यह सुविधा, Gemini 3.8 Flash, 3.7 Flash, 3.6 Flash, और 3.5 Flash Lite पर काम करती है. ज़्यादा जानकारी के लिए, एजेंटिक वीडियो समझने की सुविधा देखें.
- टोकन की गिनती (स्टैटिक मोड): वीडियो के हर सेकंड को इस तरह टोकनाइज़ किया जाता है:
इस तरह:
- अलग-अलग फ़्रेम (एक सेकंड में एक फ़्रेम के हिसाब से सैंपल लिए जाते हैं):
- अगर
media_resolutionको कम पर सेट किया जाता है, तो फ़्रेम को हर फ़्रेम के लिए 66 टोकन के हिसाब से टोकनाइज़ किया जाता है. - अन्य मामलों में, फ़्रेम को हर फ़्रेम के लिए 258 टोकन के हिसाब से टोकनाइज़ किया जाता है.
- अगर
- ऑडियो: हर सेकंड के लिए 32 टोकन.
- इसमें मेटाडेटा भी शामिल होता है.
- कुल: डिफ़ॉल्ट (कम) मीडिया रिज़ॉल्यूशन पर, वीडियो के हर सेकंड के लिए करीब 100 टोकन या ज़्यादा मीडिया रिज़ॉल्यूशन पर, वीडियो के हर सेकंड के लिए करीब 300 टोकन.
- अलग-अलग फ़्रेम (एक सेकंड में एक फ़्रेम के हिसाब से सैंपल लिए जाते हैं):
- टोकन की गिनती (एजेंटिक मोड): टोकन का इस्तेमाल, कॉन्टेंट
की जटिलता और मॉडल की नेविगेशन रणनीति के आधार पर अलग-अलग होता है. वीडियो एक्सप्लोर करने के दौरान जनरेट किए गए नेविगेशन तर्क वाले टोकन को थॉट टोकन(
total_thought_tokens) के तौर पर गिना जाता है. वहीं, ज़रूरत के हिसाब से लोड किए गए फ़्रेम, ऑडियो, और ट्रांसक्रिप्ट को टूल के इस्तेमाल वाले टोकन (total_tool_use_tokens) के तौर पर गिना जाता है. एजेंटिक प्रोसेसिंग में, लंबी अवधि के कॉन्टेंट के लिए, स्टैटिक प्रोसेसिंग की तुलना में आम तौर पर 88% तक कम टोकन इस्तेमाल होते हैं. इसकी वजह यह है कि मॉडल, प्रॉम्प्ट का जवाब देने के लिए सिर्फ़ ज़रूरी ट्रांसक्रिप्ट और/या फ़्रेम और/या ऑडियो लोड करता है. ज़्यादा जानकारी के लिए, टोकन वाली गाइड देखें. - मीडिया रिज़ॉल्यूशन: Gemini 3 में, मल्टीमॉडल
विज़न प्रोसेसिंग पर ज़्यादा कंट्रोल मिलता है. यह कंट्रोल
media_resolutionपैरामीटर की मदद से मिलता है.media_resolutionपैरामीटर, हर इनपुट इमेज या वीडियो फ़्रेम के लिए तय किए गए टोकन की ज़्यादा से ज़्यादा संख्या तय करता है. ज़्यादा रिज़ॉल्यूशन से, मॉडल को बारीक टेक्स्ट पढ़ने या छोटी-छोटी जानकारी की पहचान करने में मदद मिलती है. हालांकि, इससे टोकन का इस्तेमाल और जवाब मिलने में लगने वाला समय बढ़ जाता है.media_resolutionऔरprocessingपैरामीटर एक-दूसरे से अलग हैं. इसलिए, एक ही वीडियो इनपुट पर दोनों को सेट किया जा सकता है.
टोकन की गिनती के बारे में ज़्यादा जानकारी के लिए, टोकन वाली गाइड देखें.
- टाइमस्टैंप का फ़ॉर्मैट: अपने प्रॉम्प्ट में, वीडियो में मौजूद किसी खास समय के बारे में बताने के लिए,
MM:SSफ़ॉर्मैट का इस्तेमाल करें. जैसे, एक मिनट और 15 सेकंड के लिए01:15. - प्रॉम्प्ट की जगह: अगर टेक्स्ट और एक वीडियो को एक साथ इस्तेमाल किया जा रहा है, तो
inputकलेक्शन में, वीडियो वाले हिस्से के बाद टेक्स्ट प्रॉम्प्ट रखें. - लंबे अनुरोधों के लिए टाइमआउट: ऐसे वीडियो के लिए जिनमें प्रोसेसिंग में ज़्यादा समय लगता है या मुश्किल मल्टी-स्टेप तर्क की ज़रूरत होती है, स्ट्रीमिंग
(
stream=True) या बैकग्राउंड में प्रोसेस करने (background=True) का इस्तेमाल करें. ज़्यादा मांग होने पर, सिंक वाले ऐसे अनुरोध जिनमें स्ट्रीमिंग की सुविधा नहीं होती और बैकएंड से फिर से कोशिश की जाती है, उनके लिए कनेक्शन या पुष्टि करने वाले टोकन की वैधता की अवधि खत्म हो सकती है, इससे,401 Unauthorizedया टाइमआउट से जुड़ी गड़बड़ियां दिख सकती हैं. स्ट्रीमिंग से कनेक्शन चालू रहता है. साथ ही, बीच-बीच में तर्क देने और टूल कॉल की प्रोग्रेस दिखती है.
आगे क्या करना है
- मीडिया रिज़ॉल्यूशन: क्वालिटी और टोकन के इस्तेमाल के बीच बैलेंस बनाए रखने के लिए, वीडियो फ़्रेम का रिज़ॉल्यूशन कंट्रोल करें.
- टोकन: जानें कि स्टैटिक और एजेंटिक, दोनों प्रोसेसिंग मोड में वीडियो कॉन्टेंट को कैसे टोकनाइज़ किया जाता है.
- सिस्टम के निर्देश: सिस्टम के निर्देशों की मदद से, अपनी ज़रूरतों और इस्तेमाल के मामलों के हिसाब से, मॉडल के व्यवहार को कंट्रोल किया जा सकता है.
- Files API: Gemini के साथ इस्तेमाल करने के लिए, फ़ाइलें अपलोड करने और उन्हें मैनेज करने के बारे में ज़्यादा जानें.
- फ़ाइल के साथ प्रॉम्प्ट करने की रणनीतियां: Gemini API, टेक्स्ट, इमेज, ऑडियो, और वीडियो डेटा के साथ प्रॉम्प्ट करने की सुविधा देता है. इसे मल्टीमॉडल प्रॉम्प्टिंग भी कहा जाता है.
- सुरक्षा से जुड़े दिशा-निर्देश: जनरेटिव एआई मॉडल कभी-कभी ऐसे आउटपुट जनरेट करते हैं जिनकी उम्मीद नहीं होती. जैसे, गलत, पक्षपाती या आपत्तिजनक आउटपुट. ऐसे आउटपुट से होने वाले नुकसान के जोखिम को कम करने के लिए, पोस्ट-प्रोसेसिंग और लोगों से आकलन कराना ज़रूरी है.