Last active 1 month ago

Revision 83d1d3e93ae2ca77f3986cc231e132a3e3196cf1

VideoConvert.py Raw
1import subprocess
2from pathlib import Path
3
4# Settings
5TARGET_WIDTH = 1280
6TARGET_HEIGHT = 720
7TARGET_FPS = 24
8
9input_folder = Path(__file__).parent
10output_folder = input_folder / "converted"
11output_folder.mkdir(exist_ok=True)
12
13mp4_files = list(input_folder.glob("*.mp4"))
14
15if not mp4_files:
16 print("No MP4 files found.")
17 input("Press Enter to exit...")
18 quit()
19
20for video in mp4_files:
21 output_file = output_folder / video.name
22
23 print(f"Converting: {video.name}")
24
25 cmd = [
26 "ffmpeg",
27 "-y",
28 "-i", str(video),
29 "-vf",
30 f"scale={TARGET_WIDTH}:{TARGET_HEIGHT}:force_original_aspect_ratio=decrease,pad={TARGET_WIDTH}:{TARGET_HEIGHT}:(ow-iw)/2:(oh-ih)/2",
31 "-r", str(TARGET_FPS),
32 "-c:v", "libx264",
33 "-preset", "veryfast",
34 "-crf", "25",
35 "-pix_fmt", "yuv420p",
36 "-c:a", "aac",
37 "-b:a", "128k",
38 str(output_file)
39 ]
40
41 result = subprocess.run(cmd)
42
43 if result.returncode == 0:
44 print(f"✓ Finished {video.name}")
45 else:
46 print(f"✗ Failed {video.name}")
47
48print("\nDone!")
49input("Press Enter to exit...")