In Part 2 of the Google Video Intelligence API and Python series, we will learn how to use the API by writing our first Python script to detect different things in a video file.
The Video Intelligence API can detect and extract information it detected in a video footage. The LABEL DETECTION feature identifies objects, locations, activities, animal species, products, and more.
Buy Me a Coffee? Your support is much appreciated!
PayPal Me: https://www.paypal.me/jiejenn/5
Venmo: @Jie-Jenn
Source Code:
import os, io
import pandas as pd
from google.cloud import videointelligence
os.environ['GOOGLE_APPLICATION_CREDENTIALS'] = 'GoogleCloudKey_MyServiceAcct.json'
video_client = videointelligence.VideoIntelligenceServiceClient()
features = [videointelligence.enums.Feature.LABEL_DETECTION]
gs_URI = 'gs://dummy_videos/logo clip.mp4'
operation = video_client.annotate_video(gs_URI, features=features)
print('\nProcessing video for label annotations:')
result = operation.result(timeout=120)
annotation_results = result.annotation_results
segment_labels = annotation_results[0].segment_label_annotations
for i, segment_label in enumerate(segment_labels):
print('Video label description: {}'.format(
segment_label.entity.description))
for category_entity in segment_label.category_entities:
print('\tLabel category description: {}'.format(
category_entity.description))
# 1e9 = 1,000,000,000 (a billion) second
for i, segment in enumerate(segment_label.segments):
start_time = (segment.segment.start_time_offset.seconds +
segment.segment.start_time_offset.nanos / 1e9)
end_time = (segment.segment.end_time_offset.seconds +
segment.segment.end_time_offset.nanos / 1e9)
positions = '{}s to {}s'.format(start_time, end_time)
confidence = segment.confidence
print('\tSegment {}: {}'.format(i, positions))
print('\tConfidence: {}'.format(confidence))
print('\n')
Hi Jie-Jenn,
I tried your code. I am getting the following error message. Any thoughts:
AttributeError Traceback (most recent call last)
in
8 gs_URI=’gs://talashi/VID_20190206_163415.mp4′
9 operation= video_client.annotate_video(gs_URI, features= features)
—> 10 result= operation.result(timeout=120)
11 annotation_results=result
AttributeError: ‘coroutine’ object has no attribute ‘result’
how we can use video from our system without using google bucket