Skip to main content

gemini-video-input

Describe a Youtube Video

See Live Demo built using these code snippets

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."
]);

Describing local videos with Gemini

See Live Demo built using these code snippets

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;
}
}