فهم الفيديو

للتعرف على كيفية إنشاء الفيديو، راجع دليل Gemini Omni Flash.

تستطيع نماذج Gemini معالجة مقاطع الفيديو، مما يتيح العديد من حالات استخدام المطورين الرائدة التي كانت تتطلب تاريخياً نماذج خاصة بالمجال. تتضمن بعض قدرات الرؤية في Gemini القدرة على: وصف وتقسيم واستخراج المعلومات من مقاطع الفيديو، والإجابة على الأسئلة المتعلقة بمحتوى الفيديو، والإشارة إلى طوابع زمنية محددة داخل الفيديو.

يمكنك تقديم مقاطع الفيديو كمدخلات لبرنامج Gemini بالطرق التالية:

طريقة الإرسال الحجم الأقصى حالة الاستخدام الموصى بها
واجهة برمجة تطبيقات الملفات 20 جيجابايت (مدفوعة) / 2 جيجابايت (مجانية) الملفات الكبيرة (100 ميجابايت فأكثر)، مقاطع الفيديو الطويلة (10 دقائق فأكثر)، الملفات القابلة لإعادة الاستخدام.
تسجيل التخزين السحابي 2 جيجابايت (لكل ملف، بدون حدود للتخزين) ملفات كبيرة (100 ميجابايت فأكثر)، مقاطع فيديو طويلة (10 دقائق فأكثر)، ملفات دائمة وقابلة لإعادة الاستخدام.
البيانات المضمنة أقل من 100 ميجابايت ملفات صغيرة (أقل من 100 ميجابايت)، مدة قصيرة (أقل من دقيقة واحدة)، مدخلات لمرة واحدة.
روابط يوتيوب لا ينطبق مقاطع فيديو عامة على يوتيوب.

ملاحظة: يوصى باستخدام 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

استخدم دائمًا واجهة برمجة تطبيقات الملفات عندما يكون حجم الطلب الإجمالي (بما في ذلك الملف، والمطالبة النصية، وتعليمات النظام، وما إلى ذلك) أكبر من 20 ميجابايت، أو مدة الفيديو كبيرة، أو إذا كنت تنوي استخدام نفس الفيديو في مطالبات متعددة. تقبل واجهة برمجة تطبيقات الملفات تنسيقات ملفات الفيديو مباشرةً.

لمزيد من المعلومات حول العمل باستخدام ملفات الوسائط، يُرجى الاطّلاع على Files 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

أرسل روابط يوتيوب

يمكنك تمرير روابط يوتيوب مباشرةً إلى واجهة برمجة تطبيقات Gemini كجزء من طلبك كما يلي:

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 ساعات من فيديوهات يوتيوب يومياً.
  • بالنسبة للفئة المدفوعة، لا يوجد حد أقصى لطول الفيديو.
  • بالنسبة للطرازات السابقة لإصدار 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/mp4
  • video/mpeg
  • video/mov
  • video/avi
  • video/x-flv
  • video/mpg
  • video/webm
  • video/wmv
  • video/3gpp

التفاصيل الفنية حول الفيديوهات

  • النماذج المتوافقة والسياق: يمكن لجميع نماذج Gemini معالجة بيانات الفيديو.
    • يمكن للنماذج التي تتضمّن قدرة استيعاب مليون رمز مميّز معالجة فيديوهات تصل مدتها إلى 3 ساعات تلقائيًا (بدقة وسائط منخفضة)، أو فيديوهات تصل مدتها إلى ساعة واحدة بدقة وسائط عالية.
  • طرق المعالجة: تتوافق نماذج Gemini 3.8 Flash و3.7 Flash و3.6 Flash و3.5 Flash Lite والنماذج الأحدث مع طريقتَين لمعالجة الفيديوهات:
    • Static: يتم استخراج الإطارات بمعدل 1 إطار في الثانية ووضعها في السياق (الوضع الافتراضي لجميع النماذج). تتم معالجة الصوت بمعدل 1 كيلوبت في الثانية (قناة واحدة). تُضاف الطوابع الزمنية كل ثانية. الأفضل للمقاطع القصيرة أو عندما تكون كل لقطة مهمة (مثل الفحص إطارًا بإطار). لاحظ أن مشاهد الحركة السريعة قد تفقد بعض التفاصيل بسبب معدل أخذ العينات البالغ 1 إطار في الثانية.
    • Agentic: يقوم النموذج بالتنقل ديناميكيًا في الفيديو، ويقوم بتحميل النص و/أو الإطارات و/أو الصوت عند الطلب. يؤدي هذا إلى استخدام رموز أقل بنسبة تصل إلى 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 مستقلة: يمكنك ضبط كليهما على نفس مدخل الفيديو.

للحصول على مزيد من التفاصيل حول حسابات الرموز، راجع دليل tokens.

  • تنسيق الطابع الزمني: عند الإشارة إلى لحظات محددة في مقطع فيديو ضمن مطالبتك، استخدم التنسيق MM:SS (على سبيل المثال، 01:15 لمدة دقيقة واحدة و15 ثانية).
  • وضع الموجه: إذا كنت تجمع بين نص وفيديو واحد، فضع موجه النص بعد جزء الفيديو في المصفوفة input.
  • مهلة للطلبات الطويلة: بالنسبة للفيديوهات التي تتطلب وقت معالجة ممتدًا أو استدلالًا معقدًا متعدد الخطوات، استخدم البث (stream=True) أو التنفيذ في الخلفية (background=True). قد تتجاوز الطلبات المتزامنة غير المتدفقة، التي تشهد إعادة محاولات من جانب الخادم الخلفي تحت ضغط عالٍ، فترات صلاحية الاتصال أو رمز المصادقة، مما قد يظهر على شكل 401 Unauthorized غير متوقع أو أخطاء مهلة. يحافظ البث على الاتصال نشطًا ويعرض عملية التفكير الوسيطة وتقدم استدعاء الأدوات.

الخطوات التالية

  • دقة الوسائط: التحكم في دقة إطارات الفيديو لتحقيق التوازن بين الجودة واستخدام الرموز.
  • الرموز المميزة: يمكنك التعرّف على طريقة تقسيم محتوى الفيديو إلى رموز مميزة في وضعَي المعالجة الثابتة والمعالجة المستندة إلى الوكيل.
  • تعليمات النظام: تتيح لك تعليمات النظام توجيه سلوك النموذج استنادًا إلى احتياجاتك وحالات الاستخدام المحدّدة.
  • Files API: مزيد من المعلومات حول تحميل الملفات وإدارتها لاستخدامها مع Gemini
  • استراتيجيات المطالبة بالملفات: تدعم واجهة برمجة تطبيقات Gemini المطالبة بالنصوص والصور والصوت والفيديو، والمعروفة أيضًا باسم المطالبة متعددة الوسائط.
  • إرشادات الأمان: في بعض الأحيان، تُنشئ نماذج الذكاء الاصطناعي التوليدي نتائج غير متوقعة، مثل نتائج غير دقيقة أو متحيزة أو مسيئة. تُعدّ المعالجة اللاحقة والتقييم البشري ضروريين للحدّ من خطر الأضرار الناجمة عن هذه النتائج.