import sys import os import subprocess from pathlib import Path # --- PyInstaller & Path Handling --- if getattr(sys, 'frozen', False): # Running as a compiled PyInstaller executable EXE_DIR = Path(sys.executable).parent BUNDLE_DIR = Path(sys._MEIPASS) else: # Running as a standard Python script EXE_DIR = Path(__file__).parent BUNDLE_DIR = EXE_DIR # Locate the bundled ffmpeg.exe FFMPEG_EXE = BUNDLE_DIR / "ffmpeg.exe" # If ffmpeg.exe isn't bundled inside, fallback to system PATH if not FFMPEG_EXE.exists(): FFMPEG_EXE = "ffmpeg" # Settings TARGET_WIDTH = 1280 TARGET_HEIGHT = 720 TARGET_FPS = 24 # Process videos relative to where the executable/script resides input_folder = EXE_DIR output_folder = input_folder / "converted" output_folder.mkdir(exist_ok=True) mp4_files = list(input_folder.glob("*.mp4")) if not mp4_files: print("No MP4 files found.") input("Press Enter to exit...") sys.exit() for video in mp4_files: output_file = output_folder / video.name print(f"Converting: {video.name}") cmd = [ str(FFMPEG_EXE), # Points directly to bundled ffmpeg.exe "-y", "-i", str(video), "-vf", f"scale={TARGET_WIDTH}:{TARGET_HEIGHT}:force_original_aspect_ratio=decrease,pad={TARGET_WIDTH}:{TARGET_HEIGHT}:(ow-iw)/2:(oh-ih)/2", "-r", str(TARGET_FPS), "-c:v", "libx264", "-preset", "veryfast", "-crf", "25", "-pix_fmt", "yuv420p", "-c:a", "aac", "-b:a", "128k", str(output_file) ] result = subprocess.run(cmd) if result.returncode == 0: print(f"✓ Finished {video.name}") else: print(f"✗ Failed {video.name}") print("\nDone!") input("Press Enter to exit...")