The Video Intelligence API can detect, track, and recognize the presence of over 100,000 brands and logos in video content.
This page describes how to recognize a logo in a video using the Video Intelligence API.
Annotate a video in Cloud Storage
The following code sample demonstrates how to detect logos in a video in Cloud Storage.
REST
Send the process request
To perform annotation on a local video file, base64-encode the contents of
the video file. Include the base64-encoded contents in the inputContent
field
of the request. For information on how to base64-encode the contents of a video file,
see Base64 Encoding.
The following shows how to send a POST
request to the
videos: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://
.
For example:
"inputUri": "gs://cloud-videointelligence-demo/assistant.mp4",
- 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": ["LOGO_RECOGNITION"] }
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 response is successful, the Video Intelligence API returns the name
for your
operation. The above shows an example of such a response, where:
project-number
is the number of your project and operation-id
is the ID of the
long running operation created for the request.
- PROJECT_NUMBER: the number of your project
- LOCATION_ID: the Cloud region where annotation should take
place. Supported cloud regions are:
us-east1
,us-west1
,europe-west1
,asia-east1
. If no region is specified, a region will be determined based on video file location. - OPERATION_ID: the ID of the long running operation created
for the request and provided in the response when you started the
operation, for example
12345...
Get the results
To get the results of your request, you send a GET
request, using the
operation name returned from the call to videos:annotate
, as shown in the following example.
Before using any of the request data, make the following replacements:
- OPERATION_NAME: the name of the operation as
returned by 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
To authenticate to Video Intelligence, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.
Java
To authenticate to Video Intelligence, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.
Node.js
To authenticate to Video Intelligence, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.
Python
To authenticate to Video Intelligence, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.
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 local video
The following code sample demonstrates how to detect logos in a local video file.
REST
Send video annotation request
To perform annotation on a local video file, be sure to base64-encode the
contents of the video file.
Include the base64-encoded contents in the inputContent
field of the request.
For information on how
to base64-encode the contents of a video file, see Base64 Encoding.
The following shows how to send a POST request to the videos: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 API Quickstart
Before using any of the request data, make the following replacements:
- "inputContent": BASE64_ENCODED_CONTENT
For example:
"UklGRg41AwBBVkkgTElTVAwBAABoZHJsYXZpaDgAAAA1ggAAxPMBAAAAAAAQCAA..."
- LANGUAGE_CODE: [Optional] See supported languages
- 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:
{ "inputContent": "BASE64_ENCODED_CONTENT", "features": ["LOGO_RECOGNITION"], "videoContext": { } }
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 response is successful, the Video Intelligence API returns the name
for your
operation. The above shows an example of such a response, where
project-number
is the name of your project and operation-id
is the ID of the
long running operation created for the request.
- OPERATION_ID: provided in the response when you started the
operation, for example
12345...
Get annotation results
To retrieve the result of the operation, make a GET request, using the operation name returned from the call to videos:annotate, as shown in the following example.
Before using any of the request data, make the following replacements:
- 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:
Text detection annotations are returned as a textAnnotations
list.
Note: The done field is returned only when its value is True.
It's not included in responses for which the operation has not completed.
Go
To authenticate to Video Intelligence, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.
Java
To authenticate to Video Intelligence, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.
Node.js
To authenticate to Video Intelligence, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.
Python
To authenticate to Video Intelligence, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.
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.