Quickstart

This page shows how to make a Cloud Video Intelligence API request with curl.

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. Go to the Create service account key page in the GCP Console.

      Go to the Create Service Account Key page
    2. From the Service account drop-down list, select New service account.
    3. Enter a name into the Service account name field.
    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. Install and initialize the Cloud SDK.
  7. Provide authentication credentials to your application code by running the following command. Replace [PATH] with the location of the JSON file that contains your credentials.

    gcloud auth activate-service-account --key-file=[PATH]
  8. Obtain an authorization token:
    gcloud auth print-access-token

Make an Annotate Video Request

  1. Create a JSON request file with the following text, and save it as request.json

    {
       "inputUri":"gs://cloud-ml-sandbox/video/chicago.mp4",
       "features": [
           "LABEL_DETECTION"
       ]
    }
    
  2. Use curl to make a videos:annotate request, passing it the access token you printed, and the filename of the entity request:

    curl -s -H 'Content-Type: application/json' \
        -H 'Authorization: Bearer ACCESS_TOKEN' \
        'https://videointelligence.googleapis.com/v1/videos:annotate' \
        -d @request.json
    

    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, passing the operation's name value:

    curl -s -H 'Content-Type: application/json' \
        -H 'Authorization: Bearer ACCESS_TOKEN' \
        'https://videointelligence.googleapis.com/v1/operations/OPERATION_NAME'
    

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

    {
      "name": "OPERATION_NAME",
      "metadata": {
        "@type": "type.googleapis.com/google.cloud.videointelligence.v1.Annota
    tionProgressMetadata",
        "progressMetadata": [
          {
            "inputUri": "gs://cloud-ml-sandbox/video/chicago.mp4",
            "startTime": "2016-09-22T21:41:56.766091Z",
            "lastUpdateTime": "2016-09-22T21:42:03.889743Z"
          }
        ]
      },
      ...
    }
    
  4. After giving the request some time (about a minute, typically), the same request returns annotation results:

    {
      "name": "OPERATION_NAME",
      "metadata": {
        "@type": "type.googleapis.com/google.cloud.videointelligence.v1.AnnotateVideoProgress",
        "annotationProgress": [
          {
            "inputUri": "/cloud-ml-sandbox/video/chicago.mp4",
            "progressPercent": 100,
            "startTime": "2017-02-17T22:39:00.333942Z",
            "updateTime": "2017-02-17T22:39:11.414399Z"
          }
        ]
      },
      "done": true,
      "response": {
        "@type": "type.googleapis.com/google.cloud.videointelligence.v1.AnnotateVideoResponse",
        "annotationResults": [
          {
            "inputUri": "/cloud-ml-sandbox/video/chicago.mp4",
            "segmentLabelAnnotations": [
              {
                "entity": {
                  "entityId": "/m/01yrx",
                  "languageCode": "en-US"
                },
                "segments": [
                  {
                    "segment": {
                      "startTimeOffset": "0s",
                      "endTimeOffset": "14.833664s"
                    },
                    "confidence": 0.98509187
                  }
                ]
              },
             ...
    

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

Send feedback about...

Cloud Video Intelligence API Documentation