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 timestamps 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.
Annotating 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 & CMD LINE
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 Cloud SDK. For
instructions on installing the Cloud SDK, 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 below, make the following replacements:
- base64-encoded-content: your video as base64 encoded data. See the instructions on how to convert your data to base64.
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 below, 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
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:
C#
Go
Java
Node.js
Python
For more information on installing and using the Cloud Video Intelligence API Client Library for Python, refer to Cloud Video Intelligence API Client Libraries.PHP
Ruby
Annotating a file on Cloud Storage
Here is an example of performing video analysis for labels on a file located in Cloud Storage.
REST & CMD LINE
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 Cloud SDK. For
instructions on installing the Cloud SDK, 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 below, 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://
.
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 below, 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
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)
gsutil 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.