Skip to content

Commit 9079385

Browse files
committed
Add FFmpeg environment check in ui branch
1 parent 9c7b717 commit 9079385

1 file changed

Lines changed: 60 additions & 0 deletions

File tree

src/HwCodecDetect/run_tests.py

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import argparse
1010
import threading
1111
import tkinter as tk
12+
import tkinter.messagebox as messagebox
1213
from collections import defaultdict
1314
from .install_ffmpeg_if_needed import install_ffmpeg_if_needed
1415
from colorama import init, Fore, Style
@@ -596,6 +597,7 @@ def __init__(self, root, args):
596597
self.args = args
597598
self.stop_requested = False
598599
self.running = False
600+
self.install_log = ""
599601

600602
frame = ttk.LabelFrame(root, text="Settings")
601603
frame.pack(fill="x", padx=10, pady=10)
@@ -659,6 +661,64 @@ def start_or_stop(self):
659661
self._clear_tables()
660662

661663
def start_test(self):
664+
# 1. check FFmpeg is exists?
665+
if not shutil.which("ffmpeg"):
666+
self.prompt_install_ffmpeg()
667+
return
668+
669+
# 2. run test flow
670+
self._execute_test_flow()
671+
672+
def prompt_install_ffmpeg(self):
673+
title = "Missing Component: FFmpeg Not Found"
674+
msg = (
675+
"The application requires the FFmpeg core component to access hardware acceleration, "
676+
"but it was not detected in your system PATH.\n\n"
677+
"Would you like to attempt an automatic download and configuration?\n"
678+
"(Supports Windows, Linux, and macOS)\n\n"
679+
"If you prefer to install it manually, please visit:\n"
680+
"https://ffmpeg.org/download.html"
681+
)
682+
683+
if messagebox.askyesno(title, msg):
684+
self.start_button.config(state="disabled")
685+
self.progress["mode"] = "indeterminate"
686+
self.progress.start()
687+
688+
t = threading.Thread(target=self.run_install_thread, daemon=True)
689+
t.start()
690+
691+
def run_install_thread(self):
692+
def update_ui_after_install(success):
693+
self.progress.stop()
694+
self.progress["mode"] = "determinate"
695+
self.start_button.config(state="normal")
696+
697+
if success:
698+
messagebox.showinfo(
699+
"Installation Complete",
700+
"FFmpeg environment is now ready! You can click 'Start Test' to detect hardware codec performance."
701+
)
702+
else:
703+
messagebox.showerror(
704+
"Auto-Installation Failed",
705+
"We were unable to complete the automatic installation. This is usually caused by network timeouts or insufficient permissions.\n\n"
706+
"Suggested steps:\n"
707+
"1. Download FFmpeg manually from: https://ffmpeg.org/download.html\n"
708+
"2. Extract and add the 'bin' folder to your system environment variable (PATH)."
709+
)
710+
711+
try:
712+
result = install_ffmpeg_if_needed()
713+
if result == 0 and shutil.which("ffmpeg"):
714+
self.root.after(0, lambda: update_ui_after_install(True))
715+
else:
716+
self.root.after(0, lambda: update_ui_after_install(False))
717+
except Exception as e:
718+
print(f"Installation error: {e}")
719+
self.root.after(0, lambda: update_ui_after_install(False))
720+
721+
def _execute_test_flow(self):
662722
enc = self._safe_count(self.encoder_var, default=self.args.encoder_count)
663723
dec = self._safe_count(self.decoder_var, default=self.args.decoder_count)
664724
self.args.encoder_count = enc

0 commit comments

Comments
 (0)