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. 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.
  8. Obtain an authorization token:
    gcloud auth application-default 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

Var denne side nyttig? Giv os en anmeldelse af den:

Send feedback om...

Cloud Video Intelligence API Documentation