From dc5c3b9475079c83acf7757d0589cb0eddcb9f2a Mon Sep 17 00:00:00 2001 From: Michael Hirsch Date: Sun, 15 Nov 2020 08:46:16 -0500 Subject: [PATCH] better error if ffplay not found --- src/pylivestream/ffmpeg.py | 6 +++--- src/pylivestream/utils.py | 8 +++++++- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/pylivestream/ffmpeg.py b/src/pylivestream/ffmpeg.py index ad477b6..b55ecaa 100644 --- a/src/pylivestream/ffmpeg.py +++ b/src/pylivestream/ffmpeg.py @@ -65,11 +65,11 @@ def listener(self): TIMEOUT = 0.5 - FFPLAY = shutil.which("ffplay") - if not FFPLAY: + exe = shutil.which("ffplay") + if not exe: raise FileNotFoundError("FFplay not found, cannot start listener") - cmd = [FFPLAY, "-loglevel", "error", "-timeout", "5", "-autoexit", "rtmp://localhost"] + cmd = [exe, "-loglevel", "error", "-timeout", "5", "-autoexit", "rtmp://localhost"] print( "starting Localhost RTMP listener. \n\n", diff --git a/src/pylivestream/utils.py b/src/pylivestream/utils.py index 95c6748..1a9138b 100644 --- a/src/pylivestream/utils.py +++ b/src/pylivestream/utils.py @@ -4,6 +4,7 @@ import sys import typing as T import importlib.resources +import shutil from .ffmpeg import get_meta @@ -50,8 +51,13 @@ def check_device(cmd: T.Sequence[str]) -> bool: def check_display(fn: Path = None) -> bool: """see if it's possible to display something with a test file""" + exe = shutil.which("ffplay") + + if not exe: + raise FileNotFoundError("FFplay not found") + def _check_disp(fn: Path) -> int: - cmd = ["ffplay", "-loglevel", "error", "-t", "1.0", "-autoexit", str(fn)] + cmd = [exe, "-loglevel", "error", "-t", "1.0", "-autoexit", str(fn)] return subprocess.run(cmd, timeout=10).returncode if fn: