Skip to content

Commit

Permalink
update samples to v1 [(#1221)](GoogleCloudPlatform/python-docs-sample…
Browse files Browse the repository at this point in the history
…s#1221)

* update samples to v1

* replace while loop with operation.result(timeout)

* addressing review comments

* flake

* flake
  • Loading branch information
dizcology authored and Jon Wayne Parrott committed Nov 29, 2017
1 parent 3acd5f5 commit df56ca2
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 16 deletions.
2 changes: 1 addition & 1 deletion samples/shotchange/requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
google-cloud-videointelligence==0.28.0
google-cloud-videointelligence==1.0.0
21 changes: 6 additions & 15 deletions samples/shotchange/shotchange.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,36 +29,27 @@
# [START full_tutorial]
# [START imports]
import argparse
import sys
import time

from google.cloud import videointelligence_v1beta2
from google.cloud.videointelligence_v1beta2 import enums
from google.cloud import videointelligence
# [END imports]


def analyze_shots(path):
""" Detects camera shot changes. """
# [START construct_request]
video_client = videointelligence_v1beta2.VideoIntelligenceServiceClient()
features = [enums.Feature.SHOT_CHANGE_DETECTION]
operation = video_client.annotate_video(path, features)
video_client = videointelligence.VideoIntelligenceServiceClient()
features = [videointelligence.enums.Feature.SHOT_CHANGE_DETECTION]
operation = video_client.annotate_video(path, features=features)
# [END construct_request]
print('\nProcessing video for shot change annotations:')

# [START check_operation]
while not operation.done():
sys.stdout.write('.')
sys.stdout.flush()
time.sleep(20)

result = operation.result(timeout=90)
print('\nFinished processing.')
# [END check_operation]

# [START parse_response]
shots = operation.result().annotation_results[0].shot_annotations

for i, shot in enumerate(shots):
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 +
Expand Down

0 comments on commit df56ca2

Please sign in to comment.