Skip to content

Commit

Permalink
ffmpeg: Detect and fail on software decoder fallback
Browse files Browse the repository at this point in the history
That goal of fluster is to test one specific implementation, allowing
software fallback hides possible integration issues.
  • Loading branch information
ndufresne committed Dec 17, 2024
1 parent c994fdd commit 983e930
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 7 deletions.
22 changes: 16 additions & 6 deletions fluster/decoders/ffmpeg.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,16 +119,26 @@ 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:
Expand Down
5 changes: 4 additions & 1 deletion fluster/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)}"')

Expand Down

0 comments on commit 983e930

Please sign in to comment.