Configure MJPEG Encoder Quality in FFmpeg

This article explains how to configure the quality parameters for the Motion JPEG (MJPEG) encoder in FFmpeg. You will learn which command-line options to use, understand the specific scale used to determine image quality, and see practical examples of how to apply these settings to your video conversions.

The Quality Parameter: -q:v

To control the quality of the MJPEG encoder in FFmpeg, you use the -q:v option (which is an alias for -qscale:v). Because MJPEG is an intra-frame-only format where every frame is compressed as an individual JPEG image, traditional bitrate controls (like -b:v) are less effective than direct quality scale mapping.

The value you pass to -q:v uses a scale from 1 to 31:

Practical Examples

To apply the quality setting, insert the -q:v flag immediately after specifying the MJPEG codec (-c:v mjpeg or -vcodec mjpeg).

To convert a video to MJPEG with high visual quality, use a low scale value such as 2 or 3:

ffmpeg -i input.mp4 -c:v mjpeg -q:v 3 output.mov

Maximum Quality (Visually Lossless)

If you require the absolute highest quality and file size is not a concern, set the parameter to 1:

ffmpeg -i input.mp4 -c:v mjpeg -q:v 1 output.mov

Low Quality (Small File Size)

For drafts, testing, or situations where disk space is extremely limited, you can lower the quality by choosing a higher value like 20:

ffmpeg -i input.mp4 -c:v mjpeg -q:v 20 output.mov

Extracting JPEG Image Sequences

Because the MJPEG encoder behaves identically to the single-image JPEG encoder, you can use the exact same -q:v option when exporting a video to a sequence of individual .jpg images:

ffmpeg -i input.mp4 -q:v 2 frame_%04d.jpg

In this command, each extracted frame will be saved as a JPEG image compressed at a high-quality level of 2.