RGB Encoding
Table of contents
You do not have to encode into Y’CbCr, there are a number of codecs that support RGB directly.
It does lower the compression efficiency a little, but eliminates any concern that the Y’CbCr conversion is affecting the imagery.
| Codec Family | ffmpeg codec | Bit depth | pix_fmt | Web Support |
|---|---|---|---|---|
| H.264 | libx264rgb | 8 | rgb | no |
| HEVC/H265 | libx265 | 8 10 12 | rgb rgb-10 rgb-12 | All browsers |
| HEVC/H265 | hevc_videotoolbox | 8 10 | rgb rgb-10 rgb-12 | All browsers |
| VP9 | libvpx-vp9 | 8 10 12 | rgb rgb-10 rgb-12 | All Browsers |
| Mjpeg | mjpeg | 8 | yuv-4:2:2 yuv-4:4:4 (no RGB, see below) | no |
| DNxHD | dnxhd | 8 10 | rgb | no |
| HTJ2K | 8 -> 16 | rgb | no |
H.264 RGB Encoding
H.264 does support RGB encoding, which may be preferable in some situations.
Using the encoder:
-c:v libx264rgb
Has no support in web browsers, but there is limited support in players such as RV.
The x264 library can encode RGB, but FFmpeg only offers it through the separate libx264rgb encoder (bgr0, bgr24 or rgb24 in, stored as gbrp). -c:v libx264 has no RGB pixel formats: asking it for -pix_fmt rgb24 or gbrp does not fail, it logs “Incompatible pixel format … auto-selecting format ‘yuv444p’” and writes Y’CbCr 4:4:4 instead. Tested on FFmpeg 6.1.6, 7.1.5, 8.1, 9.0.2 and a 9.1 development build.
mjpeg RGB Encoding
FFmpeg’s mjpeg encoder cannot store RGB. Asking for -pix_fmt rgb24 gives a file in full range BT.601 Y’CbCr 4:4:4 (yuvj444p), tagged as such, whatever -colorspace says (FFmpeg 6.1.6 and 9.0.2). It decodes back to RGB correctly, but it is not an RGB encode, and it is 8-bit only. For details see: Mjpeg.
VP9 RGB Encoding
VP9 has some excellent 10 and 12 bit RGB encodes.
Example encoding:
ffmpeg -r 24 -start_number 1 -i inputfile.%04d.png -frames:v 200 -c:v libvpx-vp9 \
-crf 22 -pix_fmt gbrp10le -quality good -row-mt 1 -speed 2 \
-vf "zscale=range=full,format=gbrp10le,setparams=color_primaries=bt709:color_trc=bt709" \
-color_primaries bt709 -color_range pc -color_trc bt709 -colorspace rgb \
-y outputfile.mp4
RGB Comparisons
These are the settings behind the graphs below, kept as a record of that comparison. Do not copy them: from FFmpeg 7.1 -color_primaries and -color_trc are ignored, so the files have no primaries or transfer (measured with the same flags and filter on libx265 gbrp10le: tagged on 6.1.6 and 7.0, untagged on 7.1.5, 8.1, 9.0.2 and a 9.1 development build). Set them with setparams, as in the VP9 example.
| label | Codec Params |
|---|---|
| 8_bit_libx264rgb | -c:v libx264rgb -color_primaries bt709 -color_range pc -color_trc bt709 -colorspace rgb -crf 18 -pix_fmt rgb24 -preset slow -vf “scale=in_range=full:out_range=full” -x264-params keyint=15:no-deblock=1 |
| 8bit_mjpeg | -c:v mjpeg -color_primaries bt709 -color_range pc -color_trc bt709 -colorspace rgb -pix_fmt rgb24 -q:v 2 -vf “scale=in_range=full:out_range=full” |
| vp9_10bit_rgb | -c:v libvpx-vp9 -color_primaries bt709 -color_range pc -color_trc bt709 -colorspace rgb -crf 22 -pix_fmt gbrp10le -quality good -row-mt 1 -speed 2 -vf “scale=in_range=full:out_range=full” |
| vp9_12bit_rgb | -c:v libvpx-vp9 -color_primaries bt709 -color_range pc -color_trc bt709 -colorspace rgb -crf 22 -pix_fmt gbrp12le -quality good -row-mt 1 -speed 2 -vf “scale=in_range=full:out_range=full” |
| vp9_8bit_rgb | -c:v libvpx-vp9 -color_primaries bt709 -color_range pc -color_trc bt709 -colorspace rgb -crf 22 -pix_fmt gbrp -quality good -vf “scale=in_range=full:out_range=full” |
![]() |
| This is showing different rgb encoding against file size. |
![]() |
| This is showing different rgb encoding against encoding time |
![]() |
| This is showing different rgb encoding against mean VMAF |
For more details see:


