I’m a newbie, and I followed to use videointelligence to characterize a video. My python code (similar to the video except I log as well as print) works on short videos, but on a 25 minute video, I get
google.api_core.exceptions.RetryError: Timeout of 600.0s exceeded, last exception: 504 Deadline Exceeded
even though I have increased the timeout to 12000 seconds. Here is my code which I emphasize runs on short (< 7 minutes) videos, but fails on longer (25 minute) videos.
import io
from dotenv import load_dotenv
from google.cloud import videointelligence
maxtime = 12000
filename = ‘1998_01_South_Padre.mp4’
#filename = ‘kayak.mp4’
logfile = ‘log.txt’ #tagerrorlog lists problem tags that have to be fixed by TagThatPhoto or by editing the pix.cvs file
log = open(logfile, ‘a’)
def main():
video_client = videointelligence.VideoIntelligenceServiceClient()
features = [videointelligence.Feature.LABEL_DETECTION]
with open(filename,‘rb’) as media_file:
input_content = media_file.read()
operation = video_client.annotate_video(
request={
‘features’:features,
‘input_uri’:‘gs://resource-tutorial/cat.mp4’,
‘input_content’: input_content,
}
)
print(‘\nProcessing video for label annotations: ‘+filename)
log.write(’\n\nProcessing video for label annotations: ‘+filename+’\n’)
result = operation.result(timeout=maxtime)
print(‘\nFinished processing.’)
segment_labels = result.annotation_results[0].segment_label_annotations
for segment_label in segment_labels:
print(‘Video label description: {}’.format(segment_label.entity.description))
log.write(‘Video label description: {}’.format(segment_label.entity.description))
for category_entity in segment_label.category_entities:
print(‘\tLabel category: {}’.format(category_entity.description))
log.write(‘\tLabel category: {}’.format(category_entity.description))
for i, segment in enumerate(segment_label.segments):
start_time = (
segment.segment.start_time_offset.seconds
- segment.segment.start_time_offset.microseconds / 1e6
)
end_time = (
segment.segment.end_time_offset.seconds - segment.segment.end_time_offset.microseconds / 1e6
)
positions = ‘{}s to {}s’.format(start_time, end_time)
confidence = segment.confidence
print(‘\tSegment {}: {}’.format(i,positions))
print(‘\tConfidence: {}’.format(confidence))
log.write(‘\tSegment {}: {}’.format(i,positions))
log.write(‘\tConfidence: {}’.format(confidence))
log.write(‘\n’)
print(‘\n’)
log.close()
if name == ‘main’:
load_dotenv()
main()