13

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<->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 <string>    Specify color primaries ["undef"]
                              - undef, bt709, bt470m, bt470bg, smpte170m,
                                smpte240m, film, bt2020
  --transfer <string>     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 <string>  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?

2
  • I have the exact same problem. Did you figure out the command line to use to get h264 HD footage tagged with BT.601?
    – Casper
    Aug 4, 2016 at 14:13
  • @Casper: yes, I accepted Mulvya's answer because it was plenty of info to look up the right options. I made an edit to include the right options explicitly (e.g. NTSC is -color_primaries smpte170m -color_trc smpte170m -colorspace smpte170m). Aug 4, 2016 at 15:15

1 Answer 1

15

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 & 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.

2
  • Ah of course. I was even looking at the bt601 wikipedia page, and didn't clue in from the table having two rows. Derp. Nov 8, 2015 at 5:51
  • 1
    For those looking to do this same setting with HandBrake, under the Video tab, inside the Extra Options edit box, enter this string: "colorprim=smpte170m:transfer=smpte170m:colormatrix=smpte170m"
    – pcunite
    Feb 17, 2018 at 2:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.