static_ffmpeg
static_ffmpeg copied to clipboard
Consider to use sys.stderr instead of sys.stdout when frozen
Can you use stderr when frozen instead of stdout, sometimes frozen application don't have access to stdout because they don't have any console which is gonna make the download fail because this library print directly into stdout and stdout is None
You can change it or simply add this:
if getattr(sys, "frozen", False):
sys.stdout = sys.stderr
Because of this, to get around this problem in my project i did a little patching:
# modify static_ffmpeg add_paths
def add_ffmpeg_to_path(weak=False) -> bool:
"""Add the ffmpeg executable to the path"""
if getattr(sys, "frozen", False):
# pylint: disable=import-outside-toplevel, protected-access
from static_ffmpeg import _add_paths, run
run.sys.stdout = sys.stderr
if weak:
has_ffmpeg = _add_paths._has("ffmpeg") is not None
has_ffprobe = _add_paths._has("ffprobe") is not None
if has_ffmpeg and has_ffprobe:
return False
ffmpeg, _ = run.get_or_fetch_platform_executables_else_raise()
os.environ["PATH"] = os.pathsep.join([os.path.dirname(ffmpeg), os.environ["PATH"]])
return True
else:
# pylint: disable=import-outside-toplevel
from static_ffmpeg import _add_paths
return _add_paths.add_paths()
Thank you 🙏