From fbb300d0b59cf8d21808eecc950f78dc54d2a02a Mon Sep 17 00:00:00 2001 From: anne-o-pixel <81879599+anne-o-pixel@users.noreply.github.com> Date: Sat, 18 Jul 2026 17:20:56 +0000 Subject: [PATCH 1/8] Implement clean_env to manage environment variables Add clean_env function to remove LD_LIBRARY_PATH from environment. --- fastflix/shared.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/fastflix/shared.py b/fastflix/shared.py index c2d55239..a239f1ab 100644 --- a/fastflix/shared.py +++ b/fastflix/shared.py @@ -25,6 +25,17 @@ base_path = os.path.abspath(".") pyinstaller = False +def clean_env(): + """Return a copy of os.environ with PyInstaller's LD_LIBRARY_PATH removed. + + PyInstaller sets LD_LIBRARY_PATH to its bundled lib dir, which causes + system tools like ffmpeg to load incompatible shared libraries. + """ + env = os.environ.copy() + if pyinstaller: + env.pop("LD_LIBRARY_PATH", None) + return env + from PySide6 import QtGui, QtWidgets from fastflix.language import t From a4fc42f9ab680d106f0c9b1d0ff65cbd6281a60b Mon Sep 17 00:00:00 2001 From: anne-o-pixel <81879599+anne-o-pixel@users.noreply.github.com> Date: Sat, 18 Jul 2026 17:22:31 +0000 Subject: [PATCH 2/8] Add clean_env to subprocess environment --- fastflix/command_runner.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/fastflix/command_runner.py b/fastflix/command_runner.py index 35a9768d..623337b5 100644 --- a/fastflix/command_runner.py +++ b/fastflix/command_runner.py @@ -14,6 +14,8 @@ from psutil import Popen +from fastflix.shared import clean_env + try: from psutil import ( HIGH_PRIORITY_CLASS, @@ -93,6 +95,7 @@ def start_exec(self, command, work_dir: str = None, shell: bool = False, errors= stderr=stderr_handle, stdin=PIPE, # FFmpeg can try to read stdin and wrecks havoc on linux encoding="utf-8", + env=clean_env(), ) except PermissionError: logger.error( From 840c9df8aa898b8643dcb346cfb2a96e448031bd Mon Sep 17 00:00:00 2001 From: anne-o-pixel <81879599+anne-o-pixel@users.noreply.github.com> Date: Sat, 18 Jul 2026 17:23:26 +0000 Subject: [PATCH 3/8] Use clean_env() in run_check_features function Added clean_env() to subprocess calls for feature checks. --- fastflix/rigaya_helpers.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/fastflix/rigaya_helpers.py b/fastflix/rigaya_helpers.py index a971739b..a392ed10 100644 --- a/fastflix/rigaya_helpers.py +++ b/fastflix/rigaya_helpers.py @@ -2,6 +2,7 @@ from dataclasses import dataclass, field from subprocess import run, PIPE +from fastflix.shared import clean_env @dataclass class Encoder: @@ -72,11 +73,11 @@ def parse_qsv_devices(split_text: list[str]) -> QSVEncoder: def run_check_features(executable, is_qsv=False): outputs = [] if is_qsv: - result = run([executable, "--check-features"], stdout=PIPE, stderr=PIPE, encoding="utf-8") + result = run([executable, "--check-features"], stdout=PIPE, stderr=PIPE, encoding="utf-8", env=clean_env()) outputs.append(result.stdout.splitlines()) else: for i in range(10): - result = run([executable, "--check-features", str(i)], stdout=PIPE, stderr=PIPE, encoding="utf-8") + result = run([executable, "--check-features", str(i)], stdout=PIPE, stderr=PIPE, encoding="utf-8", env=clean_env()) if result.stderr: break outputs.append(result.stdout.splitlines()) From 8d30c53227c464da4469ddbddca5074d9a549525 Mon Sep 17 00:00:00 2001 From: anne-o-pixel <81879599+anne-o-pixel@users.noreply.github.com> Date: Sat, 18 Jul 2026 17:25:02 +0000 Subject: [PATCH 4/8] Add clean_env to subprocess calls in background_tasks Updated the run method to include a clean environment for subprocesses. --- fastflix/widgets/background_tasks.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/fastflix/widgets/background_tasks.py b/fastflix/widgets/background_tasks.py index 0641ae5f..dbd225e8 100644 --- a/fastflix/widgets/background_tasks.py +++ b/fastflix/widgets/background_tasks.py @@ -11,6 +11,7 @@ from ffmpeg_normalize import FFmpegNormalize from fastflix.flix import extract_attachments +from fastflix.shared import clean_env from fastflix.language import t from fastflix.models.fastflix_app import FastFlixApp from fastflix.shared import clean_file_string @@ -42,7 +43,7 @@ def __init__(self, main, command=""): def run(self): self.main.thread_logging_signal.emit(f"DEBUG:{t('Generating thumbnail')}: {_format_command(self.command)}") - result = run(self.command, stdin=PIPE, stdout=PIPE, stderr=STDOUT) + result = run(self.command, stdin=PIPE, stdout=PIPE, stderr=STDOUT, env=clean_env()) if result.returncode > 0: if "No such filter: 'zscale'" in result.stdout.decode(encoding="utf-8", errors="ignore"): self.main.thread_logging_signal.emit( @@ -156,6 +157,7 @@ def run(self): command, stdout=PIPE, stderr=STDOUT, + env=clean_env(), ) stdout, _ = self._process.communicate() returncode = self._process.returncode @@ -224,6 +226,7 @@ def _get_subtitle_format(self): stdout=PIPE, stderr=STDOUT, text=True, + env=clean_env(), ) if result.returncode != 0: @@ -530,6 +533,7 @@ def run(self): stdout=PIPE, stderr=open(self.app.fastflix.current_video.work_path / "hdr10extract_out.txt", "wb"), # stdin=PIPE, # FFmpeg can try to read stdin and wrecks havoc + env=clean_env(), ) process_two = Popen( @@ -539,6 +543,7 @@ def run(self): stdin=process.stdout, encoding="utf-8", cwd=str(self.app.fastflix.current_video.work_path), + env=clean_env(), ) with open(self.app.fastflix.current_video.work_path / "hdr10extract_out.txt", "r", encoding="utf-8") as f: From 64d9cad91309dcc54a842cd09fe4298d6c46db26 Mon Sep 17 00:00:00 2001 From: anne-o-pixel <81879599+anne-o-pixel@users.noreply.github.com> Date: Sat, 18 Jul 2026 17:26:30 +0000 Subject: [PATCH 5/8] Update subprocess call to include cleaned environment Pass cleaned environment to subprocess run for thumbnail generation. --- fastflix/widgets/main_post_encode.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/fastflix/widgets/main_post_encode.py b/fastflix/widgets/main_post_encode.py index 38ce1b2e..d69db28f 100644 --- a/fastflix/widgets/main_post_encode.py +++ b/fastflix/widgets/main_post_encode.py @@ -141,7 +141,8 @@ def _record_history(self, video: Video, success: bool = True): from subprocess import run as subprocess_run from fastflix.flix import generate_thumbnail_command - + from fastflix.shared import clean_env + thumb_command = generate_thumbnail_command( config=self.app.fastflix.config, source=video.source, @@ -150,7 +151,7 @@ def _record_history(self, video: Video, success: bool = True): start_time=video.video_settings.start_time or 0, input_track=video.video_settings.selected_track, ) - result = subprocess_run(thumb_command, stdin=PIPE, stdout=PIPE, stderr=STDOUT) + result = subprocess_run(thumb_command, stdin=PIPE, stdout=PIPE, stderr=STDOUT, env=clean_env()) if result.returncode != 0 or not thumb_output.exists(): logger.warning("Failed to generate thumbnail for history entry") entry.thumbnail_filename = "" From 6f8656fff8a6c34521932b619f3d7ed2e01e4014 Mon Sep 17 00:00:00 2001 From: anne-o-pixel <81879599+anne-o-pixel@users.noreply.github.com> Date: Sat, 18 Jul 2026 17:27:30 +0000 Subject: [PATCH 6/8] Use clean_env for thumbnail generation Updated thumbnail generation to use a cleaned environment. --- fastflix/widgets/windows/crop_window.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/fastflix/widgets/windows/crop_window.py b/fastflix/widgets/windows/crop_window.py index c493dc63..1a6b9635 100644 --- a/fastflix/widgets/windows/crop_window.py +++ b/fastflix/widgets/windows/crop_window.py @@ -9,6 +9,7 @@ from fastflix.encoders.common import helpers from fastflix.flix import generate_thumbnail_command +from fastflix.shared import clean_env from fastflix.language import t from fastflix.shared import time_to_number from fastflix.ui_scale import scaler @@ -690,7 +691,7 @@ def generate_image(self, with_crop=False): logger.info(f"Generating crop preview: {thumb_command}") - thumb_run = run(thumb_command, shell=True, stderr=PIPE, stdout=PIPE) + thumb_run = run(thumb_command, shell=True, stderr=PIPE, stdout=PIPE, env=clean_env()) if thumb_run.returncode > 0: logger.warning(f"Could not generate crop preview: {thumb_run.stdout} |----| {thumb_run.stderr}") return From f756ba2d5d58a496708cd33fe0b6e19e328de055 Mon Sep 17 00:00:00 2001 From: anne-o-pixel <81879599+anne-o-pixel@users.noreply.github.com> Date: Sat, 18 Jul 2026 17:28:09 +0000 Subject: [PATCH 7/8] Use clean environment for thumbnail generation Updated thumbnail generation to use a cleaned environment. --- fastflix/widgets/windows/large_preview.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/fastflix/widgets/windows/large_preview.py b/fastflix/widgets/windows/large_preview.py index 14c80cce..4ad9d19b 100644 --- a/fastflix/widgets/windows/large_preview.py +++ b/fastflix/widgets/windows/large_preview.py @@ -10,6 +10,7 @@ from fastflix.flix import ( generate_thumbnail_command, ) +from fastflix.shared import clean_env from fastflix.encoders.common import helpers from fastflix.resources import get_icon from fastflix.language import t @@ -93,7 +94,7 @@ def generate_image(self): logger.info(f"Generating large thumbnail: {thumb_command}") - thumb_run = run(thumb_command, shell=True, stderr=PIPE, stdout=PIPE) + thumb_run = run(thumb_command, shell=True, stderr=PIPE, stdout=PIPE, env=clean_env()) if thumb_run.returncode > 0: logger.warning(f"Could not generate large thumbnail: {thumb_run.stdout} |----| {thumb_run.stderr}") return From 46105aca374b9a0723e9a58aa4916e0512f4afc4 Mon Sep 17 00:00:00 2001 From: anne-o-pixel <81879599+anne-o-pixel@users.noreply.github.com> Date: Sat, 18 Jul 2026 17:30:23 +0000 Subject: [PATCH 8/8] Add clean_env function to subprocess environment --- fastflix/flix.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/fastflix/flix.py b/fastflix/flix.py index 63feff89..59942341 100644 --- a/fastflix/flix.py +++ b/fastflix/flix.py @@ -16,6 +16,7 @@ from fastflix.language import t from fastflix.models.config import Config from fastflix.models.fastflix_app import FastFlixApp +from fastflix.shared import clean_env here = os.path.abspath(os.path.dirname(__file__)) re_tff = re.compile(r"TFF:\s+(\d+)") @@ -151,6 +152,7 @@ def execute(command: List, work_dir: Union[Path, str] = None, timeout: int = Non cwd=work_dir, timeout=timeout, encoding="utf-8", + env=clean_env(), ) @@ -361,6 +363,7 @@ def extract_attachment(ffmpeg: Path, source: Path, stream: int, work_dir: Path, stderr=PIPE, stdin=PIPE, cwd=work_dir, + env=clean_env(), ) try: stdout, _ = proc.communicate(timeout=3) @@ -732,6 +735,7 @@ def _detect_hdr10_plus_tool(app: FastFlixApp, config: Config, stream) -> bool: stdout=PIPE, stderr=PIPE, stdin=PIPE, # FFmpeg can try to read stdin and wrecks havoc + env=clean_env(), ) parser_version = get_hdr10_parser_version(config)