Quickstart

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.

Try it with a lab

Before you begin

  1. Sign in to your Google Account.

    If you don't already have one, sign up for a new account.

  2. Select or create a GCP project.

    Go to the Manage resources page

  3. Make sure that billing is enabled for your project.

    Learn how to enable billing

  4. Enable the Cloud Video Intelligence API.

    Enable the API

  5. Set up authentication:
    1. In the GCP Console, go to the Create service account key page.

      Go to the Create Service Account Key page
    2. From the Service account drop-down list, select New service account.
    3. In the Service account name field, enter a name .
    4. Don't select a value from the Role drop-down list. No role is required to access this service.
    5. Click Create. A note appears, warning that this service account has no role.
    6. Click Create without role. A JSON file that contains your key downloads to your computer.
  6. 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.

  7. Install and initialize the Cloud SDK.

Make an Annotate Video Request

GCLOUD COMMAND

Use the gcloud 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

  1. Use curl to make a POST request to the videos:annotate method, using the gcloud auth application-default print-access-token command 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"
    

  2. The Video Intelligence API creates an operation to process your request. The response includes the operation name:

    {
      "name": "us-west1.18358601230245040268"
    }
    

  3. You can request information on the operation by calling the v1.operations endpoint, 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
    

  4. You'll see information related to your operation. If the operation has completed, a done field is included and set to true:

    {
      "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

Was this page helpful? Let us know how we did:

Send feedback about...

Cloud Video Intelligence API Documentation