[BUGFIX] Add timeout for bad ffmpeg image conversions (#554)
* [BUGFIX] Add timeout for bad ffmpeg image conversions * add -y * lint
This commit is contained in:
parent
ecdae163f6
commit
baebd9cba7
2 changed files with 9 additions and 4 deletions
|
|
@ -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]:
|
||||
|
|
|
|||
|
|
@ -42,7 +42,9 @@ def convert_download_thumbnail(entry: Entry, error_if_not_found: bool = True) ->
|
|||
return
|
||||
|
||||
if not download_thumbnail_path == download_thumbnail_path_as_jpg:
|
||||
FFMPEG.run(["-bitexact", "-i", download_thumbnail_path, download_thumbnail_path_as_jpg])
|
||||
FFMPEG.run(
|
||||
["-y", "-bitexact", "-i", download_thumbnail_path, download_thumbnail_path_as_jpg]
|
||||
)
|
||||
FileHandler.delete(download_thumbnail_path)
|
||||
|
||||
|
||||
|
|
@ -78,7 +80,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(["-y", "-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)
|
||||
|
|
|
|||
Loading…
Reference in a new issue