ffmpeg: How to handle color range conversions

It's hard to find comprehensive documentation about color-range manipulation with ffmpeg. I'd like to know the recommended way to deal with the following cases:

  1. Input is limited range, I want to output full range
  2. Input is full range 4:2:2, I want to output in 4:2:0 full range
  3. Input is wrongly flagged as full-range, I want to remux or re-encode in limited range

For example to solve case #2, I just add the -pix_fmt yuvj420poption. It's working but I have a warning telling me the pixel format is deprecated. I try to find a solution with -pix_fmt yuv420p -color_range 2 but the output is washed out (limited range played as full)


Input is limited range, I want to output full range

Use the scale filter, -vf scale=in_range=limited:out_range=full

and set color range for the encoder and the container*, -color_range 2,

*if writing to MP4, also add -movflags +write_colr


Input is full range 4:2:2, I want to output in 4:2:0 full range

-pix_fmt yuvj420p and same measures as above for encoder + container.


Input is wrongly flagged as full-range, I want to remux or re-encode in limited range

Re-encode is same as 1 but set the correct in_range and out_range.

To remux H264, add -bsf:v h264_metadata=video_full_range_flag=0 (with -c:v copy).

To remux H265, add -bsf:v hevc_metadata=video_full_range_flag=0 (with -c:v copy).

-color_range 1 for limited range.