لمزيد من المعلومات حول إنشاء الفيديوهات، يمكنك الاطّلاع على دليل Gemini Omni Flash.
يمكن لنماذج Gemini معالجة الفيديوهات، ما يتيح العديد من حالات الاستخدام المتقدّمة للمطوّرين التي كانت تتطلّب في السابق نماذج خاصة بمجالات معيّنة. تشمل بعض قدرات Gemini المرئية ما يلي: وصف الفيديوهات وتقسيمها واستخراج المعلومات منها، والإجابة عن أسئلة حول محتوى الفيديو، والإشارة إلى طوابع زمنية محدّدة ضمن الفيديو.
يمكنك تقديم فيديوهات كمدخلات إلى Gemini بالطرق التالية:
| طريقة الإرسال | الحد الأقصى للحجم | حالة الاستخدام المقترَحة |
|---|---|---|
| File API | 20 غيغابايت (مدفوعة) / 2 غيغابايت (مجانية) | الملفات الكبيرة (100 ميغابايت أو أكثر) والفيديوهات الطويلة (10 دقائق أو أكثر) والملفات القابلة لإعادة الاستخدام |
| تسجيل Cloud Storage | 2 غيغابايت (لكل ملف، بدون حدود لمساحة التخزين) | الملفات الكبيرة (100 ميغابايت أو أكثر) والفيديوهات الطويلة (10 دقائق أو أكثر) والملفات الدائمة والقابلة لإعادة الاستخدام |
| البيانات المضمّنة | < 100 ميغابايت | الملفات الصغيرة (أقل من 100 ميغابايت)، والمدّة القصيرة (أقل من دقيقة واحدة)، والمدخلات لمرة واحدة |
| عناوين URL على YouTube | لا ينطبق | الفيديوهات العلنية على YouTube |
ملاحظة: ننصح باستخدام File API في معظم حالات الاستخدام، خاصةً للملفات التي يزيد حجمها عن 100 ميغابايت أو عندما تريد إعادة استخدام الملف في عدة طلبات.
للتعرّف على طرق إدخال الملفات الأخرى، مثل استخدام عناوين URL أو ملفات خارجية مخزّنة في 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();
جافا
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);
جافا
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
تمرير عناوين URL لفيديوهات YouTube
يمكنك تمرير عناوين URL على 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);
جافا
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
القيود:
- في المستوى المجاني، لا يمكنك تحميل أكثر من 8 ساعات من فيديوهات YouTube يوميًا.
- بالنسبة إلى المستوى المدفوع، لا يوجد حد أقصى استنادًا إلى مدة الفيديو.
- بالنسبة إلى النماذج الأقدم من Gemini 2.5، يمكنك تحميل فيديو واحد فقط لكل طلب. بالنسبة إلى Gemini 2.5 والإصدارات الأحدث، يمكنك تحميل 10 فيديوهات بحدّ أقصى لكل طلب.
- يمكنك تحميل فيديوهات علنية فقط (وليس فيديوهات خاصة أو غير مُدرَجة).
فهم الفيديوهات المستند إلى الذكاء الاصطناعي الوكيل
تستخدم مدخلات الفيديو تلقائيًا معالجة ثابتة (استخراج اللقطات بمعدل لقطة واحدة في الثانية). تتيح نماذج Gemini 3.8 Flash و3.7 Flash و3.6 Flash و3.5 Flash Lite أيضًا ميزة الفهم الآلي للفيديوهات، حيث يستكشف النموذج المخطط الزمني للفيديو بشكل ديناميكي، ويفحص النصوص بشكل انتقائي، ويعدّل معدّل عرض اللقطات ودرجة الدقة بشكل تكيفي أثناء التشغيل استنادًا إلى الطلب.
| الوضع | الوصف | الطُرز المتوافقة |
|---|---|---|
| ثابتة (تلقائي) | يستخرج اللقطات بمعدّل ثابت (لقطة واحدة في الثانية) ويضعها في السياق في عملية واحدة. مناسبة للمقاطع القصيرة | جميع نماذج Gemini |
| Agentic | يتنقّل النموذج ديناميكيًا في المخطط الزمني للفيديو، ولا يحمّل سوى المحتوى الذي يحتاجه استنادًا إلى الطلب. زيادة في كفاءة استخدام الرموز المميزة بنسبة تصل إلى% 88 وتحسين جودة المحتوى الطويل بنسبة% 7 تقريبًا | Gemini 3.8 Flash و3.7 Flash و3.6 Flash و3.5 Flash Lite |
اختيار وضع المعالجة
كإرشادات عامة، ننصحك بالبدء باستخدام الوضع الوكيل، خاصةً عند تحسين جودة الردود أو كفاءة الرموز المميزة.
- الاستجابة المباشرة: فيديوهات طويلة أو طلبات بحث تستهدف لحظات معيّنة يتنقّل النموذج بشكل ديناميكي في المخطط الزمني لاستهداف المعلومات ذات الصلة بالسياق بدون ملء نافذة السياق.
- ثابتة: طلبات البحث التي تتطلّب سرعة استجابة عالية على مقاطع قصيرة (أقل من 5 دقائق)، أو الحالات التي تتطلّب دقة على مستوى الإطار في المقطع بأكمله.
ملاحظة: بالنسبة إلى الفيديوهات الطويلة أو الطلبات المعقّدة التي تستغرق معالجتها وقتًا أطول، استخدِم البث المباشر (
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?";
جافا
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 إمكانات قوية لفهم محتوى الفيديو من خلال معالجة المعلومات من كل من محتوى الصوت والمرئي. يتيح لك ذلك استخراج مجموعة كبيرة من التفاصيل، بما في ذلك إنشاء أوصاف لما يحدث في فيديو والإجابة عن الأسئلة حول محتواه.
بالنسبة إلى الأوصاف المرئية، يأخذ النموذج عيّنات من الفيديو بمعدّل لقطة واحدة في الثانية (FPS). يعمل معدّل أخذ العيّنات التلقائي هذا بشكل جيد مع معظم المحتوى، ولكن يجب الانتباه إلى أنّه قد لا يرصد التفاصيل في الفيديوهات التي تتضمّن حركة سريعة أو تغييرات سريعة في المشاهد.
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.";
جافا
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".
ضبط الفواصل الزمنية لقص الفيديو
يمكنك قص الفيديو من خلال تحديد start_offset وend_offset في عنصر الإعداد processing.
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
ضبط عدد اللقطات في الثانية بشكل مخصّص
يمكنك ضبط أخذ عيّنات مخصّصة لمعدّل عرض اللقطات من خلال تمرير وسيطة fps في عنصر الإعداد processing.
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 معالجة بيانات الفيديو.
- يمكن للنماذج التي تتضمّن قدرة استيعاب مليون رمز مميّز معالجة فيديوهات تصل مدتها إلى 3 ساعات تلقائيًا (بدقة وسائط منخفضة)، أو فيديوهات تصل مدتها إلى ساعة واحدة بدقة وسائط عالية.
- طرق المعالجة: تتوافق نماذج Gemini 3.8 Flash و3.7 Flash و3.6 Flash و3.5 Flash Lite والنماذج الأحدث مع طريقتَين لمعالجة الفيديوهات:
- ثابتة: يتم استخراج اللقطات بمعدّل لقطة واحدة في الثانية ووضعها في السياق (الإعداد التلقائي لجميع النماذج). تتم معالجة الصوت بمعدل 1 كيلوبت في الثانية (قناة واحدة). تتم إضافة الطوابع الزمنية كل ثانية. هذا الخيار هو الأفضل للمقاطع القصيرة أو عندما تكون كل لقطة مهمة (مثل الفحص لقطة بلقطة). يُرجى العِلم أنّ تسلسلات الإجراءات السريعة قد تفقد بعض التفاصيل بسبب معدّل أخذ العيّنات البالغ إطارًا واحدًا في الثانية.
- التفاعلية: يتنقّل النموذج ديناميكيًا في الفيديو، ويحمّل النص و/أو الإطارات و/أو الصوت عند الطلب. يستخدم هذا النموذج عددًا أقل من الرموز المميزة بنسبة تصل إلى %88 للمحتوى الطويل، ولكن قد تزيد مدة TTFT قليلاً في المقاطع القصيرة (أقل من 5 دقائق) بسبب عمليات الاستدلال الداخلية والرحلات المتكررة للأداة قبل بدء عملية الإنشاء. الأفضل للفيديوهات الطويلة لتحسين تكاليف الرموز المميّزة وجودة الردود. متوافق مع 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(مثلاً،01:15للإشارة إلى دقيقة واحدة و15 ثانية). - موضع الطلب: في حال الجمع بين نص وفيديو واحد، ضَع طلب النص
بعد جزء الفيديو في مصفوفة
input. - مهلات الطلبات الطويلة: بالنسبة إلى الفيديوهات التي تتطلّب وقت معالجة أطول أو تتضمّن الاستدلال المتعدّد الخطوات المعقّد، استخدِم البث (
stream=True) أو التنفيذ في الخلفية (background=True). قد تتجاوز الطلبات المتزامنة وغير المتعلّقة بالبث والتي تتضمّن عمليات إعادة محاولة في الخلفية في ظل الطلب المرتفع مدة صلاحية الرمز المميز للمصادقة أو الاتصال، ما قد يؤدي إلى ظهور أخطاء غير متوقّعة من النوع401 Unauthorizedأو أخطاء المهلة. يؤدي البث إلى إبقاء الاتصال نشطًا وعرض عملية الاستدلال الوسيطة ومستوى التقدّم في طلبات استخدام الأدوات.
الخطوات التالية
- درجة دقة الوسائط: يمكنك التحكّم في درجة دقة إطارات الفيديو لتحقيق التوازن بين الجودة واستخدام الرموز المميزة.
- الرموز المميزة: يمكنك التعرّف على طريقة تقسيم محتوى الفيديو إلى رموز مميزة في وضعَي المعالجة الثابتة والمعالجة المستندة إلى الوكيل.
- تعليمات النظام: تتيح لك تعليمات النظام توجيه سلوك النموذج استنادًا إلى احتياجاتك وحالات الاستخدام المحدّدة.
- Files API: مزيد من المعلومات حول تحميل الملفات وإدارتها لاستخدامها مع Gemini
- استراتيجيات إنشاء الطلبات باستخدام الملفات: يتيح Gemini API إنشاء الطلبات باستخدام بيانات نصية وصور وملفات صوتية وفيديوهات، ويُعرف ذلك أيضًا باسم إنشاء الطلبات المتعددة الوسائط.
- إرشادات الأمان: في بعض الأحيان، تُنشئ نماذج الذكاء الاصطناعي التوليدي نتائج غير متوقعة، مثل نتائج غير دقيقة أو متحيزة أو مسيئة. تُعدّ المعالجة اللاحقة والتقييم البشري ضروريين للحدّ من خطر الأضرار الناجمة عن هذه النتائج.