From 63c866166b63d52b8bd3f14c089f39aab486cae1 Mon Sep 17 00:00:00 2001 From: Brett Williams Date: Wed, 14 Dec 2022 23:49:24 -0800 Subject: [PATCH] Fix issue with getting frame count from webm files in ffmpeg --- utilities/ffmpeg_worker.py | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/utilities/ffmpeg_worker.py b/utilities/ffmpeg_worker.py index 3a2b8e2..64d2cd3 100644 --- a/utilities/ffmpeg_worker.py +++ b/utilities/ffmpeg_worker.py @@ -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