How to Encode VP9 Video with FLAC Audio in FFmpeg

This article provides a direct guide and the exact FFmpeg commands needed to create a Matroska (MKV) file containing VP9 video and FLAC audio. You will learn how to write the command for transcoding existing media files, understand what each parameter does, and discover how to adjust quality settings for the best results.

The Standard FFmpeg Command

To transcode an input video and audio file into a VP9 video and FLAC audio stream wrapped in an MKV container, use the following command:

ffmpeg -i input.mp4 -c:v libvpx-vp9 -crf 30 -b:v 0 -c:a flac output.mkv

Parameter Breakdown

Advanced Adjustments

1. Controlling Audio Bit Depth

FLAC is lossless, but you can control its sample format (such as 16-bit or 24-bit) if your source file supports it. FFmpeg handles this automatically based on the input, but you can force 16-bit depth by adding the sample format flag:

ffmpeg -i input.mp4 -c:v libvpx-vp9 -crf 30 -b:v 0 -c:a flac -sample_fmt s16 output.mkv

2. Speed vs. Quality CPU Usage

The VP9 encoder is CPU-intensive. You can control the encoding speed using the -deadline or -cpu-used parameters.

ffmpeg -i input.mp4 -c:v libvpx-vp9 -crf 30 -b:v 0 -deadline good -cpu-used 2 -c:a flac output.mkv

3. Copying Streams Without Re-encoding (Remuxing)

If your source file already contains VP9 video and FLAC audio, you can package them into an MKV container instantly without re-encoding by copying the codecs:

ffmpeg -i input.webm -c:v copy -c:a copy output.mkv