[BUGFIX] Add timeout for bad ffmpeg image conversions

This commit is contained in:
Jesse Bannon 2023-03-16 23:36:13 -07:00
parent ecdae163f6
commit 89b06132f6
2 changed files with 6 additions and 3 deletions

View file

@ -73,7 +73,7 @@ class FFMPEG:
return f"{relative_file_path}.out.{extension}"
@classmethod
def run(cls, ffmpeg_args: List[str]) -> None:
def run(cls, ffmpeg_args: List[str], timeout: Optional[float] = None) -> None:
"""
Runs an ffmpeg command. Should not include 'ffmpeg' as the beginning argument.
@ -81,6 +81,8 @@ class FFMPEG:
----------
ffmpeg_args:
Arguments to pass to ffmpeg. Each one will be separated by a space.
timeout
Optional. timeout
"""
cls._ensure_installed()
@ -88,7 +90,7 @@ class FFMPEG:
cmd.extend(ffmpeg_args)
logger.debug("Running %s", " ".join(cmd))
with Logger.handle_external_logs(name="ffmpeg"):
subprocess.run(cmd, check=True, capture_output=True)
subprocess.run(cmd, check=True, capture_output=True, timeout=timeout)
def _create_metadata_chapter_entry(start_sec: int, end_sec: int, title: str) -> List[str]:

View file

@ -78,7 +78,8 @@ def download_and_convert_url_thumbnail(
tmp_output_path = FFMPEG.tmp_file_path(
relative_file_path=thumbnail.name, extension="jpg"
)
FFMPEG.run(["-bitexact", "-i", thumbnail.name, tmp_output_path])
# Add timeout of 1 second in case ffmpeg hangs from a bad thumbnail
FFMPEG.run(["-bitexact", "-i", thumbnail.name, tmp_output_path], timeout=1)
# Have FileHandler handle the move to a potential cross-device
FileHandler.move(tmp_output_path, output_thumbnail_path)