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
import re
import time
import ffmpeg
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,
args=args)
self.total_frames = -1
if os.path.exists(input_path):
media_stats = ffmpeg.probe(input_path)
for stream in media_stats['streams']:
if stream['codec_type'] == 'video':
self.total_frames = stream['nb_frames']
break
stream_info = subprocess.check_output([self.renderer_path(), "-i", # https://stackoverflow.com/a/61604105
input_path, "-map", "0:v:0", "-c", "copy", "-f", "null", "-y",
"/dev/null"], stderr=subprocess.STDOUT).decode('utf-8')
found_frames = re.findall('frame=\s*(\d+)', stream_info)
self.total_frames = found_frames[-1] if found_frames else '-1'
self.frame = 0
# Stats