Skip to content

Commit

Permalink
Make subprocess more reliable
Browse files Browse the repository at this point in the history
  • Loading branch information
WyattBlue committed Dec 15, 2023
1 parent 4ca42fe commit 0528d29
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 13 deletions.
21 changes: 10 additions & 11 deletions auto_editor/ffwrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from fractions import Fraction
from pathlib import Path
from re import search
from shutil import which
from subprocess import PIPE, Popen
from typing import Any

Expand Down Expand Up @@ -39,21 +40,19 @@ def _set_ff_path(ff_location: str | None, my_ffmpeg: bool) -> str:

self.debug = debug
self.show_cmd = show_cmd
self.path = _set_ff_path(ff_location, my_ffmpeg)
_path: str | None = _set_ff_path(ff_location, my_ffmpeg)

if _path == "ffmpeg":
_path = which("ffmpeg")

if _path is None:
Log().error("Did not find ffmpeg on PATH.")
self.path = _path

try:
_version = get_stdout([self.path, "-version"]).split("\n")[0]
self.version = _version.replace("ffmpeg version", "").strip().split(" ")[0]
except FileNotFoundError:
if sys.platform == "darwin":
Log().error(
"No ffmpeg found, download via homebrew or install ae-ffmpeg."
)
if sys.platform == "win32":
Log().error(
"No ffmpeg found, download ffmpeg with your favorite package "
"manager (ex chocolatey), or install ae-ffmpeg."
)

Log().error("ffmpeg must be installed and on PATH.")

def print(self, message: str) -> None:
Expand Down
4 changes: 2 additions & 2 deletions auto_editor/utils/func.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,9 @@ def get_stdout(cmd: list[str]) -> str:


def get_stdout_bytes(cmd: list[str]) -> bytes:
from subprocess import PIPE, Popen
from subprocess import DEVNULL, PIPE, Popen

return Popen(cmd, stdout=PIPE, stderr=PIPE).communicate()[0]
return Popen(cmd, stdin=DEVNULL, stdout=PIPE, stderr=PIPE).communicate()[0]


def aspect_ratio(width: int, height: int) -> tuple[int, int]:
Expand Down

0 comments on commit 0528d29

Please sign in to comment.