logo
Browse Source

update

main
junjie.jiang 2 years ago
parent
commit
25d183349d
  1. 25
      video_decoder.py

25
video_decoder.py

@ -106,23 +106,24 @@ class VideoDecoder(PyOperator):
continue continue
yield frame yield frame
# @staticmethod
# def get_video_duration(video):
# print(video)
# if video.duration is not None:
# return float(video.duration * video.time_base)
# elif video.metadata.get('DURATION') is not None:
# time_str = video.metadata['DURATION']
# return reduce(lambda x, y: float(x) * 60 + float(y), time_str.split(':'))
# else:
# return None
@staticmethod
def get_video_duration(video):
if video.duration is not None:
return float(video.duration * video.time_base)
elif video.metadata.get('DURATION') is not None:
time_str = video.metadata['DURATION']
return reduce(lambda x, y: float(x) * 60 + float(y), time_str.split(':'))
else:
return None
def __call__(self, video_path: str) -> Generator: def __call__(self, video_path: str) -> Generator:
with av.open(video_path) as container: with av.open(video_path) as container:
stream = container.streams.video[0] stream = container.streams.video[0]
duration = float(container.duration) / 1000000
image_format = 'RGB'
duration = VideoDecoder.get_video_duration(stream)
if duration is None:
duration = float(container.duration) / 1000000
image_format = 'RGB'
frame_gen = VideoDecoder._decdoe(stream, container, self._start_time) frame_gen = VideoDecoder._decdoe(stream, container, self._start_time)
sample_function = self.get_sample(stream, duration) sample_function = self.get_sample(stream, duration)
for frame in sample_function(frame_gen): for frame in sample_function(frame_gen):

Loading…
Cancel
Save