Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ffmpeg: Detect and fail on software decoder fallback #224

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 16 additions & 7 deletions fluster/decoders/ffmpeg.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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:
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