LCM Logo
Graphics & Video

FFmpeg

Compress video with FFmpeg

Use ffmpeg (FFmpeg's CLI tool) to compress video files.

Best compression: "AV1":

shell
ffmpeg -i input.mp4 -c:v libaom-av1 -crf 30 -b:v 0 output.mkv

Good compression, wider support: "H.264":

shell
ffmpeg -i input.mp4 -c:v libx264 -crf 23 output.mp4

Concatenate MP4 videos

When two MP4 files use the same video and audio codecs, resolution, frame rate, and stream layout, the best approach is FFmpeg's concat demuxer. It joins the existing streams without re-encoding, so the operation is fast and does not reduce quality.

Create a text file that lists the videos in playback order, then concatenate them with stream copy:

shell
printf "file '%s'\n" first.mp4 second.mp4 > inputs.txt
ffmpeg -f concat -safe 0 -i inputs.txt -c copy output.mp4

To include every MP4 file in the current directory, use a shell glob. Files are added in filename order, so use names such as 01-intro.mp4 and 02-main.mp4 when the playback order matters:

shell
printf "file '%s'\n" *.mp4 > inputs.txt

If the inputs do not have matching formats, normalize them by re-encoding through the concat filter:

shell
ffmpeg -i first.mp4 -i second.mp4 \
  -filter_complex "[0:v:0][0:a:0][1:v:0][1:a:0]concat=n=2:v=1:a=1[v][a]" \
  -map "[v]" -map "[a]" -c:v libx264 -crf 23 -c:a aac output.mp4

The fallback assumes that both files contain one video stream and one audio stream. Inputs with different resolutions or frame rates may also need scaling or frame-rate filters before concat.

On this page