32
32
import sys
33
33
import time
34
34
35
- from google .cloud .gapic .videointelligence .v1beta1 import enums
36
- from google .cloud .gapic .videointelligence .v1beta1 import (
37
- video_intelligence_service_client )
35
+ from google .cloud import videointelligence_v1beta2
36
+ from google .cloud .videointelligence_v1beta2 import enums
38
37
# [END imports]
39
38
40
39
41
40
def analyze_shots (path ):
42
41
""" Detects camera shot changes. """
43
42
# [START construct_request]
44
- video_client = (video_intelligence_service_client .
45
- VideoIntelligenceServiceClient ())
43
+ video_client = videointelligence_v1beta2 .VideoIntelligenceServiceClient ()
46
44
features = [enums .Feature .SHOT_CHANGE_DETECTION ]
47
45
operation = video_client .annotate_video (path , features )
48
46
# [END construct_request]
@@ -58,13 +56,14 @@ def analyze_shots(path):
58
56
# [END check_operation]
59
57
60
58
# [START parse_response]
61
- shots = operation .result ().annotation_results [0 ]
62
-
63
- for note , shot in enumerate (shots .shot_annotations ):
64
- print ('Scene {}: {} to {}' .format (
65
- note ,
66
- shot .start_time_offset ,
67
- shot .end_time_offset ))
59
+ shots = operation .result ().annotation_results [0 ].shot_annotations
60
+
61
+ for i , shot in enumerate (shots ):
62
+ start_time = (shot .start_time_offset .seconds +
63
+ shot .start_time_offset .nanos / 1e9 )
64
+ end_time = (shot .end_time_offset .seconds +
65
+ shot .end_time_offset .nanos / 1e9 )
66
+ print ('\t Shot {}: {} to {}' .format (i , start_time , end_time ))
68
67
# [END parse_response]
69
68
70
69
0 commit comments