VideoConvert.py
· 1.1 KiB · Python
Raw
import subprocess
from pathlib import Path
# Settings
TARGET_WIDTH = 1280
TARGET_HEIGHT = 720
TARGET_FPS = 24
input_folder = Path(__file__).parent
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...")
quit()
for video in mp4_files:
output_file = output_folder / video.name
print(f"Converting: {video.name}")
cmd = [
"ffmpeg",
"-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...")
| 1 | import subprocess |
| 2 | from pathlib import Path |
| 3 | |
| 4 | # Settings |
| 5 | TARGET_WIDTH = 1280 |
| 6 | TARGET_HEIGHT = 720 |
| 7 | TARGET_FPS = 24 |
| 8 | |
| 9 | input_folder = Path(__file__).parent |
| 10 | output_folder = input_folder / "converted" |
| 11 | output_folder.mkdir(exist_ok=True) |
| 12 | |
| 13 | mp4_files = list(input_folder.glob("*.mp4")) |
| 14 | |
| 15 | if not mp4_files: |
| 16 | print("No MP4 files found.") |
| 17 | input("Press Enter to exit...") |
| 18 | quit() |
| 19 | |
| 20 | for 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 | |
| 48 | print("\nDone!") |
| 49 | input("Press Enter to exit...") |