To remove baked-in black bars (i.e., black borders that are part of the video frames) using FFmpeg, you can use the crop filter. Here's a step-by-step guide:
Step 1: Detect the Crop Area
Use the cropdetect filter to automatically find the optimal crop parameters. This analyzes the video and identifies the area that is not black.
ffmpeg -i input.mp4 -vf "cropdetect=64:12:0.05" -f null -v 0 -stats -y /dev/null
64: Minimum width of the black area to detect (adjust if needed).
12: Minimum height of the black area to detect (adjust if needed).
0.05: Threshold for black detection (0.05 = 5% of pixels can be black).
Output Example:
crop=1280:576:0:72
This means the video should be cropped to 1280x576 starting at x=0, y=72.
Step 2: Apply the Crop Filter
Use the detected crop values in a second FFmpeg command:
ffmpeg -i input.mp4 -vf "crop=1280:576:0:72" output.mp4
Replace 1280:576:0:72 with the values from your cropdetect output.
Alternative: Manual Crop
If you know the exact dimensions, you can skip cropdetect and directly use the crop filter. For example, to remove top/bottom bars:
ffmpeg -i input.mp4 -vf "crop=width:height:x:y" output.mp4
width/height: Dimensions of the content (e.g., 1280:576).
x/y: Starting coordinates (e.g., 0:72 for 72px top/bottom bars).
If the Video Has Side Bars
If the black bars are on the sides (left/right), adjust the crop accordingly. For example:
ffmpeg -i input.mp4 -vf "crop=1440:1080:0:0" output.mp4
This crops a 1440x1080 area from a 1920x1080 video (removing 240px from each side).
If You Want to Scale Instead
If the video has a different aspect ratio (e.g., 4:3 with 16:9 bars), you can scale to fill the screen:
ffmpeg -i input.mp4 -vf "scale=1280:720:force_original_aspect_ratio=decrease" output.mp4
force_original_aspect_ratio=decrease: Maintains the aspect ratio and scales down if needed.
- Adjust
1280:720 to your desired resolution.
Notes
- Crop vs. Scale: Cropping removes the bars but changes the aspect ratio. Scaling stretches the content, which may distort it.
- Manual Adjustment: If
cropdetect isn't precise, manually tweak the crop values based on the video's resolution and known aspect ratio.
Example: Full Workflow
- Detect crop:
ffmpeg -i input.mp4 -vf "cropdetect=64:12:0.05" -f null -v 0 -stats -y /dev/null
- Apply crop:
ffmpeg -i input.mp4 -vf "crop=1280:576:0:72" output.mp4
This will remove the black bars and retain the original content.