Analyze videos for labels

The Video Intelligence API can identify entities shown in video footage using the LABEL_DETECTION feature. This feature identifies objects, locations, activities, animal species, products, and more.

The analysis can be compartmentalized as follows:

  • Frame level:
    Entities are identified and labeled within each frame (with one frame per second sampling).
  • Shot level:
    Shots are automatically detected within every segment (or video). Entities are then identified and labeled within each shot.
  • Segment level:
    User-selected segments of a video can be specified for analysis by stipulating beginning and ending time offsets for the purposes of annotation (see VideoSegment ). Entities are then identified and labeled within each segment. If no segments are specified, the whole video is treated as one segment.

Annotate a local file

Here is an example of performing video analysis for labels on a local file.

Looking for something more in-depth? Check out our detailed Python tutorial .

REST

Send the process request

The following shows how to send a POST request to the videos:annotate method. You can configure the LabelDetectionMode to shot-level and/or frame-level annotations. We recommend using SHOT_AND_FRAME_MODE . The example uses the access token for a service account set up for the project using the Google Cloud CLI. For instructions on installing the Google Cloud CLI, setting up a project with a service account, and obtaining an access token, see the Video Intelligence quickstart .

Before using any of the request data, make the following replacements:

HTTP method and URL:

POST https://videointelligence.googleapis.com/v1/videos:annotate

Request JSON body:

{
  "inputContent": " BASE64_ENCODED_CONTENT 
",
  "features": ["LABEL_DETECTION"],
}

To send your request, expand one of these options:

You should receive a JSON response similar to the following:

{
  "name": "projects/ PROJECT_NUMBER 
/locations/ LOCATION_ID 
/operations/ OPERATION_ID 
"
}

If the request is successful, Video Intelligence returns the name of your operation.

Get the results

To get the results of your request, you must send a GET request to the projects.locations.operations resource. The following shows how to send such a request.

Before using any of the request data, make the following replacements:

  • OPERATION_NAME : the name of the operation as returned by the Video Intelligence API. The operation name has the format projects/ PROJECT_NUMBER /locations/ LOCATION_ID /operations/ OPERATION_ID
  • PROJECT_NUMBER : The numeric identifier for your Google Cloud project

HTTP method and URL:

GET https://videointelligence.googleapis.com/v1/ OPERATION_NAME 

To send your request, expand one of these options:

You should receive a JSON response similar to the following:

Go

  func 
  
 label 
 ( 
 w 
  
 io 
 . 
 Writer 
 , 
  
 file 
  
 string 
 ) 
  
 error 
  
 { 
  
 ctx 
  
 := 
  
 context 
 . 
 Background 
 () 
  
 client 
 , 
  
 err 
  
 := 
  
 video 
 . 
 NewClient 
 ( 
 ctx 
 ) 
  
 if 
  
 err 
  
 != 
  
 nil 
  
 { 
  
 return 
  
 fmt 
 . 
 Errorf 
 ( 
 "video.NewClient: %w" 
 , 
  
 err 
 ) 
  
 } 
  
 defer 
  
 client 
 . 
 Close 
 () 
  
 fileBytes 
 , 
  
 err 
  
 := 
  
 os 
 . 
 ReadFile 
 ( 
 file 
 ) 
  
 if 
  
 err 
  
 != 
  
 nil 
  
 { 
  
 return 
  
 err 
  
 } 
  
 op 
 , 
  
 err 
  
 := 
  
 client 
 . 
 AnnotateVideo 
 ( 
 ctx 
 , 
  
& videopb 
 . 
 AnnotateVideoRequest 
 { 
  
 Features 
 : 
  
 [] 
 videopb 
 . 
 Feature 
 { 
  
 videopb 
 . 
 Feature_LABEL_DETECTION 
 , 
  
 }, 
  
 InputContent 
 : 
  
 fileBytes 
 , 
  
 }) 
  
 if 
  
 err 
  
 != 
  
 nil 
  
 { 
  
 return 
  
 fmt 
 . 
 Errorf 
 ( 
 "AnnotateVideo: %w" 
 , 
  
 err 
 ) 
  
 } 
  
 resp 
 , 
  
 err 
  
 := 
  
 op 
 . 
 Wait 
 ( 
 ctx 
 ) 
  
 if 
  
 err 
  
 != 
  
 nil 
  
 { 
  
 return 
  
 fmt 
 . 
 Errorf 
 ( 
 "Wait: %w" 
 , 
  
 err 
 ) 
  
 } 
  
 printLabels 
  
 := 
  
 func 
 ( 
 labels 
  
 [] 
 * 
 videopb 
 . 
 LabelAnnotation 
 ) 
  
 { 
  
 for 
  
 _ 
 , 
  
 label 
  
 := 
  
 range 
  
 labels 
  
 { 
  
 fmt 
 . 
 Fprintf 
 ( 
 w 
 , 
  
 "\tDescription: %s\n" 
 , 
  
 label 
 . 
 Entity 
 . 
 Description 
 ) 
  
 for 
  
 _ 
 , 
  
 category 
  
 := 
  
 range 
  
 label 
 . 
 CategoryEntities 
  
 { 
  
 fmt 
 . 
 Fprintf 
 ( 
 w 
 , 
  
 "\t\tCategory: %s\n" 
 , 
  
 category 
 . 
 Description 
 ) 
  
 } 
  
 for 
  
 _ 
 , 
  
 segment 
  
 := 
  
 range 
  
 label 
 . 
 Segments 
  
 { 
  
 start 
 , 
  
 _ 
  
 := 
  
 ptypes 
 . 
 Duration 
 ( 
 segment 
 . 
 Segment 
 . 
 StartTimeOffset 
 ) 
  
 end 
 , 
  
 _ 
  
 := 
  
 ptypes 
 . 
 Duration 
 ( 
 segment 
 . 
 Segment 
 . 
 EndTimeOffset 
 ) 
  
 fmt 
 . 
 Fprintf 
 ( 
 w 
 , 
  
 "\t\tSegment: %s to %s\n" 
 , 
  
 start 
 , 
  
 end 
 ) 
  
 } 
  
 } 
  
 } 
  
 // A single video was processed. Get the first result. 
  
 result 
  
 := 
  
 resp 
 . 
 AnnotationResults 
 [ 
 0 
 ] 
  
 fmt 
 . 
 Fprintln 
 ( 
 w 
 , 
  
 "SegmentLabelAnnotations:" 
 ) 
  
 printLabels 
 ( 
 result 
 . 
 SegmentLabelAnnotations 
 ) 
  
 fmt 
 . 
 Fprintln 
 ( 
 w 
 , 
  
 "ShotLabelAnnotations:" 
 ) 
  
 printLabels 
 ( 
 result 
 . 
 ShotLabelAnnotations 
 ) 
  
 fmt 
 . 
 Fprintln 
 ( 
 w 
 , 
  
 "FrameLabelAnnotations:" 
 ) 
  
 printLabels 
 ( 
 result 
 . 
 FrameLabelAnnotations 
 ) 
  
 return 
  
 nil 
 } 
 

Java

  // Instantiate a com.google.cloud.videointelligence.v1.VideoIntelligenceServiceClient 
 try 
  
 ( 
 VideoIntelligenceServiceClient 
  
 client 
  
 = 
  
 VideoIntelligenceServiceClient 
 . 
 create 
 ()) 
  
 { 
  
 // Read file and encode into Base64 
  
 Path 
  
 path 
  
 = 
  
 Paths 
 . 
 get 
 ( 
 filePath 
 ); 
  
 byte 
 [] 
  
 data 
  
 = 
  
 Files 
 . 
 readAllBytes 
 ( 
 path 
 ); 
  
 AnnotateVideoRequest 
  
 request 
  
 = 
  
 AnnotateVideoRequest 
 . 
 newBuilder 
 () 
  
 . 
 setInputContent 
 ( 
 ByteString 
 . 
 copyFrom 
 ( 
 data 
 )) 
  
 . 
 addFeatures 
 ( 
 Feature 
 . 
 LABEL_DETECTION 
 ) 
  
 . 
 build 
 (); 
  
 // Create an operation that will contain the response when the operation completes. 
  
 OperationFuture<AnnotateVideoResponse 
 , 
  
 AnnotateVideoProgress 
>  
 response 
  
 = 
  
 client 
 . 
 annotateVideoAsync 
 ( 
 request 
 ); 
  
 System 
 . 
 out 
 . 
 println 
 ( 
 "Waiting for operation to complete..." 
 ); 
  
 for 
  
 ( 
 VideoAnnotationResults 
  
 results 
  
 : 
  
 response 
 . 
 get 
 (). 
 getAnnotationResultsList 
 ()) 
  
 { 
  
 // process video / segment level label annotations 
  
 System 
 . 
 out 
 . 
 println 
 ( 
 "Locations: " 
 ); 
  
 for 
  
 ( 
 LabelAnnotation 
  
 labelAnnotation 
  
 : 
  
 results 
 . 
 getSegmentLabelAnnotationsList 
 ()) 
  
 { 
  
 System 
 . 
 out 
 . 
 println 
 ( 
 "Video label: " 
  
 + 
  
 labelAnnotation 
 . 
 getEntity 
 (). 
 getDescription 
 ()); 
  
 // categories 
  
 for 
  
 ( 
 Entity 
  
 categoryEntity 
  
 : 
  
 labelAnnotation 
 . 
 getCategoryEntitiesList 
 ()) 
  
 { 
  
 System 
 . 
 out 
 . 
 println 
 ( 
 "Video label category: " 
  
 + 
  
 categoryEntity 
 . 
 getDescription 
 ()); 
  
 } 
  
 // segments 
  
 for 
  
 ( 
 LabelSegment 
  
 segment 
  
 : 
  
 labelAnnotation 
 . 
 getSegmentsList 
 ()) 
  
 { 
  
 double 
  
 startTime 
  
 = 
  
 segment 
 . 
 getSegment 
 (). 
 getStartTimeOffset 
 (). 
 getSeconds 
 () 
  
 + 
  
 segment 
 . 
 getSegment 
 (). 
 getStartTimeOffset 
 (). 
 getNanos 
 () 
  
 / 
  
 1e9 
 ; 
  
 double 
  
 endTime 
  
 = 
  
 segment 
 . 
 getSegment 
 (). 
 getEndTimeOffset 
 (). 
 getSeconds 
 () 
  
 + 
  
 segment 
 . 
 getSegment 
 (). 
 getEndTimeOffset 
 (). 
 getNanos 
 () 
  
 / 
  
 1e9 
 ; 
  
 System 
 . 
 out 
 . 
 printf 
 ( 
 "Segment location: %.3f:%.2f\n" 
 , 
  
 startTime 
 , 
  
 endTime 
 ); 
  
 System 
 . 
 out 
 . 
 println 
 ( 
 "Confidence: " 
  
 + 
  
 segment 
 . 
 getConfidence 
 ()); 
  
 } 
  
 } 
  
 // process shot label annotations 
  
 for 
  
 ( 
 LabelAnnotation 
  
 labelAnnotation 
  
 : 
  
 results 
 . 
 getShotLabelAnnotationsList 
 ()) 
  
 { 
  
 System 
 . 
 out 
 . 
 println 
 ( 
 "Shot label: " 
  
 + 
  
 labelAnnotation 
 . 
 getEntity 
 (). 
 getDescription 
 ()); 
  
 // categories 
  
 for 
  
 ( 
 Entity 
  
 categoryEntity 
  
 : 
  
 labelAnnotation 
 . 
 getCategoryEntitiesList 
 ()) 
  
 { 
  
 System 
 . 
 out 
 . 
 println 
 ( 
 "Shot label category: " 
  
 + 
  
 categoryEntity 
 . 
 getDescription 
 ()); 
  
 } 
  
 // segments 
  
 for 
  
 ( 
 LabelSegment 
  
 segment 
  
 : 
  
 labelAnnotation 
 . 
 getSegmentsList 
 ()) 
  
 { 
  
 double 
  
 startTime 
  
 = 
  
 segment 
 . 
 getSegment 
 (). 
 getStartTimeOffset 
 (). 
 getSeconds 
 () 
  
 + 
  
 segment 
 . 
 getSegment 
 (). 
 getStartTimeOffset 
 (). 
 getNanos 
 () 
  
 / 
  
 1e9 
 ; 
  
 double 
  
 endTime 
  
 = 
  
 segment 
 . 
 getSegment 
 (). 
 getEndTimeOffset 
 (). 
 getSeconds 
 () 
  
 + 
  
 segment 
 . 
 getSegment 
 (). 
 getEndTimeOffset 
 (). 
 getNanos 
 () 
  
 / 
  
 1e9 
 ; 
  
 System 
 . 
 out 
 . 
 printf 
 ( 
 "Segment location: %.3f:%.2f\n" 
 , 
  
 startTime 
 , 
  
 endTime 
 ); 
  
 System 
 . 
 out 
 . 
 println 
 ( 
 "Confidence: " 
  
 + 
  
 segment 
 . 
 getConfidence 
 ()); 
  
 } 
  
 } 
  
 // process frame label annotations 
  
 for 
  
 ( 
 LabelAnnotation 
  
 labelAnnotation 
  
 : 
  
 results 
 . 
 getFrameLabelAnnotationsList 
 ()) 
  
 { 
  
 System 
 . 
 out 
 . 
 println 
 ( 
 "Frame label: " 
  
 + 
  
 labelAnnotation 
 . 
 getEntity 
 (). 
 getDescription 
 ()); 
  
 // categories 
  
 for 
  
 ( 
 Entity 
  
 categoryEntity 
  
 : 
  
 labelAnnotation 
 . 
 getCategoryEntitiesList 
 ()) 
  
 { 
  
 System 
 . 
 out 
 . 
 println 
 ( 
 "Frame label category: " 
  
 + 
  
 categoryEntity 
 . 
 getDescription 
 ()); 
  
 } 
  
 // segments 
  
 for 
  
 ( 
 LabelSegment 
  
 segment 
  
 : 
  
 labelAnnotation 
 . 
 getSegmentsList 
 ()) 
  
 { 
  
 double 
  
 startTime 
  
 = 
  
 segment 
 . 
 getSegment 
 (). 
 getStartTimeOffset 
 (). 
 getSeconds 
 () 
  
 + 
  
 segment 
 . 
 getSegment 
 (). 
 getStartTimeOffset 
 (). 
 getNanos 
 () 
  
 / 
  
 1e9 
 ; 
  
 double 
  
 endTime 
  
 = 
  
 segment 
 . 
 getSegment 
 (). 
 getEndTimeOffset 
 (). 
 getSeconds 
 () 
  
 + 
  
 segment 
 . 
 getSegment 
 (). 
 getEndTimeOffset 
 (). 
 getNanos 
 () 
  
 / 
  
 1e9 
 ; 
  
 System 
 . 
 out 
 . 
 printf 
 ( 
 "Segment location: %.3f:%.2f\n" 
 , 
  
 startTime 
 , 
  
 endTime 
 ); 
  
 System 
 . 
 out 
 . 
 println 
 ( 
 "Confidence: " 
  
 + 
  
 segment 
 . 
 getConfidence 
 ()); 
  
 } 
  
 } 
  
 } 
 } 
 

Node.js

  // Imports the Google Cloud Video Intelligence library + Node's fs library 
 const 
  
 video 
  
 = 
  
 require 
 ( 
 ' @google-cloud/video-intelligence 
' 
 ). 
 v1 
 ; 
 const 
  
 fs 
  
 = 
  
 require 
 ( 
 'fs' 
 ); 
 const 
  
 util 
  
 = 
  
 require 
 ( 
 'util' 
 ); 
 // Creates a client 
 const 
  
 client 
  
 = 
  
 new 
  
 video 
 . 
  VideoIntelligenceServiceClient 
 
 (); 
 /** 
 * TODO(developer): Uncomment the following line before running the sample. 
 */ 
 // const path = 'Local file to analyze, e.g. ./my-file.mp4'; 
 // Reads a local video file and converts it to base64 
 const 
  
 readFile 
  
 = 
  
 util 
 . 
 promisify 
 ( 
 fs 
 . 
 readFile 
 ); 
 const 
  
 file 
  
 = 
  
 await 
  
 readFile 
 ( 
 path 
 ); 
 const 
  
 inputContent 
  
 = 
  
 file 
 . 
 toString 
 ( 
 'base64' 
 ); 
 // Constructs request 
 const 
  
 request 
  
 = 
  
 { 
  
 inputContent 
 : 
  
 inputContent 
 , 
  
 features 
 : 
  
 [ 
 'LABEL_DETECTION' 
 ], 
 }; 
 // Detects labels in a video 
 const 
  
 [ 
 operation 
 ] 
  
 = 
  
 await 
  
 client 
 . 
 annotateVideo 
 ( 
 request 
 ); 
 console 
 . 
 log 
 ( 
 'Waiting for operation to complete...' 
 ); 
 const 
  
 [ 
 operationResult 
 ] 
  
 = 
  
 await 
  
 operation 
 . 
 promise 
 (); 
 // Gets annotations for video 
 const 
  
 annotations 
  
 = 
  
 operationResult 
 . 
 annotationResults 
 [ 
 0 
 ]; 
 const 
  
 labels 
  
 = 
  
 annotations 
 . 
 segmentLabelAnnotations 
 ; 
 labels 
 . 
 forEach 
 ( 
 label 
  
 = 
>  
 { 
  
 console 
 . 
 log 
 ( 
 `Label 
 ${ 
 label 
 . 
 entity 
 . 
 description 
 } 
 occurs at:` 
 ); 
  
 label 
 . 
 segments 
 . 
 forEach 
 ( 
 segment 
  
 = 
>  
 { 
  
 const 
  
 time 
  
 = 
  
 segment 
 . 
 segment 
 ; 
  
 if 
  
 ( 
 time 
 . 
 startTimeOffset 
 . 
 seconds 
  
 === 
  
 undefined 
 ) 
  
 { 
  
 time 
 . 
 startTimeOffset 
 . 
 seconds 
  
 = 
  
 0 
 ; 
  
 } 
  
 if 
  
 ( 
 time 
 . 
 startTimeOffset 
 . 
 nanos 
  
 === 
  
 undefined 
 ) 
  
 { 
  
 time 
 . 
 startTimeOffset 
 . 
 nanos 
  
 = 
  
 0 
 ; 
  
 } 
  
 if 
  
 ( 
 time 
 . 
 endTimeOffset 
 . 
 seconds 
  
 === 
  
 undefined 
 ) 
  
 { 
  
 time 
 . 
 endTimeOffset 
 . 
 seconds 
  
 = 
  
 0 
 ; 
  
 } 
  
 if 
  
 ( 
 time 
 . 
 endTimeOffset 
 . 
 nanos 
  
 === 
  
 undefined 
 ) 
  
 { 
  
 time 
 . 
 endTimeOffset 
 . 
 nanos 
  
 = 
  
 0 
 ; 
  
 } 
  
 console 
 . 
 log 
 ( 
  
 `\tStart: 
 ${ 
 time 
 . 
 startTimeOffset 
 . 
 seconds 
 } 
 ` 
  
 + 
  
 `. 
 ${ 
 ( 
 time 
 . 
 startTimeOffset 
 . 
 nanos 
  
 / 
  
 1e6 
 ). 
 toFixed 
 ( 
 0 
 ) 
 } 
 s` 
  
 ); 
  
 console 
 . 
 log 
 ( 
  
 `\tEnd: 
 ${ 
 time 
 . 
 endTimeOffset 
 . 
 seconds 
 } 
 .` 
  
 + 
  
 ` 
 ${ 
 ( 
 time 
 . 
 endTimeOffset 
 . 
 nanos 
  
 / 
  
 1e6 
 ). 
 toFixed 
 ( 
 0 
 ) 
 } 
 s` 
  
 ); 
  
 console 
 . 
 log 
 ( 
 `\tConfidence: 
 ${ 
 segment 
 . 
 confidence 
 } 
 ` 
 ); 
  
 }); 
 }); 
 

Python

For more information on installing and using the Video Intelligence API Client Library for Python, refer to Video Intelligence API Client Libraries .
  """Detect labels given a file path.""" 
 video_client 
 = 
 videointelligence 
 . 
 VideoIntelligenceServiceClient 
 () 
 features 
 = 
 [ 
 videointelligence 
 . 
 Feature 
 . 
 LABEL_DETECTION 
 ] 
 with 
 io 
 . 
 open 
 ( 
 path 
 , 
 "rb" 
 ) 
 as 
 movie 
 : 
 input_content 
 = 
 movie 
 . 
 read 
 () 
 operation 
 = 
 video_client 
 . 
 annotate_video 
 ( 
 request 
 = 
 { 
 "features" 
 : 
 features 
 , 
 "input_content" 
 : 
 input_content 
 } 
 ) 
 print 
 ( 
 " 
 \n 
 Processing video for label annotations:" 
 ) 
 result 
 = 
 operation 
 . 
 result 
 ( 
 timeout 
 = 
 90 
 ) 
 print 
 ( 
 " 
 \n 
 Finished processing." 
 ) 
 # Process video/segment level label annotations 
 segment_labels 
 = 
 result 
 . 
 annotation_results 
 [ 
 0 
 ] 
 . 
 segment_label_annotations 
 for 
 i 
 , 
 segment_label 
 in 
 enumerate 
 ( 
 segment_labels 
 ): 
 print 
 ( 
 "Video label description: 
 {} 
 " 
 . 
 format 
 ( 
 segment_label 
 . 
 entity 
 . 
 description 
 )) 
 for 
 category_entity 
 in 
 segment_label 
 . 
 category_entities 
 : 
 print 
 ( 
 " 
 \t 
 Label category description: 
 {} 
 " 
 . 
 format 
 ( 
 category_entity 
 . 
 description 
 ) 
 ) 
 for 
 i 
 , 
 segment 
 in 
 enumerate 
 ( 
 segment_label 
 . 
 segments 
 ): 
 start_time 
 = 
 ( 
 segment 
 . 
 segment 
 . 
 start_time_offset 
 . 
 seconds 
 + 
 segment 
 . 
 segment 
 . 
 start_time_offset 
 . 
 microseconds 
 / 
 1e6 
 ) 
 end_time 
 = 
 ( 
 segment 
 . 
 segment 
 . 
 end_time_offset 
 . 
 seconds 
 + 
 segment 
 . 
 segment 
 . 
 end_time_offset 
 . 
 microseconds 
 / 
 1e6 
 ) 
 positions 
 = 
 " 
 {} 
 s to 
 {} 
 s" 
 . 
 format 
 ( 
 start_time 
 , 
 end_time 
 ) 
 confidence 
 = 
 segment 
 . 
 confidence 
 print 
 ( 
 " 
 \t 
 Segment 
 {} 
 : 
 {} 
 " 
 . 
 format 
 ( 
 i 
 , 
 positions 
 )) 
 print 
 ( 
 " 
 \t 
 Confidence: 
 {} 
 " 
 . 
 format 
 ( 
 confidence 
 )) 
 print 
 ( 
 " 
 \n 
 " 
 ) 
 # Process shot level label annotations 
 shot_labels 
 = 
 result 
 . 
 annotation_results 
 [ 
 0 
 ] 
 . 
 shot_label_annotations 
 for 
 i 
 , 
 shot_label 
 in 
 enumerate 
 ( 
 shot_labels 
 ): 
 print 
 ( 
 "Shot label description: 
 {} 
 " 
 . 
 format 
 ( 
 shot_label 
 . 
 entity 
 . 
 description 
 )) 
 for 
 category_entity 
 in 
 shot_label 
 . 
 category_entities 
 : 
 print 
 ( 
 " 
 \t 
 Label category description: 
 {} 
 " 
 . 
 format 
 ( 
 category_entity 
 . 
 description 
 ) 
 ) 
 for 
 i 
 , 
 shot 
 in 
 enumerate 
 ( 
 shot_label 
 . 
 segments 
 ): 
 start_time 
 = 
 ( 
 shot 
 . 
 segment 
 . 
 start_time_offset 
 . 
 seconds 
 + 
 shot 
 . 
 segment 
 . 
 start_time_offset 
 . 
 microseconds 
 / 
 1e6 
 ) 
 end_time 
 = 
 ( 
 shot 
 . 
 segment 
 . 
 end_time_offset 
 . 
 seconds 
 + 
 shot 
 . 
 segment 
 . 
 end_time_offset 
 . 
 microseconds 
 / 
 1e6 
 ) 
 positions 
 = 
 " 
 {} 
 s to 
 {} 
 s" 
 . 
 format 
 ( 
 start_time 
 , 
 end_time 
 ) 
 confidence 
 = 
 shot 
 . 
 confidence 
 print 
 ( 
 " 
 \t 
 Segment 
 {} 
 : 
 {} 
 " 
 . 
 format 
 ( 
 i 
 , 
 positions 
 )) 
 print 
 ( 
 " 
 \t 
 Confidence: 
 {} 
 " 
 . 
 format 
 ( 
 confidence 
 )) 
 print 
 ( 
 " 
 \n 
 " 
 ) 
 # Process frame level label annotations 
 frame_labels 
 = 
 result 
 . 
 annotation_results 
 [ 
 0 
 ] 
 . 
 frame_label_annotations 
 for 
 i 
 , 
 frame_label 
 in 
 enumerate 
 ( 
 frame_labels 
 ): 
 print 
 ( 
 "Frame label description: 
 {} 
 " 
 . 
 format 
 ( 
 frame_label 
 . 
 entity 
 . 
 description 
 )) 
 for 
 category_entity 
 in 
 frame_label 
 . 
 category_entities 
 : 
 print 
 ( 
 " 
 \t 
 Label category description: 
 {} 
 " 
 . 
 format 
 ( 
 category_entity 
 . 
 description 
 ) 
 ) 
 # Each frame_label_annotation has many frames, 
 # here we print information only about the first frame. 
 frame 
 = 
 frame_label 
 . 
 frames 
 [ 
 0 
 ] 
 time_offset 
 = 
 frame 
 . 
 time_offset 
 . 
 seconds 
 + 
 frame 
 . 
 time_offset 
 . 
 microseconds 
 / 
 1e6 
 print 
 ( 
 " 
 \t 
 First frame time offset: 
 {} 
 s" 
 . 
 format 
 ( 
 time_offset 
 )) 
 print 
 ( 
 " 
 \t 
 First frame confidence: 
 {} 
 " 
 . 
 format 
 ( 
 frame 
 . 
 confidence 
 )) 
 print 
 ( 
 " 
 \n 
 " 
 ) 
 

Additional languages

C#: Please follow the C# setup instructions on the client libraries page and then visit the Video Intelligence reference documentation for .NET.

PHP: Please follow the PHP setup instructions on the client libraries page and then visit the Video Intelligence reference documentation for PHP.

Ruby: Please follow the Ruby setup instructions on the client libraries page and then visit the Video Intelligence reference documentation for Ruby.

Annotate a file on Cloud Storage

Here is an example of performing video analysis for labels on a file located in Cloud Storage.

REST

For more information on installing and using the Video Intelligence API Client Library for Python, refer to Video Intelligence API Client Libraries .

Send the process request

The following shows how to send a POST request to the annotate method. The example uses the access token for a service account set up for the project using the Google Cloud CLI. For instructions on installing the Google Cloud CLI, setting up a project with a service account, and obtaining an access token, see the Video Intelligence quickstart .

Before using any of the request data, make the following replacements:

  • INPUT_URI : a Cloud Storage bucket that contains the file you want to annotate, including the file name. Must start with gs:// .
  • PROJECT_NUMBER : The numeric identifier for your Google Cloud project

HTTP method and URL:

POST https://videointelligence.googleapis.com/v1/videos:annotate

Request JSON body:

{
  "inputUri": " INPUT_URI 
",
  "features": ["LABEL_DETECTION"],
}

To send your request, expand one of these options:

You should receive a JSON response similar to the following:

{
  "name": "projects/ PROJECT_NUMBER 
/locations/ LOCATION_ID 
/operations/ OPERATION_ID 
"
}

If the request is successful, the Video Intelligence returns the name of your operation.

Get the results

To get the results of your request, you must send a GET request to the projects.locations.operations resource. The following shows how to send such a request.

Before using any of the request data, make the following replacements:

  • OPERATION_NAME : the name of the operation as returned by the Video Intelligence API. The operation name has the format projects/ PROJECT_NUMBER /locations/ LOCATION_ID /operations/ OPERATION_ID
  • PROJECT_NUMBER : The numeric identifier for your Google Cloud project

HTTP method and URL:

GET https://videointelligence.googleapis.com/v1/ OPERATION_NAME 

To send your request, expand one of these options:

You should receive a JSON response similar to the following:

Download annotation results

Copy the annotation from the source to the destination bucket: (see Copy files and objects )

gcloud storage cp gcs_uri gs://my-bucket

Note: If the output gcs uri is provided by the user, then the annotation is stored in that gcs uri.

Go

  func 
  
 labelURI 
 ( 
 w 
  
 io 
 . 
 Writer 
 , 
  
 file 
  
 string 
 ) 
  
 error 
  
 { 
  
 ctx 
  
 := 
  
 context 
 . 
 Background 
 () 
  
 client 
 , 
  
 err 
  
 := 
  
 video 
 . 
 NewClient 
 ( 
 ctx 
 ) 
  
 if 
  
 err 
  
 != 
  
 nil 
  
 { 
  
 return 
  
 fmt 
 . 
 Errorf 
 ( 
 "video.NewClient: %w" 
 , 
  
 err 
 ) 
  
 } 
  
 defer 
  
 client 
 . 
 Close 
 () 
  
 op 
 , 
  
 err 
  
 := 
  
 client 
 . 
 AnnotateVideo 
 ( 
 ctx 
 , 
  
& videopb 
 . 
 AnnotateVideoRequest 
 { 
  
 Features 
 : 
  
 [] 
 videopb 
 . 
 Feature 
 { 
  
 videopb 
 . 
 Feature_LABEL_DETECTION 
 , 
  
 }, 
  
 InputUri 
 : 
  
 file 
 , 
  
 }) 
  
 if 
  
 err 
  
 != 
  
 nil 
  
 { 
  
 return 
  
 fmt 
 . 
 Errorf 
 ( 
 "AnnotateVideo: %w" 
 , 
  
 err 
 ) 
  
 } 
  
 resp 
 , 
  
 err 
  
 := 
  
 op 
 . 
 Wait 
 ( 
 ctx 
 ) 
  
 if 
  
 err 
  
 != 
  
 nil 
  
 { 
  
 return 
  
 fmt 
 . 
 Errorf 
 ( 
 "Wait: %w" 
 , 
  
 err 
 ) 
  
 } 
  
 printLabels 
  
 := 
  
 func 
 ( 
 labels 
  
 [] 
 * 
 videopb 
 . 
 LabelAnnotation 
 ) 
  
 { 
  
 for 
  
 _ 
 , 
  
 label 
  
 := 
  
 range 
  
 labels 
  
 { 
  
 fmt 
 . 
 Fprintf 
 ( 
 w 
 , 
  
 "\tDescription: %s\n" 
 , 
  
 label 
 . 
 Entity 
 . 
 Description 
 ) 
  
 for 
  
 _ 
 , 
  
 category 
  
 := 
  
 range 
  
 label 
 . 
 CategoryEntities 
  
 { 
  
 fmt 
 . 
 Fprintf 
 ( 
 w 
 , 
  
 "\t\tCategory: %s\n" 
 , 
  
 category 
 . 
 Description 
 ) 
  
 } 
  
 for 
  
 _ 
 , 
  
 segment 
  
 := 
  
 range 
  
 label 
 . 
 Segments 
  
 { 
  
 start 
 , 
  
 _ 
  
 := 
  
 ptypes 
 . 
 Duration 
 ( 
 segment 
 . 
 Segment 
 . 
 StartTimeOffset 
 ) 
  
 end 
 , 
  
 _ 
  
 := 
  
 ptypes 
 . 
 Duration 
 ( 
 segment 
 . 
 Segment 
 . 
 EndTimeOffset 
 ) 
  
 fmt 
 . 
 Fprintf 
 ( 
 w 
 , 
  
 "\t\tSegment: %s to %s\n" 
 , 
  
 start 
 , 
  
 end 
 ) 
  
 } 
  
 } 
  
 } 
  
 // A single video was processed. Get the first result. 
  
 result 
  
 := 
  
 resp 
 . 
 AnnotationResults 
 [ 
 0 
 ] 
  
 fmt 
 . 
 Fprintln 
 ( 
 w 
 , 
  
 "SegmentLabelAnnotations:" 
 ) 
  
 printLabels 
 ( 
 result 
 . 
 SegmentLabelAnnotations 
 ) 
  
 fmt 
 . 
 Fprintln 
 ( 
 w 
 , 
  
 "ShotLabelAnnotations:" 
 ) 
  
 printLabels 
 ( 
 result 
 . 
 ShotLabelAnnotations 
 ) 
  
 fmt 
 . 
 Fprintln 
 ( 
 w 
 , 
  
 "FrameLabelAnnotations:" 
 ) 
  
 printLabels 
 ( 
 result 
 . 
 FrameLabelAnnotations 
 ) 
  
 return 
  
 nil 
 } 
 

Java

  // Instantiate a com.google.cloud.videointelligence.v1.VideoIntelligenceServiceClient 
 try 
  
 ( 
 VideoIntelligenceServiceClient 
  
 client 
  
 = 
  
 VideoIntelligenceServiceClient 
 . 
 create 
 ()) 
  
 { 
  
 // Provide path to file hosted on GCS as "gs://bucket-name/..." 
  
 AnnotateVideoRequest 
  
 request 
  
 = 
  
 AnnotateVideoRequest 
 . 
 newBuilder 
 () 
  
 . 
 setInputUri 
 ( 
 gcsUri 
 ) 
  
 . 
 addFeatures 
 ( 
 Feature 
 . 
 LABEL_DETECTION 
 ) 
  
 . 
 build 
 (); 
  
 // Create an operation that will contain the response when the operation completes. 
  
 OperationFuture<AnnotateVideoResponse 
 , 
  
 AnnotateVideoProgress 
>  
 response 
  
 = 
  
 client 
 . 
 annotateVideoAsync 
 ( 
 request 
 ); 
  
 System 
 . 
 out 
 . 
 println 
 ( 
 "Waiting for operation to complete..." 
 ); 
  
 for 
  
 ( 
 VideoAnnotationResults 
  
 results 
  
 : 
  
 response 
 . 
 get 
 (). 
 getAnnotationResultsList 
 ()) 
  
 { 
  
 // process video / segment level label annotations 
  
 System 
 . 
 out 
 . 
 println 
 ( 
 "Locations: " 
 ); 
  
 for 
  
 ( 
 LabelAnnotation 
  
 labelAnnotation 
  
 : 
  
 results 
 . 
 getSegmentLabelAnnotationsList 
 ()) 
  
 { 
  
 System 
 . 
 out 
 . 
 println 
 ( 
 "Video label: " 
  
 + 
  
 labelAnnotation 
 . 
 getEntity 
 (). 
 getDescription 
 ()); 
  
 // categories 
  
 for 
  
 ( 
 Entity 
  
 categoryEntity 
  
 : 
  
 labelAnnotation 
 . 
 getCategoryEntitiesList 
 ()) 
  
 { 
  
 System 
 . 
 out 
 . 
 println 
 ( 
 "Video label category: " 
  
 + 
  
 categoryEntity 
 . 
 getDescription 
 ()); 
  
 } 
  
 // segments 
  
 for 
  
 ( 
 LabelSegment 
  
 segment 
  
 : 
  
 labelAnnotation 
 . 
 getSegmentsList 
 ()) 
  
 { 
  
 double 
  
 startTime 
  
 = 
  
 segment 
 . 
 getSegment 
 (). 
 getStartTimeOffset 
 (). 
 getSeconds 
 () 
  
 + 
  
 segment 
 . 
 getSegment 
 (). 
 getStartTimeOffset 
 (). 
 getNanos 
 () 
  
 / 
  
 1e9 
 ; 
  
 double 
  
 endTime 
  
 = 
  
 segment 
 . 
 getSegment 
 (). 
 getEndTimeOffset 
 (). 
 getSeconds 
 () 
  
 + 
  
 segment 
 . 
 getSegment 
 (). 
 getEndTimeOffset 
 (). 
 getNanos 
 () 
  
 / 
  
 1e9 
 ; 
  
 System 
 . 
 out 
 . 
 printf 
 ( 
 "Segment location: %.3f:%.3f\n" 
 , 
  
 startTime 
 , 
  
 endTime 
 ); 
  
 System 
 . 
 out 
 . 
 println 
 ( 
 "Confidence: " 
  
 + 
  
 segment 
 . 
 getConfidence 
 ()); 
  
 } 
  
 } 
  
 // process shot label annotations 
  
 for 
  
 ( 
 LabelAnnotation 
  
 labelAnnotation 
  
 : 
  
 results 
 . 
 getShotLabelAnnotationsList 
 ()) 
  
 { 
  
 System 
 . 
 out 
 . 
 println 
 ( 
 "Shot label: " 
  
 + 
  
 labelAnnotation 
 . 
 getEntity 
 (). 
 getDescription 
 ()); 
  
 // categories 
  
 for 
  
 ( 
 Entity 
  
 categoryEntity 
  
 : 
  
 labelAnnotation 
 . 
 getCategoryEntitiesList 
 ()) 
  
 { 
  
 System 
 . 
 out 
 . 
 println 
 ( 
 "Shot label category: " 
  
 + 
  
 categoryEntity 
 . 
 getDescription 
 ()); 
  
 } 
  
 // segments 
  
 for 
  
 ( 
 LabelSegment 
  
 segment 
  
 : 
  
 labelAnnotation 
 . 
 getSegmentsList 
 ()) 
  
 { 
  
 double 
  
 startTime 
  
 = 
  
 segment 
 . 
 getSegment 
 (). 
 getStartTimeOffset 
 (). 
 getSeconds 
 () 
  
 + 
  
 segment 
 . 
 getSegment 
 (). 
 getStartTimeOffset 
 (). 
 getNanos 
 () 
  
 / 
  
 1e9 
 ; 
  
 double 
  
 endTime 
  
 = 
  
 segment 
 . 
 getSegment 
 (). 
 getEndTimeOffset 
 (). 
 getSeconds 
 () 
  
 + 
  
 segment 
 . 
 getSegment 
 (). 
 getEndTimeOffset 
 (). 
 getNanos 
 () 
  
 / 
  
 1e9 
 ; 
  
 System 
 . 
 out 
 . 
 printf 
 ( 
 "Segment location: %.3f:%.3f\n" 
 , 
  
 startTime 
 , 
  
 endTime 
 ); 
  
 System 
 . 
 out 
 . 
 println 
 ( 
 "Confidence: " 
  
 + 
  
 segment 
 . 
 getConfidence 
 ()); 
  
 } 
  
 } 
  
 // process frame label annotations 
  
 for 
  
 ( 
 LabelAnnotation 
  
 labelAnnotation 
  
 : 
  
 results 
 . 
 getFrameLabelAnnotationsList 
 ()) 
  
 { 
  
 System 
 . 
 out 
 . 
 println 
 ( 
 "Frame label: " 
  
 + 
  
 labelAnnotation 
 . 
 getEntity 
 (). 
 getDescription 
 ()); 
  
 // categories 
  
 for 
  
 ( 
 Entity 
  
 categoryEntity 
  
 : 
  
 labelAnnotation 
 . 
 getCategoryEntitiesList 
 ()) 
  
 { 
  
 System 
 . 
 out 
 . 
 println 
 ( 
 "Frame label category: " 
  
 + 
  
 categoryEntity 
 . 
 getDescription 
 ()); 
  
 } 
  
 // segments 
  
 for 
  
 ( 
 LabelSegment 
  
 segment 
  
 : 
  
 labelAnnotation 
 . 
 getSegmentsList 
 ()) 
  
 { 
  
 double 
  
 startTime 
  
 = 
  
 segment 
 . 
 getSegment 
 (). 
 getStartTimeOffset 
 (). 
 getSeconds 
 () 
  
 + 
  
 segment 
 . 
 getSegment 
 (). 
 getStartTimeOffset 
 (). 
 getNanos 
 () 
  
 / 
  
 1e9 
 ; 
  
 double 
  
 endTime 
  
 = 
  
 segment 
 . 
 getSegment 
 (). 
 getEndTimeOffset 
 (). 
 getSeconds 
 () 
  
 + 
  
 segment 
 . 
 getSegment 
 (). 
 getEndTimeOffset 
 (). 
 getNanos 
 () 
  
 / 
  
 1e9 
 ; 
  
 System 
 . 
 out 
 . 
 printf 
 ( 
 "Segment location: %.3f:%.2f\n" 
 , 
  
 startTime 
 , 
  
 endTime 
 ); 
  
 System 
 . 
 out 
 . 
 println 
 ( 
 "Confidence: " 
  
 + 
  
 segment 
 . 
 getConfidence 
 ()); 
  
 } 
  
 } 
  
 } 
 } 
 

Node.js

  // Imports the Google Cloud Video Intelligence library 
 const 
  
 video 
  
 = 
  
 require 
 ( 
 ' @google-cloud/video-intelligence 
' 
 ). 
 v1 
 ; 
 // Creates a client 
 const 
  
 client 
  
 = 
  
 new 
  
 video 
 . 
  VideoIntelligenceServiceClient 
 
 (); 
 /** 
 * TODO(developer): Uncomment the following line before running the sample. 
 */ 
 // const gcsUri = 'GCS URI of the video to analyze, e.g. gs://my-bucket/my-video.mp4'; 
 const 
  
 request 
  
 = 
  
 { 
  
 inputUri 
 : 
  
 gcsUri 
 , 
  
 features 
 : 
  
 [ 
 'LABEL_DETECTION' 
 ], 
 }; 
 // Detects labels in a video 
 const 
  
 [ 
 operation 
 ] 
  
 = 
  
 await 
  
 client 
 . 
 annotateVideo 
 ( 
 request 
 ); 
 console 
 . 
 log 
 ( 
 'Waiting for operation to complete...' 
 ); 
 const 
  
 [ 
 operationResult 
 ] 
  
 = 
  
 await 
  
 operation 
 . 
 promise 
 (); 
 // Gets annotations for video 
 const 
  
 annotations 
  
 = 
  
 operationResult 
 . 
 annotationResults 
 [ 
 0 
 ]; 
 const 
  
 labels 
  
 = 
  
 annotations 
 . 
 segmentLabelAnnotations 
 ; 
 labels 
 . 
 forEach 
 ( 
 label 
  
 = 
>  
 { 
  
 console 
 . 
 log 
 ( 
 `Label 
 ${ 
 label 
 . 
 entity 
 . 
 description 
 } 
 occurs at:` 
 ); 
  
 label 
 . 
 segments 
 . 
 forEach 
 ( 
 segment 
  
 = 
>  
 { 
  
 const 
  
 time 
  
 = 
  
 segment 
 . 
 segment 
 ; 
  
 if 
  
 ( 
 time 
 . 
 startTimeOffset 
 . 
 seconds 
  
 === 
  
 undefined 
 ) 
  
 { 
  
 time 
 . 
 startTimeOffset 
 . 
 seconds 
  
 = 
  
 0 
 ; 
  
 } 
  
 if 
  
 ( 
 time 
 . 
 startTimeOffset 
 . 
 nanos 
  
 === 
  
 undefined 
 ) 
  
 { 
  
 time 
 . 
 startTimeOffset 
 . 
 nanos 
  
 = 
  
 0 
 ; 
  
 } 
  
 if 
  
 ( 
 time 
 . 
 endTimeOffset 
 . 
 seconds 
  
 === 
  
 undefined 
 ) 
  
 { 
  
 time 
 . 
 endTimeOffset 
 . 
 seconds 
  
 = 
  
 0 
 ; 
  
 } 
  
 if 
  
 ( 
 time 
 . 
 endTimeOffset 
 . 
 nanos 
  
 === 
  
 undefined 
 ) 
  
 { 
  
 time 
 . 
 endTimeOffset 
 . 
 nanos 
  
 = 
  
 0 
 ; 
  
 } 
  
 console 
 . 
 log 
 ( 
  
 `\tStart: 
 ${ 
 time 
 . 
 startTimeOffset 
 . 
 seconds 
 } 
 ` 
  
 + 
  
 `. 
 ${ 
 ( 
 time 
 . 
 startTimeOffset 
 . 
 nanos 
  
 / 
  
 1e6 
 ). 
 toFixed 
 ( 
 0 
 ) 
 } 
 s` 
  
 ); 
  
 console 
 . 
 log 
 ( 
  
 `\tEnd: 
 ${ 
 time 
 . 
 endTimeOffset 
 . 
 seconds 
 } 
 .` 
  
 + 
  
 ` 
 ${ 
 ( 
 time 
 . 
 endTimeOffset 
 . 
 nanos 
  
 / 
  
 1e6 
 ). 
 toFixed 
 ( 
 0 
 ) 
 } 
 s` 
  
 ); 
  
 console 
 . 
 log 
 ( 
 `\tConfidence: 
 ${ 
 segment 
 . 
 confidence 
 } 
 ` 
 ); 
  
 }); 
 }); 
 

Python

  """Detects labels given a GCS path.""" 
 video_client 
 = 
 videointelligence 
 . 
 VideoIntelligenceServiceClient 
 () 
 features 
 = 
 [ 
 videointelligence 
 . 
 Feature 
 . 
 LABEL_DETECTION 
 ] 
 mode 
 = 
 videointelligence 
 . 
 LabelDetectionMode 
 . 
 SHOT_AND_FRAME_MODE 
 config 
 = 
 videointelligence 
 . 
 LabelDetectionConfig 
 ( 
 label_detection_mode 
 = 
 mode 
 ) 
 context 
 = 
 videointelligence 
 . 
 VideoContext 
 ( 
 label_detection_config 
 = 
 config 
 ) 
 operation 
 = 
 video_client 
 . 
 annotate_video 
 ( 
 request 
 = 
 { 
 "features" 
 : 
 features 
 , 
 "input_uri" 
 : 
 path 
 , 
 "video_context" 
 : 
 context 
 } 
 ) 
 print 
 ( 
 " 
 \n 
 Processing video for label annotations:" 
 ) 
 result 
 = 
 operation 
 . 
 result 
 ( 
 timeout 
 = 
 180 
 ) 
 print 
 ( 
 " 
 \n 
 Finished processing." 
 ) 
 # Process video/segment level label annotations 
 segment_labels 
 = 
 result 
 . 
 annotation_results 
 [ 
 0 
 ] 
 . 
 segment_label_annotations 
 for 
 i 
 , 
 segment_label 
 in 
 enumerate 
 ( 
 segment_labels 
 ): 
 print 
 ( 
 "Video label description: 
 {} 
 " 
 . 
 format 
 ( 
 segment_label 
 . 
 entity 
 . 
 description 
 )) 
 for 
 category_entity 
 in 
 segment_label 
 . 
 category_entities 
 : 
 print 
 ( 
 " 
 \t 
 Label category description: 
 {} 
 " 
 . 
 format 
 ( 
 category_entity 
 . 
 description 
 ) 
 ) 
 for 
 i 
 , 
 segment 
 in 
 enumerate 
 ( 
 segment_label 
 . 
 segments 
 ): 
 start_time 
 = 
 ( 
 segment 
 . 
 segment 
 . 
 start_time_offset 
 . 
 seconds 
 + 
 segment 
 . 
 segment 
 . 
 start_time_offset 
 . 
 microseconds 
 / 
 1e6 
 ) 
 end_time 
 = 
 ( 
 segment 
 . 
 segment 
 . 
 end_time_offset 
 . 
 seconds 
 + 
 segment 
 . 
 segment 
 . 
 end_time_offset 
 . 
 microseconds 
 / 
 1e6 
 ) 
 positions 
 = 
 " 
 {} 
 s to 
 {} 
 s" 
 . 
 format 
 ( 
 start_time 
 , 
 end_time 
 ) 
 confidence 
 = 
 segment 
 . 
 confidence 
 print 
 ( 
 " 
 \t 
 Segment 
 {} 
 : 
 {} 
 " 
 . 
 format 
 ( 
 i 
 , 
 positions 
 )) 
 print 
 ( 
 " 
 \t 
 Confidence: 
 {} 
 " 
 . 
 format 
 ( 
 confidence 
 )) 
 print 
 ( 
 " 
 \n 
 " 
 ) 
 # Process shot level label annotations 
 shot_labels 
 = 
 result 
 . 
 annotation_results 
 [ 
 0 
 ] 
 . 
 shot_label_annotations 
 for 
 i 
 , 
 shot_label 
 in 
 enumerate 
 ( 
 shot_labels 
 ): 
 print 
 ( 
 "Shot label description: 
 {} 
 " 
 . 
 format 
 ( 
 shot_label 
 . 
 entity 
 . 
 description 
 )) 
 for 
 category_entity 
 in 
 shot_label 
 . 
 category_entities 
 : 
 print 
 ( 
 " 
 \t 
 Label category description: 
 {} 
 " 
 . 
 format 
 ( 
 category_entity 
 . 
 description 
 ) 
 ) 
 for 
 i 
 , 
 shot 
 in 
 enumerate 
 ( 
 shot_label 
 . 
 segments 
 ): 
 start_time 
 = 
 ( 
 shot 
 . 
 segment 
 . 
 start_time_offset 
 . 
 seconds 
 + 
 shot 
 . 
 segment 
 . 
 start_time_offset 
 . 
 microseconds 
 / 
 1e6 
 ) 
 end_time 
 = 
 ( 
 shot 
 . 
 segment 
 . 
 end_time_offset 
 . 
 seconds 
 + 
 shot 
 . 
 segment 
 . 
 end_time_offset 
 . 
 microseconds 
 / 
 1e6 
 ) 
 positions 
 = 
 " 
 {} 
 s to 
 {} 
 s" 
 . 
 format 
 ( 
 start_time 
 , 
 end_time 
 ) 
 confidence 
 = 
 shot 
 . 
 confidence 
 print 
 ( 
 " 
 \t 
 Segment 
 {} 
 : 
 {} 
 " 
 . 
 format 
 ( 
 i 
 , 
 positions 
 )) 
 print 
 ( 
 " 
 \t 
 Confidence: 
 {} 
 " 
 . 
 format 
 ( 
 confidence 
 )) 
 print 
 ( 
 " 
 \n 
 " 
 ) 
 # Process frame level label annotations 
 frame_labels 
 = 
 result 
 . 
 annotation_results 
 [ 
 0 
 ] 
 . 
 frame_label_annotations 
 for 
 i 
 , 
 frame_label 
 in 
 enumerate 
 ( 
 frame_labels 
 ): 
 print 
 ( 
 "Frame label description: 
 {} 
 " 
 . 
 format 
 ( 
 frame_label 
 . 
 entity 
 . 
 description 
 )) 
 for 
 category_entity 
 in 
 frame_label 
 . 
 category_entities 
 : 
 print 
 ( 
 " 
 \t 
 Label category description: 
 {} 
 " 
 . 
 format 
 ( 
 category_entity 
 . 
 description 
 ) 
 ) 
 # Each frame_label_annotation has many frames, 
 # here we print information only about the first frame. 
 frame 
 = 
 frame_label 
 . 
 frames 
 [ 
 0 
 ] 
 time_offset 
 = 
 frame 
 . 
 time_offset 
 . 
 seconds 
 + 
 frame 
 . 
 time_offset 
 . 
 microseconds 
 / 
 1e6 
 print 
 ( 
 " 
 \t 
 First frame time offset: 
 {} 
 s" 
 . 
 format 
 ( 
 time_offset 
 )) 
 print 
 ( 
 " 
 \t 
 First frame confidence: 
 {} 
 " 
 . 
 format 
 ( 
 frame 
 . 
 confidence 
 )) 
 print 
 ( 
 " 
 \n 
 " 
 ) 
 

Additional languages

C#: Please follow the C# setup instructions on the client libraries page and then visit the Video Intelligence reference documentation for .NET.

PHP: Please follow the PHP setup instructions on the client libraries page and then visit the Video Intelligence reference documentation for PHP.

Ruby: Please follow the Ruby setup instructions on the client libraries page and then visit the Video Intelligence reference documentation for Ruby.

Design a Mobile Site
View Site in Mobile | Classic
Share by: