1
votes

I have set up a Google Cloud function which takes a video uploaded from an app engine front engine and placed in a google cloud bucket and then applies the google cloud video intelligence api. The results of the API are displayed in the console. I want these results to be put in a json file in a google cloud bucket so that I can access them through big query.

I have allocated the out_put_uri method a variable as to where the json file should end up however I am unsure as to how to call this method.

import os

from google.cloud import videointelligence

def video_dump(event, context):

    """ Detects camera shot changes. """
# [START video_shot_tutorial_construct_request]
video_client = videointelligence.VideoIntelligenceServiceClient()
features = [videointelligence.enums.Feature.SHOT_CHANGE_DETECTION]
operation = video_client.annotate_video('gs://'+event['bucket']+'/'+event['name'], features=features)
output_uri = 'gs://mastersproject-252719.appspot.com/json'
# [END video_shot_tutorial_construct_request]
print('\nProcessing video for shot change annotations:')

# [START video_shot_tutorial_check_operation]
result = operation.result(timeout=120)

print('\nFinished processing.')
# [END video_shot_tutorial_check_operation]

# [START video_shot_tutorial_parse_response]
for i, shot in enumerate(result.annotation_results[0].shot_annotations):
    start_time = (shot.start_time_offset.seconds +
                  shot.start_time_offset.nanos / 1e9)
    end_time = (shot.end_time_offset.seconds +
                shot.end_time_offset.nanos / 1e9)
    print('\tShot {}: {} to {}'.format(i, start_time, end_time))
# [END video_shot_tutorial_parse_response]

I am looking for a json file of results to be created and placed in gs://mastersproject-252719.appspot.com/json

1

1 Answers

0
votes

I believe you just include the output_uri in the annotate_video parentheses, like below:

operation = video_client.annotate_video('gs://'+event['bucket']+'/'+event['name'],
  features=features, output_uri = 'gs://mastersproject-252719.appspot.com/json')