12

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)

3
  • For 3, which codec?
    – Gyan
    Feb 13, 2019 at 11:44
  • h264. Does it matter? are those informations part of the bistream and specific to each codecs? Feb 13, 2019 at 12:30
  • 4
    Colorimetry can be stored within the bitstream as well as the container. Tools to modify bitstream data without re-encoding only exist for some codecs. H264 is one of them.
    – Gyan
    Feb 13, 2019 at 12:31

1 Answer 1

11

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.

10
  • Thanks! A few minor corrections and typo in your answer: #1 -vf scale=in_range=limited:out_range=full _ instead of : #2 Using yuv420p is also working when adding -color_range 2 and -movflags +write_colr this way ffmpeg does not output a depreciation warning #3 if input is limited range flagged as full range, then -bsf:v h264_metadata=video_full_range_flag=0 must be used. Feb 14, 2019 at 14:36
  • Using yuv420p is also working --> not here. The color_range does affect encoder behaviour but not the actual range.
    – Gyan
    Feb 14, 2019 at 15:03
  • well, it worked with ffmpeg -i input.mov -vf scale=in_range=limited:out_range=full -color_range 2 -pix_fmt yuv420p -c:v libx264 -crf 20 -movflags +write_colr -movflags +faststart out.mp4 Does yuv420p impose a limited range? if so, what should be used if yuvj420p is deprecated? Feb 14, 2019 at 15:22
  • See the signalstats filer to identify the high and low values.
    – Gyan
    Feb 14, 2019 at 15:35
  • well if I test the file encoded with yuv420p I get YMIN=0 and YMAX=255 Feb 14, 2019 at 15:42

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .