Skip to content

Make and validate a first FFmpeg video encode

needs review

This workflow creates a short test in Matroska. It maps the first video stream, optionally maps audio, encodes video with x264, and encodes audio with Opus. Your FFmpeg build must include libx264 and libopus.

Terminal window
ffprobe -v error -show_format -show_streams -of json input.mkv
ffmpeg -hide_banner -h encoder=libx264
ffmpeg -hide_banner -h encoder=libopus

Confirm the source stream indexes, frame rate, pixel format, resolution, color metadata, audio layout, and subtitles before encoding.

Terminal window
ffmpeg -ss 00:05:00 -i input.mkv -t 30 \
-map 0:v:0 -map '0:a?' \
-c:v libx264 -preset slow -crf 20 -pix_fmt yuv420p \
-c:a libopus -b:a 128k \
sample.mkv

-map makes stream selection explicit. The ? makes the audio mapping optional. -crf controls the x264 quality/size tradeoff, while -preset controls its speed/compression tradeoff. The yuv420p pixel format is a compatibility choice and may be wrong for high-bit-depth or HDR sources.

Terminal window
ffmpeg -v error -i sample.mkv -f null -
ffprobe -v error -show_format -show_streams -of json sample.mkv

The decode check should print no errors. Confirm the expected stream count, codecs, duration, resolution, pixel format, and color fields. Finally watch the whole sample on a target player and seek through it.