Quickstart

Installing the Google Cloud SDK

The Google Video Intelligence API makes use of the gcloud command line tool, which is distributed within the Google Cloud Platform Cloud SDK.

Follow the instructions to install and initialize the Cloud SDK.

If you're using Cloud Shell (recommended) or a Compute Engine instance, the SDK is already installed and initialized.

Set up your project

If you haven't already done so:

  1. Sign in to your Google account.

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

  2. In the Cloud Platform Console, go to the Manage resources page and select or create a new project.

    Go to the Manage resources page

  3. Enable billing for your project.

    Enable billing

  4. Enable the Cloud Video Intelligence API.

    Enable the API

  5. After enabling the Google Cloud Video Intelligence API, click the Go to Credentials button to set up your Cloud Video Intelligence API credentials:

Set up authorization

This quickstart creates and uses a service account tied to your GCP Console project for authorization. These steps assume that you've installed and initialized the gcloud command line tool.

  1. Create a service account:
    gcloud iam service-accounts create quickstart
  2. Create a service account key file:
    gcloud iam service-accounts keys create key.json \
    --iam-account quickstart@your-project-123.iam.gserviceaccount.com
  3. Authenticate to your service account, passing the location of your service account key file:
    gcloud auth activate-service-account --key-file key.json
  4. Obtain an authorization token using your service account:
    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...

Google Cloud Video Intelligence API Documentation