Skip to content

Analyze Video

Shows how to generate text from video content using open-ended analysis.

This example assumes using TwelveLabs; is in scope and apiKey contains your TwelveLabs API key.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
using var client = new TwelveLabsClient(apiKey);

// Retrieve an indexed video to analyze.
var indexes = await client.SubpackageIndexes.ListAsync(
    xApiKey: apiKey);
var indexId = indexes.Data?.FirstOrDefault()?.Id
    ?? throw new AssertInconclusiveException("No indexes found. Create an index and upload videos first.");

var assets = await client.SubpackageIndexesSubpackageIndexesIndexedAssets.ListAsync(
    indexId: indexId,
    xApiKey: apiKey);
var videoId = assets.Data?.FirstOrDefault()?.Id
    ?? throw new AssertInconclusiveException("No indexed assets found in the index.");

// Generate a summary of the video using open-ended analysis with streaming disabled.
var response = await client.AnalyzeAsync(
    xApiKey: apiKey,
    videoId: videoId,
    prompt: "Provide a brief summary of this video, including the main topic and key points.",
    stream: false);

// The non-streaming response contains the generated text and token usage.
var result = response.NonStreamAnalyzeResponse;
Console.WriteLine($"Generated text: {result!.Data}");
Console.WriteLine($"Finish reason: {result.FinishReason}");