Recognizing logos

Video Intelligence API can detect, track, and recognize the presence of over 100,000 brands and logos in video content.

This page describes how to recognize a logo in a video using the Video Intelligence API.

Annotate a video on Cloud Storage

The following code sample demonstrates how to detect logos from a video on Cloud Storage

REST & CMD LINE

Send the process request

To perform annotation on a local video file, base64-encode the contents of the video file. Include the base64-encoded contents in the inputContent field of the request. For information on how to base64-encode the contents of a video file, see Base64 Encoding.

The following shows how to send a POST request to the videos:annotate method. The example uses the access token for a service account set up for the project using the Cloud SDK. For instructions on installing the Cloud SDK, setting up a project with a service account, and obtaining an access token, see the Video Intelligence quickstart.

Before using any of the request data below, make the following replacements:

  • input-uri: a Cloud Storage bucket that contains the file you want to annotate, including the file name. Must start with gs://.
    For example:
    "inputUri": "gs://cloud-videointelligence-demo/assistant.mp4",

HTTP method and URL:

POST https://videointelligence.googleapis.com/v1p3beta/videos:annotate

Request JSON body:

{
    "inputUri":"input-uri",
    "features": ["LOGO_RECOGNITION"]
}

To send your request, expand one of these options:

You should receive a JSON response similar to the following:

{
  "name": "projects/project-number/locations/location-id/operations/operation-id"
}

If the response is successful, the Video Intelligence API returns the name for your operation. The above shows an example of such a response, where: project-number is the name of your project and operation-id is the ID of the long running operation created for the request.

  • project-number: the number of your project
  • location-id: the Cloud region where annotation should take place. Supported cloud regions are: us-east1, us-west1, europe-west1, asia-east1. If no region is specified, a region will be determined based on video file location.
  • operation-id: the ID of the long running operation created for the request and provided in the response when you started the operation, for example 12345...

Get the results

To get the results of your request, you send a GET request, using the operation name returned from the call to videos:annotate, as shown in the following example.

Before using any of the request data below, make the following replacements:

  • operation-name: the name of the operation as returned by Video Intelligence API. The operation name has the format projects/project-number/locations/location-id/operations/operation-id

HTTP method and URL:

GET https://videointelligence.googleapis.com/v1/operation-name

To send your request, expand one of these options:

You should receive a JSON response similar to the following:

Java

/*
 * Please include the following imports to run this sample.
 *
 * import com.google.cloud.videointelligence.v1p3beta1.AnnotateVideoRequest;
 * import com.google.cloud.videointelligence.v1p3beta1.AnnotateVideoResponse;
 * import com.google.cloud.videointelligence.v1p3beta1.DetectedAttribute;
 * import com.google.cloud.videointelligence.v1p3beta1.Entity;
 * import com.google.cloud.videointelligence.v1p3beta1.Feature;
 * import com.google.cloud.videointelligence.v1p3beta1.LogoRecognitionAnnotation;
 * import com.google.cloud.videointelligence.v1p3beta1.NormalizedBoundingBox;
 * import com.google.cloud.videointelligence.v1p3beta1.TimestampedObject;
 * import com.google.cloud.videointelligence.v1p3beta1.Track;
 * import com.google.cloud.videointelligence.v1p3beta1.VideoAnnotationResults;
 * import com.google.cloud.videointelligence.v1p3beta1.VideoIntelligenceServiceClient;
 * import com.google.cloud.videointelligence.v1p3beta1.VideoSegment;
 * import com.google.protobuf.Duration;
 * import java.util.Arrays;
 * import java.util.List;
 */

/** Performs asynchronous video annotation for logo recognition on a file hosted in GCS. */
public static void sampleAnnotateVideo() {
    try (VideoIntelligenceServiceClient videoIntelligenceServiceClient =
                 VideoIntelligenceServiceClient.create()) {
        String inputUri = "gs://cloud-samples-data/video/googlework_short.mp4";
        Feature featuresElement = Feature.LOGO_RECOGNITION;
        List<Feature> features = Arrays.asList(featuresElement);
        AnnotateVideoRequest request =
                AnnotateVideoRequest.newBuilder().setInputUri(inputUri).addAllFeatures(features).build();
        AnnotateVideoResponse response =
                videoIntelligenceServiceClient.annotateVideoAsync(request).get();
        // Get the first response, since we sent only one video.
        VideoAnnotationResults annotationResult = response.getAnnotationResultsList().get(0);
        // Annotations for list of logos detected, tracked and recognized in video.
        for (LogoRecognitionAnnotation logoRecognitionAnnotation :
                annotationResult.getLogoRecognitionAnnotationsList()) {
            Entity entity = logoRecognitionAnnotation.getEntity();
            // Opaque entity ID. Some IDs may be available in [Google Knowledge Graph Search API](https://developers.google.com/knowledge-graph/).
            System.out.printf("Entity Id : %s\n", entity.getEntityId());
            // Textual description, e.g. `Google`.
            System.out.printf("Description : %s\n", entity.getDescription());
            // All logo tracks where the recognized logo appears. Each track corresponds to one logo instance appearing in consecutive frames.
            for (Track track : logoRecognitionAnnotation.getTracksList()) {
                // Video segment of a track.
                VideoSegment segment = track.getSegment();
                Duration segmentStartTimeOffset = segment.getStartTimeOffset();
                System.out.printf(
                        "\n\tStart Time Offset : %s.%s\n",
                        segmentStartTimeOffset.getSeconds(), segmentStartTimeOffset.getNanos());
                Duration segmentEndTimeOffset = segment.getEndTimeOffset();
                System.out.printf(
                        "\tEnd Time Offset : %s.%s\n",
                        segmentEndTimeOffset.getSeconds(), segmentEndTimeOffset.getNanos());
                System.out.printf("\tConfidence : %s\n", track.getConfidence());
                // The object with timestamp and attributes per frame in the track.
                for (TimestampedObject timestampedObject : track.getTimestampedObjectsList()) {
                    // Normalized Bounding box in a frame, where the object is located.
                    NormalizedBoundingBox normalizedBoundingBox =
                            timestampedObject.getNormalizedBoundingBox();
                    System.out.printf("\n\t\tLeft : %s\n", normalizedBoundingBox.getLeft());
                    System.out.printf("\t\tTop : %s\n", normalizedBoundingBox.getTop());
                    System.out.printf("\t\tRight : %s\n", normalizedBoundingBox.getRight());
                    System.out.printf("\t\tBottom : %s\n", normalizedBoundingBox.getBottom());
                    // Optional. The attributes of the object in the bounding box.
                    for (DetectedAttribute attribute : timestampedObject.getAttributesList()) {
                        System.out.printf("\n\t\t\tName : %s\n", attribute.getName());
                        System.out.printf("\t\t\tConfidence : %s\n", attribute.getConfidence());
                        System.out.printf("\t\t\tValue : %s\n", attribute.getValue());
                    }
                }
                // Optional. Attributes in the track level.
                for (DetectedAttribute trackAttribute : track.getAttributesList()) {
                    System.out.printf("\n\t\tName : %s\n", trackAttribute.getName());
                    System.out.printf("\t\tConfidence : %s\n", trackAttribute.getConfidence());
                    System.out.printf("\t\tValue : %s\n", trackAttribute.getValue());
                }
            }
            // All video segments where the recognized logo appears. There might be multiple instances of the same logo class appearing in one VideoSegment.
            for (VideoSegment logoRecognitionAnnotationSegment :
                    logoRecognitionAnnotation.getSegmentsList()) {
                Duration logoRecognitionAnnotationSegmentStartTimeOffset =
                        logoRecognitionAnnotationSegment.getStartTimeOffset();
                System.out.printf(
                        "\n\tStart Time Offset : %s.%s\n",
                        logoRecognitionAnnotationSegmentStartTimeOffset.getSeconds(),
                        logoRecognitionAnnotationSegmentStartTimeOffset.getNanos());
                Duration logoRecognitionAnnotationSegmentEndTimeOffset =
                        logoRecognitionAnnotationSegment.getEndTimeOffset();
                System.out.printf(
                        "\tEnd Time Offset : %s.%s\n",
                        logoRecognitionAnnotationSegmentEndTimeOffset.getSeconds(),
                        logoRecognitionAnnotationSegmentEndTimeOffset.getNanos());
            }
        }
    } catch (Exception exception) {
        System.err.println("Failed to create the client due to: " + exception);
    }
}

Node.js


const videoIntelligence = require('@google-cloud/video-intelligence').v1p3beta1;

/** Performs asynchronous video annotation for logo recognition on a file hosted in GCS. */
async function sampleAnnotateVideo() {
  const client = new videoIntelligence.VideoIntelligenceServiceClient();
  const inputUri = 'gs://cloud-samples-data/video/googlework_short.mp4';
  const featuresElement = 'LOGO_RECOGNITION';
  const features = [featuresElement];
  const request = {
    inputUri: inputUri,
    features: features,
  };

  // Create a job whose results you can either wait for now, or get later
  const [operation] = await client.annotateVideo(request);

  // Get a Promise representation of the final result of the job
  const [response] = await operation.promise();

  // Get the first response, since we sent only one video.
  const annotationResult = response.annotationResults[0];
  // Annotations for list of logos detected, tracked and recognized in video.
  for (const logoRecognitionAnnotation of annotationResult.logoRecognitionAnnotations) {
    const entity = logoRecognitionAnnotation.entity;
    // Opaque entity ID. Some IDs may be available in [Google Knowledge Graph Search API](https://developers.google.com/knowledge-graph/).
    console.log(`Entity Id : ${entity.entityId}`);
    // Textual description, e.g. `Google`.
    console.log(`Description : ${entity.description}`);
    // All logo tracks where the recognized logo appears. Each track corresponds to one logo instance appearing in consecutive frames.
    for (const track of logoRecognitionAnnotation.tracks) {
      // Video segment of a track.
      const segment = track.segment;
      const segmentStartTimeOffset = segment.startTimeOffset;
      console.log(
        `\n\tStart Time Offset : ${segmentStartTimeOffset.seconds}.${segmentStartTimeOffset.nanos}`
      );
      const segmentEndTimeOffset = segment.endTimeOffset;
      console.log(
        `\tEnd Time Offset : ${segmentEndTimeOffset.seconds}.${segmentEndTimeOffset.nanos}`
      );
      console.log(`\tConfidence : ${track.confidence}`);
      // The object with timestamp and attributes per frame in the track.
      for (const timestampedObject of track.timestampedObjects) {
        // Normalized Bounding box in a frame, where the object is located.
        const normalizedBoundingBox = timestampedObject.normalizedBoundingBox;
        console.log(`\n\t\tLeft : ${normalizedBoundingBox.left}`);
        console.log(`\t\tTop : ${normalizedBoundingBox.top}`);
        console.log(`\t\tRight : ${normalizedBoundingBox.right}`);
        console.log(`\t\tBottom : ${normalizedBoundingBox.bottom}`);
        // Optional. The attributes of the object in the bounding box.
        for (const attribute of timestampedObject.attributes) {
          console.log(`\n\t\t\tName : ${attribute.name}`);
          console.log(`\t\t\tConfidence : ${attribute.confidence}`);
          console.log(`\t\t\tValue : ${attribute.value}`);
        }
      }
      // Optional. Attributes in the track level.
      for (const trackAttribute of track.attributes) {
        console.log(`\n\t\tName : ${trackAttribute.name}`);
        console.log(`\t\tConfidence : ${trackAttribute.confidence}`);
        console.log(`\t\tValue : ${trackAttribute.value}`);
      }
    }
    // All video segments where the recognized logo appears. There might be multiple instances of the same logo class appearing in one VideoSegment.
    for (const logoRecognitionAnnotationSegment of logoRecognitionAnnotation.segments) {
      const logoRecognitionAnnotationSegmentStartTimeOffset =
        logoRecognitionAnnotationSegment.startTimeOffset;
      console.log(
        `\n\tStart Time Offset : ${logoRecognitionAnnotationSegmentStartTimeOffset.seconds}.${logoRecognitionAnnotationSegmentStartTimeOffset.nanos}`
      );
      const logoRecognitionAnnotationSegmentEndTimeOffset =
        logoRecognitionAnnotationSegment.endTimeOffset;
      console.log(
        `\tEnd Time Offset : ${logoRecognitionAnnotationSegmentEndTimeOffset.seconds}.${logoRecognitionAnnotationSegmentEndTimeOffset.nanos}`
      );
    }
  }
}

Python


from google.cloud import videointelligence_v1p3beta1
from google.cloud.videointelligence_v1p3beta1 import enums


def sample_annotate_video(
    input_uri="gs://cloud-samples-data/video/googlework_tiny.mp4",
):

    client = videointelligence_v1p3beta1.VideoIntelligenceServiceClient()

    features_element = enums.Feature.LOGO_RECOGNITION
    features = [features_element]

    operation = client.annotate_video(input_uri=input_uri, features=features)

    print(u"Waiting for operation to complete...")
    response = operation.result()

    # Get the first response, since we sent only one video.
    annotation_result = response.annotation_results[0]
    # Annotations for list of logos detected, tracked and recognized in video.
    for logo_recognition_annotation in annotation_result.logo_recognition_annotations:
        entity = logo_recognition_annotation.entity
        # Opaque entity ID. Some IDs may be available in [Google Knowledge Graph
        # Search API](https://developers.google.com/knowledge-graph/).
        print(u"Entity Id : {}".format(entity.entity_id))
        # Textual description, e.g. `Google`.
        print(u"Description : {}".format(entity.description))
        # All logo tracks where the recognized logo appears. Each track corresponds
        # to one logo instance appearing in consecutive frames.
        for track in logo_recognition_annotation.tracks:
            # Video segment of a track.
            segment = track.segment
            segment_start_time_offset = segment.start_time_offset
            print(
                u"\n\tStart Time Offset : {}.{}".format(
                    segment_start_time_offset.seconds, segment_start_time_offset.nanos
                )
            )
            segment_end_time_offset = segment.end_time_offset
            print(
                u"\tEnd Time Offset : {}.{}".format(
                    segment_end_time_offset.seconds, segment_end_time_offset.nanos
                )
            )
            print(u"\tConfidence : {}".format(track.confidence))
            # The object with timestamp and attributes per frame in the track.
            for timestamped_object in track.timestamped_objects:
                # Normalized Bounding box in a frame, where the object is located.
                normalized_bounding_box = timestamped_object.normalized_bounding_box
                print(u"\n\t\tLeft : {}".format(normalized_bounding_box.left))
                print(u"\t\tTop : {}".format(normalized_bounding_box.top))
                print(u"\t\tRight : {}".format(normalized_bounding_box.right))
                print(u"\t\tBottom : {}".format(normalized_bounding_box.bottom))
                # Optional. The attributes of the object in the bounding box.
                for attribute in timestamped_object.attributes:
                    print(u"\n\t\t\tName : {}".format(attribute.name))
                    print(u"\t\t\tConfidence : {}".format(attribute.confidence))
                    print(u"\t\t\tValue : {}".format(attribute.value))
            # Optional. Attributes in the track level.
            for track_attribute in track.attributes:
                print(u"\n\t\tName : {}".format(track_attribute.name))
                print(u"\t\tConfidence : {}".format(track_attribute.confidence))
                print(u"\t\tValue : {}".format(track_attribute.value))
        # All video segments where the recognized logo appears. There might be
        # multiple instances of the same logo class appearing in one VideoSegment.
        for logo_recognition_annotation_segment in logo_recognition_annotation.segments:
            logo_recognition_annotation_segment_start_time_offset = (
                logo_recognition_annotation_segment.start_time_offset
            )
            print(
                u"\n\tStart Time Offset : {}.{}".format(
                    logo_recognition_annotation_segment_start_time_offset.seconds,
                    logo_recognition_annotation_segment_start_time_offset.nanos,
                )
            )
            logo_recognition_annotation_segment_end_time_offset = (
                logo_recognition_annotation_segment.end_time_offset
            )
            print(
                u"\tEnd Time Offset : {}.{}".format(
                    logo_recognition_annotation_segment_end_time_offset.seconds,
                    logo_recognition_annotation_segment_end_time_offset.nanos,
                )
            )

Annotate a local video

The following code sample demonstrates how to detect logos in a local video file.

REST & CMD LINE

Send video annotation request

To perform annotation on a local video file, be sure to base64-encode the contents of the video file. Include the base64-encoded contents in the inputContent field of the request. For information on how to base64-encode the contents of a video file, see Base64 Encoding.

The following shows how to send a POST request to the videos:annotate method. The example uses the access token for a service account set up for the project using the Cloud SDK. For instructions on installing the Cloud SDK, setting up a project with a service account, and obtaining an access token, see the Video Intelligence API Quickstart

Before using any of the request data below, make the following replacements:

  • "inputContent": base-64-encoded-content
    For example:
    "UklGRg41AwBBVkkgTElTVAwBAABoZHJsYXZpaDgAAAA1ggAAxPMBAAAAAAAQCAA..."
  • language-code: [Optional] See supported languages

HTTP method and URL:

POST https://videointelligence.googleapis.com/v1p3beta/videos:annotate

Request JSON body:

{
  "inputContent": "base-64-encoded-content",
  "features": ["LOGO_RECOGNITION"],
  "videoContext": {
  }
}

To send your request, expand one of these options:

You should receive a JSON response similar to the following:

{
  "name": "projects/project-number/locations/location-id/operations/operation-id"
}

If the response is successful, the Video Intelligence API returns the name for your operation. The above shows an example of such a response, where project-number is the name of your project and operation-id is the ID of the long running operation created for the request.

  • operation-id: provided in the response when you started the operation, for example 12345...

Get annotation results

To retrieve the result of the operation, make a GET request, using the operation name returned from the call to videos:annotate, as shown in the following example.

HTTP method and URL:

GET https://videointelligence.googleapis.com/v1/operation-name

To send your request, expand one of these options:

You should receive a JSON response similar to the following:

Text detection annotations are returned as a textAnnotations list. Note: The done field is only returned when its value is True. It's not included in responses for which the operation has not completed.

Java

/*
 * Please include the following imports to run this sample.
 *
 * import com.google.cloud.videointelligence.v1p3beta1.AnnotateVideoRequest;
 * import com.google.cloud.videointelligence.v1p3beta1.AnnotateVideoResponse;
 * import com.google.cloud.videointelligence.v1p3beta1.DetectedAttribute;
 * import com.google.cloud.videointelligence.v1p3beta1.Entity;
 * import com.google.cloud.videointelligence.v1p3beta1.Feature;
 * import com.google.cloud.videointelligence.v1p3beta1.LogoRecognitionAnnotation;
 * import com.google.cloud.videointelligence.v1p3beta1.NormalizedBoundingBox;
 * import com.google.cloud.videointelligence.v1p3beta1.TimestampedObject;
 * import com.google.cloud.videointelligence.v1p3beta1.Track;
 * import com.google.cloud.videointelligence.v1p3beta1.VideoAnnotationResults;
 * import com.google.cloud.videointelligence.v1p3beta1.VideoIntelligenceServiceClient;
 * import com.google.cloud.videointelligence.v1p3beta1.VideoSegment;
 * import com.google.protobuf.ByteString;
 * import com.google.protobuf.Duration;
 * import java.nio.file.Files;
 * import java.nio.file.Path;
 * import java.nio.file.Paths;
 * import java.util.Arrays;
 * import java.util.List;
 */

/**
 * Performs asynchronous video annotation for logo recognition on a local file.
 *
 * @param localFilePath Path to local video file, e.g. /path/video.mp4
 */
public static void sampleAnnotateVideo(String localFilePath) {
    try (VideoIntelligenceServiceClient videoIntelligenceServiceClient =
                 VideoIntelligenceServiceClient.create()) {
        // localFilePath = "resources/googlework_short.mp4";
        Path path = Paths.get(localFilePath);
        byte[] data = Files.readAllBytes(path);
        ByteString inputContent = ByteString.copyFrom(data);
        Feature featuresElement = Feature.LOGO_RECOGNITION;
        List<Feature> features = Arrays.asList(featuresElement);
        AnnotateVideoRequest request =
                AnnotateVideoRequest.newBuilder()
                        .setInputContent(inputContent)
                        .addAllFeatures(features)
                        .build();
        AnnotateVideoResponse response =
                videoIntelligenceServiceClient.annotateVideoAsync(request).get();
        // Get the first response, since we sent only one video.
        VideoAnnotationResults annotationResult = response.getAnnotationResultsList().get(0);
        // Annotations for list of logos detected, tracked and recognized in video.
        for (LogoRecognitionAnnotation logoRecognitionAnnotation :
                annotationResult.getLogoRecognitionAnnotationsList()) {
            Entity entity = logoRecognitionAnnotation.getEntity();
            // Opaque entity ID. Some IDs may be available in [Google Knowledge Graph Search API](https://developers.google.com/knowledge-graph/).
            System.out.printf("Entity Id : %s\n", entity.getEntityId());
            // Textual description, e.g. `Google`.
            System.out.printf("Description : %s\n", entity.getDescription());
            // All logo tracks where the recognized logo appears. Each track corresponds to one logo instance appearing in consecutive frames.
            for (Track track : logoRecognitionAnnotation.getTracksList()) {
                // Video segment of a track.
                VideoSegment segment = track.getSegment();
                Duration segmentStartTimeOffset = segment.getStartTimeOffset();
                System.out.printf(
                        "\n\tStart Time Offset : %s.%s\n",
                        segmentStartTimeOffset.getSeconds(), segmentStartTimeOffset.getNanos());
                Duration segmentEndTimeOffset = segment.getEndTimeOffset();
                System.out.printf(
                        "\tEnd Time Offset : %s.%s\n",
                        segmentEndTimeOffset.getSeconds(), segmentEndTimeOffset.getNanos());
                System.out.printf("\tConfidence : %s\n", track.getConfidence());
                // The object with timestamp and attributes per frame in the track.
                for (TimestampedObject timestampedObject : track.getTimestampedObjectsList()) {
                    // Normalized Bounding box in a frame, where the object is located.
                    NormalizedBoundingBox normalizedBoundingBox =
                            timestampedObject.getNormalizedBoundingBox();
                    System.out.printf("\n\t\tLeft : %s\n", normalizedBoundingBox.getLeft());
                    System.out.printf("\t\tTop : %s\n", normalizedBoundingBox.getTop());
                    System.out.printf("\t\tRight : %s\n", normalizedBoundingBox.getRight());
                    System.out.printf("\t\tBottom : %s\n", normalizedBoundingBox.getBottom());
                    // Optional. The attributes of the object in the bounding box.
                    for (DetectedAttribute attribute : timestampedObject.getAttributesList()) {
                        System.out.printf("\n\t\t\tName : %s\n", attribute.getName());
                        System.out.printf("\t\t\tConfidence : %s\n", attribute.getConfidence());
                        System.out.printf("\t\t\tValue : %s\n", attribute.getValue());
                    }
                }
                // Optional. Attributes in the track level.
                for (DetectedAttribute trackAttribute : track.getAttributesList()) {
                    System.out.printf("\n\t\tName : %s\n", trackAttribute.getName());
                    System.out.printf("\t\tConfidence : %s\n", trackAttribute.getConfidence());
                    System.out.printf("\t\tValue : %s\n", trackAttribute.getValue());
                }
            }
            // All video segments where the recognized logo appears. There might be multiple instances of the same logo class appearing in one VideoSegment.
            for (VideoSegment logoRecognitionAnnotationSegment :
                    logoRecognitionAnnotation.getSegmentsList()) {
                Duration logoRecognitionAnnotationSegmentStartTimeOffset =
                        logoRecognitionAnnotationSegment.getStartTimeOffset();
                System.out.printf(
                        "\n\tStart Time Offset : %s.%s\n",
                        logoRecognitionAnnotationSegmentStartTimeOffset.getSeconds(),
                        logoRecognitionAnnotationSegmentStartTimeOffset.getNanos());
                Duration logoRecognitionAnnotationSegmentEndTimeOffset =
                        logoRecognitionAnnotationSegment.getEndTimeOffset();
                System.out.printf(
                        "\tEnd Time Offset : %s.%s\n",
                        logoRecognitionAnnotationSegmentEndTimeOffset.getSeconds(),
                        logoRecognitionAnnotationSegmentEndTimeOffset.getNanos());
            }
        }
    } catch (Exception exception) {
        System.err.println("Failed to create the client due to: " + exception);
    }
}

Node.js


const videoIntelligence = require('@google-cloud/video-intelligence').v1p3beta1;

const fs = require('fs');
/**
 * Performs asynchronous video annotation for logo recognition on a local file.
 *
 * @param localFilePath {string} Path to local video file, e.g. /path/video.mp4
 */
async function sampleAnnotateVideo(localFilePath) {
  const client = new videoIntelligence.VideoIntelligenceServiceClient();
  // const localFilePath = 'resources/googlework_short.mp4';
  const inputContent = fs.readFileSync(localFilePath).toString('base64');
  const featuresElement = 'LOGO_RECOGNITION';
  const features = [featuresElement];
  const request = {
    inputContent: inputContent,
    features: features,
  };

  // Create a job whose results you can either wait for now, or get later
  const [operation] = await client.annotateVideo(request);

  // Get a Promise representation of the final result of the job
  const [response] = await operation.promise();

  // Get the first response, since we sent only one video.
  const annotationResult = response.annotationResults[0];
  // Annotations for list of logos detected, tracked and recognized in video.
  for (const logoRecognitionAnnotation of annotationResult.logoRecognitionAnnotations) {
    const entity = logoRecognitionAnnotation.entity;
    // Opaque entity ID. Some IDs may be available in [Google Knowledge Graph Search API](https://developers.google.com/knowledge-graph/).
    console.log(`Entity Id : ${entity.entityId}`);
    // Textual description, e.g. `Google`.
    console.log(`Description : ${entity.description}`);
    // All logo tracks where the recognized logo appears. Each track corresponds to one logo instance appearing in consecutive frames.
    for (const track of logoRecognitionAnnotation.tracks) {
      // Video segment of a track.
      const segment = track.segment;
      const segmentStartTimeOffset = segment.startTimeOffset;
      console.log(
        `\n\tStart Time Offset : ${segmentStartTimeOffset.seconds}.${segmentStartTimeOffset.nanos}`
      );
      const segmentEndTimeOffset = segment.endTimeOffset;
      console.log(
        `\tEnd Time Offset : ${segmentEndTimeOffset.seconds}.${segmentEndTimeOffset.nanos}`
      );
      console.log(`\tConfidence : ${track.confidence}`);
      // The object with timestamp and attributes per frame in the track.
      for (const timestampedObject of track.timestampedObjects) {
        // Normalized Bounding box in a frame, where the object is located.
        const normalizedBoundingBox = timestampedObject.normalizedBoundingBox;
        console.log(`\n\t\tLeft : ${normalizedBoundingBox.left}`);
        console.log(`\t\tTop : ${normalizedBoundingBox.top}`);
        console.log(`\t\tRight : ${normalizedBoundingBox.right}`);
        console.log(`\t\tBottom : ${normalizedBoundingBox.bottom}`);
        // Optional. The attributes of the object in the bounding box.
        for (const attribute of timestampedObject.attributes) {
          console.log(`\n\t\t\tName : ${attribute.name}`);
          console.log(`\t\t\tConfidence : ${attribute.confidence}`);
          console.log(`\t\t\tValue : ${attribute.value}`);
        }
      }
      // Optional. Attributes in the track level.
      for (const trackAttribute of track.attributes) {
        console.log(`\n\t\tName : ${trackAttribute.name}`);
        console.log(`\t\tConfidence : ${trackAttribute.confidence}`);
        console.log(`\t\tValue : ${trackAttribute.value}`);
      }
    }
    // All video segments where the recognized logo appears. There might be multiple instances of the same logo class appearing in one VideoSegment.
    for (const logoRecognitionAnnotationSegment of logoRecognitionAnnotation.segments) {
      const logoRecognitionAnnotationSegmentStartTimeOffset =
        logoRecognitionAnnotationSegment.startTimeOffset;
      console.log(
        `\n\tStart Time Offset : ${logoRecognitionAnnotationSegmentStartTimeOffset.seconds}.${logoRecognitionAnnotationSegmentStartTimeOffset.nanos}`
      );
      const logoRecognitionAnnotationSegmentEndTimeOffset =
        logoRecognitionAnnotationSegment.endTimeOffset;
      console.log(
        `\tEnd Time Offset : ${logoRecognitionAnnotationSegmentEndTimeOffset.seconds}.${logoRecognitionAnnotationSegmentEndTimeOffset.nanos}`
      );
    }
  }
}

Python


from google.cloud import videointelligence_v1p3beta1
from google.cloud.videointelligence_v1p3beta1 import enums


def sample_annotate_video(local_file_path="resources/googlework_tiny.mp4"):
    """Performs asynchronous video annotation for logo recognition on a local file."""

    client = videointelligence_v1p3beta1.VideoIntelligenceServiceClient()

    with io.open(local_file_path, "rb") as f:
        input_content = f.read()
    features_element = enums.Feature.LOGO_RECOGNITION
    features = [features_element]

    operation = client.annotate_video(input_content=input_content, features=features)

    print(u"Waiting for operation to complete...")
    response = operation.result()

    # Get the first response, since we sent only one video.
    annotation_result = response.annotation_results[0]
    # Annotations for list of logos detected, tracked and recognized in video.
    for logo_recognition_annotation in annotation_result.logo_recognition_annotations:
        entity = logo_recognition_annotation.entity
        # Opaque entity ID. Some IDs may be available in [Google Knowledge Graph
        # Search API](https://developers.google.com/knowledge-graph/).
        print(u"Entity Id : {}".format(entity.entity_id))
        # Textual description, e.g. `Google`.
        print(u"Description : {}".format(entity.description))
        # All logo tracks where the recognized logo appears. Each track corresponds
        # to one logo instance appearing in consecutive frames.
        for track in logo_recognition_annotation.tracks:
            # Video segment of a track.
            segment = track.segment
            segment_start_time_offset = segment.start_time_offset
            print(
                u"\n\tStart Time Offset : {}.{}".format(
                    segment_start_time_offset.seconds, segment_start_time_offset.nanos
                )
            )
            segment_end_time_offset = segment.end_time_offset
            print(
                u"\tEnd Time Offset : {}.{}".format(
                    segment_end_time_offset.seconds, segment_end_time_offset.nanos
                )
            )
            print(u"\tConfidence : {}".format(track.confidence))
            # The object with timestamp and attributes per frame in the track.
            for timestamped_object in track.timestamped_objects:
                # Normalized Bounding box in a frame, where the object is located.
                normalized_bounding_box = timestamped_object.normalized_bounding_box
                print(u"\n\t\tLeft : {}".format(normalized_bounding_box.left))
                print(u"\t\tTop : {}".format(normalized_bounding_box.top))
                print(u"\t\tRight : {}".format(normalized_bounding_box.right))
                print(u"\t\tBottom : {}".format(normalized_bounding_box.bottom))
                # Optional. The attributes of the object in the bounding box.
                for attribute in timestamped_object.attributes:
                    print(u"\n\t\t\tName : {}".format(attribute.name))
                    print(u"\t\t\tConfidence : {}".format(attribute.confidence))
                    print(u"\t\t\tValue : {}".format(attribute.value))
            # Optional. Attributes in the track level.
            for track_attribute in track.attributes:
                print(u"\n\t\tName : {}".format(track_attribute.name))
                print(u"\t\tConfidence : {}".format(track_attribute.confidence))
                print(u"\t\tValue : {}".format(track_attribute.value))
        # All video segments where the recognized logo appears. There might be
        # multiple instances of the same logo class appearing in one VideoSegment.
        for logo_recognition_annotation_segment in logo_recognition_annotation.segments:
            logo_recognition_annotation_segment_start_time_offset = (
                logo_recognition_annotation_segment.start_time_offset
            )
            print(
                u"\n\tStart Time Offset : {}.{}".format(
                    logo_recognition_annotation_segment_start_time_offset.seconds,
                    logo_recognition_annotation_segment_start_time_offset.nanos,
                )
            )
            logo_recognition_annotation_segment_end_time_offset = (
                logo_recognition_annotation_segment.end_time_offset
            )
            print(
                u"\tEnd Time Offset : {}.{}".format(
                    logo_recognition_annotation_segment_end_time_offset.seconds,
                    logo_recognition_annotation_segment_end_time_offset.nanos,
                )
            )