ffmpeg: explicitly tag h.264 as bt.601, rather than leaving unspecified? I want to tag video as explicitly bt.601, rather than "unspecified".  I know players typically choose bt.601 as the default for videos less than 1280 pixels wide, but I want to make it explicit that bt.601 is the correct colour matrix for a video.

The sticking point is that there is no bt601 option for ffmpeg or libx264, only bt709 and some others.

I have some videos that were downscaled from HD, and are still in bt.709, but aren't tagged properly.  So when I watch a video, I sometimes have to manually toggle my player to bt.709.  Tagging explicitly as bt.601 will communicate to future viewers (e.g. myself) that it's definitely bt.601, and not a mis-tagged bt.709 video, when I look at it with mediainfo.

Another use-case for this would be if you upscaled a bt.601 video to 1280 or higher without doing a colormatrix conversion (using -vf colormatrix), players would incorrectly assume bt.709 if you left the color information unspecified.

FFMpeg's colormatrix video filter does support bt601 as an input or output color matrix, but doesn't also set tags.  (Since it doesn't have the side-effect of setting ffmpeg's color options, it refuses to even operate with src and dest the same, like -vf colormatrix=bt601:bt601.)



ffmpg in  -color_primaries bt709 -color_trc bt709 -colorspace bt709  out


will tag the output video as using bt.709 for yuv&lt;->rgb.  The tags end up inside the video bitstream itself, not just in the container (since this is seems to be a codec-specific thing, not a container thing, for mp4 and mkv containers at least).

e.g. mediainfo output:

Complete name             : out.mkv
...
Writing application                      : Lavf57.14.100
Writing library                          : Lavf57.14.100


Video
ID                                       : 1
Format                                   : AVC
...
Writing library                          : x264 core 148 r2638+4 afcf21c
Encoding settings                        : cabac=1 / ref=8 / ...
Language                                 : English
Default                                  : Yes
Forced                                   : No
Color primaries                          : BT.709
Transfer characteristics                 : BT.709
Matrix coefficients                      : BT.709




So bt.709 is easy to tag.  The problem is, I don't see bt.601 anywhere.  Is one of other names an alias for it, or is there really no way to specify it explicitly?

x264 --fullhelp output:

  --colorprim &lt;string&gt;    Specify color primaries ["undef"]
                              - undef, bt709, bt470m, bt470bg, smpte170m,
                                smpte240m, film, bt2020
  --transfer &lt;string&gt;     Specify transfer characteristics ["undef"]
                              - undef, bt709, bt470m, bt470bg, smpte170m,
                                smpte240m, linear, log100, log316,
                                iec61966-2-4, bt1361e, iec61966-2-1,
                                bt2020-10, bt2020-12
  --colormatrix &lt;string&gt;  Specify color matrix setting ["???"]
                              - undef, bt709, fcc, bt470bg, smpte170m,
                                smpte240m, GBR, YCgCo, bt2020nc, bt2020c


ffmpeg -h full  shows the same set of options for its color options, which ffmpeg's -c:v libx264 video codec passes on to x264.  Is any of these an alias for bt.601, or have a numerically equivalent colour matrix?
PAL and NTSC have different color primaries, so 

NTSC = SMPTE 170M = BT 601 525

PAL = BT 470 BG = BT 601 625

See the rows for value 5 &amp; 6 on the table on page 387 of the active H.264 standard.



So the right args for ffmpeg are:

NTSC:

# NTSC
ffmpeg -i input  \
 -colorspace smpte170m -color_primaries smpte170m -color_trc smpte170m

mediainfo:
Color primaries                          : BT.601 NTSC
Transfer characteristics                 : BT.601
Matrix coefficients                      : BT.601


PAL:

-color_trc doesn't accept bt470bg, but ffmpeg -h full shows that gamma28 means "BT.470 BG" for that option.

# PAL
ffmpeg -i input  \
 -colorspace bt470bg -color_primaries bt470bg -color_trc gamma28

mediainfo:
Color primaries                          : BT.601 PAL
Transfer characteristics                 : BT.470 System B, BT.470 System G
Matrix coefficients                      : BT.601


-colorspace is the most important option; the others don't make a visible difference for software players like mpv on Linux.