This page shows how to make a Cloud Video Intelligence API request with curl.
You can follow the steps on this page or try this quickstart as a Google Cloud Training lab.
Before you begin
-
Sign in to your Google Account.
If you don't already have one, sign up for a new account.
-
Select or create a GCP project.
-
Make sure that billing is enabled for your Google Cloud Platform project.
- Enable the Cloud Video Intelligence API.
-
Set up authentication:
-
In the GCP Console, go to the Create service account key page.
Go to the Create Service Account Key page - From the Service account list, select New service account.
- In the Service account name field, enter a name.
- Don't select a value from the Role list. No role is required to access this service.
- Click Create. A note appears, warning that this service account has no role.
- Click Create without role. A JSON file that contains your key downloads to your computer.
-
-
Set the environment variable GOOGLE_APPLICATION_CREDENTIALS to the file path of the JSON file that contains your service account key. This variable only applies to your current shell session, so if you open a new session, set the variable again.
- Install and initialize the Cloud SDK.
Make an Annotate Video Request
GCLOUD COMMAND
Use thegcloud command line tool to call the detect-labels command
on the path of the video to be analyzed.
gcloud ml video detect-labels gs://cloud-ml-sandbox/video/chicago.mp4
Command-line
Use
curlto make a POST request to thevideos:annotatemethod, using thegcloud auth application-default print-access-tokencommand to paste in an access token to your service account:curl -X POST \ -H "Authorization: Bearer "$(gcloud auth application-default print-access-token) \ -H "Content-Type: application/json; charset=utf-8" \ --data "{ 'inputUri':'gs://cloud-ml-sandbox/video/chicago.mp4', 'features': [ 'LABEL_DETECTION' ] }" "https://videointelligence.googleapis.com/v1/videos:annotate"The Video Intelligence API creates an operation to process your request. The response includes the operation name:
{ "name": "us-west1.18358601230245040268" }You can request information on the operation by calling the
v1.operationsendpoint, replacing operation-name in the example below with the name returned in the previous step:curl -X GET \ -H "Authorization: Bearer "$(gcloud auth application-default print-access-token) \ https://videointelligence.googleapis.com/v1/operations/operation-name
You'll see information related to your operation. If the operation has completed, a
donefield is included and set totrue:{ "name": "us-west1.104032612573769453", "metadata": { "@type": "type.googleapis.com/google.cloud.videointelligence.v1.AnnotateVideoProgress", "annotationProgress": [ { "inputUri": "/cloud-ml-sandbox/video/chicago.mp4", "progressPercent": 100, "startTime": "2018-11-01T22:13:17.978847Z", "updateTime": "2018-11-01T22:13:29.576004Z" } ] }, "done": true, ... }
After giving the request some time (about a minute, typically), the same request returns annotation results:
{
"name": "us-west1.104032612573769453",
"metadata": {
"@type": "type.googleapis.com/google.cloud.videointelligence.v1.AnnotateVideoProgress",
"annotationProgress": [
{
"inputUri": "/cloud-ml-sandbox/video/chicago.mp4",
"progressPercent": 100,
"startTime": "2018-11-01T22:13:17.978847Z",
"updateTime": "2018-11-01T22:13:29.576004Z"
}
]
},
"done": true,
"response": {
"@type": "type.googleapis.com/google.cloud.videointelligence.v1.AnnotateVideoResponse",
"annotationResults": [
{
"inputUri": "/cloud-ml-sandbox/video/chicago.mp4",
"segmentLabelAnnotations": [
{
"entity": {
"entityId": "/m/07bsy",
"description": "transport",
"languageCode": "en-US"
},
"segments": [
{
"segment": {
"startTimeOffset": "0s",
"endTimeOffset": "38.757872s"
},
"confidence": 0.81231534
}
]
},
{
"entity": {
"entityId": "/m/01n32",
"description": "city",
"languageCode": "en-US"
},
"categoryEntities": [
{
"entityId": "/m/043rvww",
"description": "geographical feature",
"languageCode": "en-US"
}
],
"segments": [
{
"segment": {
"startTimeOffset": "0s",
"endTimeOffset": "38.757872s"
},
"confidence": 0.3942462
}
]
},
...
{
"entity": {
"entityId": "/m/06gfj",
"description": "road",
"languageCode": "en-US"
},
"segments": [
{
"segment": {
"startTimeOffset": "0s",
"endTimeOffset": "38.757872s"
},
"confidence": 0.86698604
}
]
}
]
}
]
}
}
Congratulations! You've sent your first request to Cloud Video Intelligence API.
Clean up
To avoid unnecessary Google Cloud Platform charges, use the GCP Console to delete your project if you do not need it.
What's next
- Work through the How-To Guides.
- Work through the Samples & Tutorials.
- Consult the API Reference for complete information on all API calls.


