diff --git a/StreamingCommunity/Lib/FFmpeg/command.py b/StreamingCommunity/Lib/FFmpeg/command.py index 4c3c996..951934a 100644 --- a/StreamingCommunity/Lib/FFmpeg/command.py +++ b/StreamingCommunity/Lib/FFmpeg/command.py @@ -12,7 +12,7 @@ from rich.console import Console # Internal utilities from StreamingCommunity.Util._jsonConfig import config_manager -from StreamingCommunity.Util.os import os_manager, os_summary, suppress_output +from StreamingCommunity.Util.os import os_manager, suppress_output, get_ffmpeg_path # Logic class @@ -34,7 +34,6 @@ FFMPEG_DEFAULT_PRESET = config_manager.get("M3U8_CONVERSION", "default_preset") # Variable USE_LARGE_BAR = not ("android" in sys.platform or "ios" in sys.platform) -FFMPEG_PATH = os_summary.ffmpeg_path console = Console() @@ -48,7 +47,7 @@ def check_subtitle_encoders() -> Tuple[Optional[bool], Optional[bool]]: """ try: result = subprocess.run( - [FFMPEG_PATH, '-encoders'], + [get_ffmpeg_path(), '-encoders'], capture_output=True, text=True, check=True @@ -102,7 +101,7 @@ def join_video(video_path: str, out_path: str, codec: M3U8_Codec = None): - out_path (str): The path to save the output file. - codec (M3U8_Codec): The video codec to use. Defaults to 'copy'. """ - ffmpeg_cmd = [FFMPEG_PATH] + ffmpeg_cmd = [get_ffmpeg_path()] # Enabled the use of gpu if USE_GPU: @@ -185,7 +184,7 @@ def join_audios(video_path: str, audio_tracks: List[Dict[str, str]], out_path: s video_audio_same_duration = check_duration_v_a(video_path, audio_tracks[0].get('path')) # Start command with locate ffmpeg - ffmpeg_cmd = [FFMPEG_PATH] + ffmpeg_cmd = [get_ffmpeg_path()] # Enabled the use of gpu if USE_GPU: @@ -278,7 +277,7 @@ def join_subtitle(video_path: str, subtitles_list: List[Dict[str, str]], out_pat Each dictionary should contain the 'path' key with the path to the subtitle file and the 'name' key with the name of the subtitle. - out_path (str): The path to save the output file. """ - ffmpeg_cmd = [FFMPEG_PATH, "-i", video_path] + ffmpeg_cmd = [get_ffmpeg_path(), "-i", video_path] # Add subtitle input files first for subtitle in subtitles_list: diff --git a/StreamingCommunity/Lib/FFmpeg/util.py b/StreamingCommunity/Lib/FFmpeg/util.py index 6241028..df28173 100644 --- a/StreamingCommunity/Lib/FFmpeg/util.py +++ b/StreamingCommunity/Lib/FFmpeg/util.py @@ -13,11 +13,10 @@ from rich.console import Console # Internal utilities -from StreamingCommunity.Util.os import os_summary +from StreamingCommunity.Util.os import get_ffprobe_path # Variable -FFPROB_PATH = os_summary.ffprobe_path console = Console() @@ -32,7 +31,7 @@ def has_audio_stream(video_path: str) -> bool: has_audio (bool): True if the input video has an audio stream, False otherwise. """ try: - ffprobe_cmd = [FFPROB_PATH, '-v', 'error', '-print_format', 'json', '-select_streams', 'a', '-show_streams', video_path] + ffprobe_cmd = [get_ffprobe_path(), '-v', 'error', '-print_format', 'json', '-select_streams', 'a', '-show_streams', video_path] logging.info(f"FFmpeg command: {ffprobe_cmd}") with subprocess.Popen(ffprobe_cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True) as proc: @@ -60,7 +59,7 @@ def get_video_duration(file_path: str) -> float: """ try: - ffprobe_cmd = [FFPROB_PATH, '-v', 'error', '-show_format', '-print_format', 'json', file_path] + ffprobe_cmd = [get_ffprobe_path(), '-v', 'error', '-show_format', '-print_format', 'json', file_path] logging.info(f"FFmpeg command: {ffprobe_cmd}") # Use a with statement to ensure the subprocess is cleaned up properly @@ -144,7 +143,7 @@ def get_ffprobe_info(file_path): """ try: result = subprocess.run( - [FFPROB_PATH, '-v', 'error', '-show_format', '-show_streams', '-print_format', 'json', file_path], + [get_ffprobe_path(), '-v', 'error', '-show_format', '-show_streams', '-print_format', 'json', file_path], stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True, check=True ) output = result.stdout diff --git a/StreamingCommunity/Util/os.py b/StreamingCommunity/Util/os.py index ce91c3c..2c63dc0 100644 --- a/StreamingCommunity/Util/os.py +++ b/StreamingCommunity/Util/os.py @@ -506,4 +506,12 @@ def compute_sha1_hash(input_string: str) -> str: hashed_string = hashlib.sha1(input_string.encode()).hexdigest() # Return the hashed string - return hashed_string \ No newline at end of file + return hashed_string + +def get_ffmpeg_path(): + """Returns the path of FFmpeg.""" + return os_summary.ffmpeg_path + +def get_ffprobe_path(): + """Returns the path of FFprobe.""" + return os_summary.ffprobe_path \ No newline at end of file