From 488c85268b24c6b62ae5aa90c67adaa7f3c714c1 Mon Sep 17 00:00:00 2001 From: Nicolas Dufresne Date: Tue, 17 Dec 2024 14:14:32 -0500 Subject: [PATCH] ffmpeg: Detect and fail on software decoder fallback The goal of fluster is to test one specific implementation, allowing software fallback hides possible integration issues. --- fluster/decoders/ffmpeg.py | 23 ++++++++++++++++------- fluster/utils.py | 5 ++++- 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/fluster/decoders/ffmpeg.py b/fluster/decoders/ffmpeg.py index 76823a6..6684997 100644 --- a/fluster/decoders/ffmpeg.py +++ b/fluster/decoders/ffmpeg.py @@ -23,7 +23,7 @@ from fluster.codec import Codec, OutputFormat from fluster.decoder import Decoder, register_decoder -from fluster.utils import file_checksum, run_command, run_command_with_output +from fluster.utils import file_checksum, run_command_with_output @lru_cache(maxsize=128) @@ -119,16 +119,25 @@ def decode( # MD5 muxer if self.use_md5_muxer and not keep_files: command.extend(["-f", "md5", "-"]) - output = run_command_with_output(command, timeout=timeout, verbose=verbose) + # Output file + else: + command.extend(["-f", "rawvideo", output_filepath]) + + output = run_command_with_output(command, timeout=timeout, verbose=verbose, keep_stderr=True) + + # Detect software fallback and turn this into an error + if self.hw_acceleration: + hw_error = re.search(r"Failed setup for format", output) + if hw_error: + raise Exception("Failed to use HW accelerator.") + + if self.use_md5_muxer and not keep_files: md5sum = re.search(r"MD5=([0-9a-fA-F]+)\s*", output) if not md5sum: raise Exception("No MD5 found in the program trace.") return md5sum.group(1).lower() - - # Output file - command.extend(["-f", "rawvideo", output_filepath]) - run_command(command, timeout=timeout, verbose=verbose) - return file_checksum(output_filepath) + else: + return file_checksum(output_filepath) @lru_cache(maxsize=128) def check(self, verbose: bool) -> bool: diff --git a/fluster/utils.py b/fluster/utils.py index cd50a07..63eefa5 100644 --- a/fluster/utils.py +++ b/fluster/utils.py @@ -88,9 +88,12 @@ def run_command_with_output( verbose: bool = False, check: bool = True, timeout: Optional[int] = None, + keep_stderr: bool = False, ) -> str: """Runs a command and returns std output trace""" - serr = subprocess.DEVNULL if not verbose else subprocess.STDOUT + serr = subprocess.DEVNULL + if verbose or keep_stderr: + serr = subprocess.STDOUT if verbose: print(f'\nRunning command "{" ".join(command)}"')