Automation Lab
•
2024-03-05
Bulk Video Compressor for Social Media
Estimated Time
8 MIN
Environment
Python 3.x, FFmpeg
Preparation
Step 1 Install Tools
You need FFmpeg installed on your system to handle the video processing.
- Windows:
choco install ffmpeg - Mac:
brew install ffmpeg
02
Step 2 Implementation
The Python Script
Save this as compress.py and run it in a folder containing your videos.
import subprocess
import os
def compress_video(input_path, output_path):
cmd = [
'ffmpeg', '-i', input_path,
'-vcodec', 'libx264', '-crf', '28',
output_path
]
subprocess.run(cmd)
folder = './input_videos'
for filename in os.listdir(folder):
if filename.endswith(".mp4"):
print(f"Compressing {filename}...")
compress_video(os.path.join(folder, filename), os.path.join('./output', filename))
Why these settings?
This script uses the libx264 codec and a CRF (Constant Rate Factor) value of 28, which is the "sweet spot" for mobile viewing—small size, great quality.
Download Full Automation Pack
Get all source codes, advanced configurations, and exclusive troubleshooting guides.
FREE DOWNLOADSecure Verification Required