gemini-video-input
Describe a Youtube Video
See Live Demo built using these code snippets
- Javascript
- Python
import { GoogleGenerativeAI } from "@google/generative-ai";
const genAI = new GoogleGenerativeAI(apiKey);
const model = genAI.getGenerativeModel({ model: "gemini-2.0-flash" });
const result = await model.generateContent([
{
fileData: {
mimeType: "video/webm",
fileUri: youtubeUrl
}
},
"Describe what you see in this video in detail."
]);
from google import genai
from google.genai.types import Part
client = genai.Client()
YOUTUBE_VIDEO_URL = (
"https://www.youtube.com/watch?v=O_W_VGUeHVI"
)
response = client.models.generate_content(
model="gemini-2.0-flash",
contents=[
Part.from_uri(
file_uri=YOUTUBE_VIDEO_URL,
mime_type="video/webm",
),
"Describe what you see in this video in detail."
]
)
print(response.text)
Describing local videos with Gemini
See Live Demo built using these code snippets
- Javascript
- Python
import { GoogleGenerativeAI } from "@google/generative-ai";
import * as fs from "node:fs";
async function describeVideo(videoPath, apiKey) {
// Initialize the Gemini API client
const genAI = new GoogleGenerativeAI(apiKey);
const model = genAI.getGenerativeModel({ model: "gemini-2.0-flash" });
try {
// Read the video file and convert to base64
const videoBytes = fs.readFileSync(videoPath, { encoding: "base64" });
console.log("Generating video description...");
const result = await model.generateContent([
"Please describe what you see in this video in detail. Include any notable events, " +
"people, objects, or actions that appear.",
{
inlineData: {
data: videoBytes,
mimeType: "video/mp4",
},
},
]);
console.log(result.response.text());
} catch (error) {
console.error("Error processing video:", error);
throw error;
}
}
from google import genai
def describe_video(video_path, api_key):
client = genai.Client(api_key=api_key)
print("Uploading video file...")
video_file = client.files.upload(file=video_path)
print(f"Completed upload: {video_file.uri}")
print("Waiting for video processing...")
while video_file.state.name == "PROCESSING":
print('.', end='', flush=True)
time.sleep(1)
video_file = client.files.get(name=video_file.name)
if video_file.state.name == "FAILED":
raise ValueError(f"Video processing failed: {video_file.state.name}")
print("\nGenerating video description...")
response = client.models.generate_content(
model="gemini-2.0-flash",
contents=[
video_file,
"Please describe what you see in this video in detail. Include any notable events, "
"people, objects, or actions that appear."
]
)
print(response.text)