Fix issue with getting frame count from webm files in ffmpeg

This commit is contained in:
Brett Williams
2022-12-14 23:49:24 -08:00
parent 086eed5437
commit 63c866166b

View File

@@ -1,7 +1,6 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
import re import re
import time import time
import ffmpeg
from utilities.render_worker import * from utilities.render_worker import *
@@ -14,14 +13,11 @@ class FFMPEGRenderWorker(BaseRenderWorker):
super(FFMPEGRenderWorker, self).__init__(input_path=input_path, output_path=output_path, ignore_extensions=True, super(FFMPEGRenderWorker, self).__init__(input_path=input_path, output_path=output_path, ignore_extensions=True,
args=args) args=args)
self.total_frames = -1 stream_info = subprocess.check_output([self.renderer_path(), "-i", # https://stackoverflow.com/a/61604105
if os.path.exists(input_path): input_path, "-map", "0:v:0", "-c", "copy", "-f", "null", "-y",
media_stats = ffmpeg.probe(input_path) "/dev/null"], stderr=subprocess.STDOUT).decode('utf-8')
for stream in media_stats['streams']: found_frames = re.findall('frame=\s*(\d+)', stream_info)
if stream['codec_type'] == 'video': self.total_frames = found_frames[-1] if found_frames else '-1'
self.total_frames = stream['nb_frames']
break
self.frame = 0 self.frame = 0
# Stats # Stats