Currently I am using the AnnotateVideo function to analyse videos. Is there any way to analyse only a section of a video, such as providing start_time and end_time as an argument to the function ?
gs_video_path ='gs://'+bucket_name+'/'+videodata.video.path+videodata.video.name
print(gs_video_path)
video_client = videointelligence.VideoIntelligenceServiceClient()
features = [videointelligence.enums.Feature.OBJECT_TRACKING]
operation = video_client.annotate_video(gs_video_path, features=features)
You can analyse only the sections you're interested in by providing a VideoContext
with a VideoSegment
list. Here is an example with a single 21..42s segment:
from google.cloud import videointelligence
from google.cloud.videointelligence import enums, types
video_client = videointelligence.VideoIntelligenceServiceClient()
gs_video_path = f'gs://{bucket_name}/{videodata.video.path}{videodata.video.name}'
features = [enums.Feature.OBJECT_TRACKING]
segment = types.VideoSegment()
segment.start_time_offset.FromSeconds(21)
segment.end_time_offset.FromSeconds(42)
context = types.VideoContext(segments=[segment])
operation = video_client.annotate_video(
gs_video_path,
features=features,
video_context=context)
If you want more examples, I recently wrote this tutorial: https://codelabs.developers.google.com/codelabs/cloud-video-intelligence-python3