3

Did I get this right? In 4:2:0 the left half of the 4x2 rectangle has the same chroma anyway so it does not matter which chroma_location subsampling type is used?

ffmpeg7 seems to default to chroma_location=topleft i.e. Chroma Subsampling Type 2 with PAL .dv input:

0 left, 1 center, 2 topleft, 3 top, 4 bottomleft, 5 bottom, auto gives 2 with .dv input, blank unspecified.

On the other hand, with 4:1:1 input: isn't chroma_location topleft the same as top but other chroma_locations sample different chroma or pick a mean of two chromas, right?

PAL .dv seems to be 4:2:0 and NTSC .dv 4:1:1.

https://en.wikipedia.org/wiki/Chroma_subsampling

https://www.researchgate.net/figure/Figure-E2-Location-of-the-top-left-chroma-sample-when-chroma-format-idc-is-equal-to-1_fig1_327253648

For example, I have used the following command to convert 4:3 PAL .dv to .mp4. Setting chroma_location to any variation does not seem to make any difference.

It seems ffmpeg auto-detects chroma_location in input anyway so the user only needs to intervene if it happens to be incorrect? And in PAL 4:2:0 input and in .mp4 4:2:0 output it does not matter anyway? So maybe I can omit chroma_location from the commands below at least for PAL:

ffmpeg7 -i 4_3_PAL.dv -vf bwdif=1,scale=788:576,crop=768:576:10:0,setsar=sar=1/1,setparams=range=limited:color_primaries=bt470bg:color_trc=bt709:colorspace=smpte170m:chroma_location=topleft -c:v libx265 -crf 18 -preset slow -pix_fmt yuv420p10le -profile:v main10 -timecode 00:00:00:00 -tag:v hvc1 -c:a aac -b:a 128k 4_3_PAL_dv_to_10bit_limited_5-1-6.mp4

Which among all yields deeper reds than the default with untagged colors:

Chroma subsampling                       : 4:2:0 (Type 2)
Bit depth                                : 10 bits
Color range                              : Limited
Color primaries                          : BT.601 PAL
Transfer characteristics                 : BT.709
Matrix coefficients                      : BT.601

A similar command for 4:3 NTSC .dv where chroma_location in the 4:1:1 .dv might matter?

ffmpeg7 -i 4_3_NTSC.dv -vf bwdif=1,scale=648:480,crop=640:480:4:0,setsar=sar=1/1,setparams=range=limited:color_primaries=smpte170m:color_trc=bt709:colorspace=smpte170m:chroma_location=topleft -c:v libx265 -crf 18 -preset slow -pix_fmt yuv420p10le -profile:v main10 -timecode '00:00:00;00' -tag:v hvc1 -c:a aac -b:a 128k 4_3_NTSC_dv_to_10bit_limited_6-1-6.mp4

ffmpeg4 does not seem to support setting chroma_location at least like this.

Years ago I used a similar command for PAL .dv but then to 8-bit without color attributes and range (which defaulted to limited). I considered re-encoding but it seems just adding color might losslessly work without re-encoding with a command below? (hvc1 and timecode can also be added, but of course 8-bit must be re-encoded to 10-bit). Also setting range to full/limited seems to work later but I am not sure if that really works:

ffmpeg -i input.mp4 -c copy -color_range 1 -color_primaries:v bt470bg -color_trc:v bt709 -colorspace:v smpte170m -timecode 00:00:00:00 -tag:v hvc1 output.mp4
wywh
  • 66

1 Answers1

0

Chroma sample position generally matters, because during upscaling and downscaling, the scaler needs to know which location to scale to and from. That is, unless nearest-neighbor scaling (point sampling) is used. The available sample positions only move across the full mentioned 4x2 field for 4:1:0 (quarter horizontal and half vertical resolution) chroma subsampling, a 2x2 pixel window for the usual 4:2:0 (half horizontal, half vertical) subsampling, and a 2x1 pixel window for 4:2:2.

scale uses bicubic by default for scaling, which includes chroma scaling, zscale uses bilinear by default.

FFmpeg can indeed read the source tags from sources just fine, normally, and also carries the tag to the encoder.

damian101
  • 103