Log in

View Full Version : --fullrange and --colormatrix


simps
5th October 2010, 11:01
source - dgmpegdec - pc-scale - mpegsource() - x264
source - dgavcdec - pc-scale - avcsource() - x264

Since I always use pc-scale in both dgmpegdec and dgavcdec, am I always feeding x264 with 0-255 material? Does pc-scale really converts it to 0-255, no matter what the source is?

If so, should I use "--fullrange on" in x264 in this scenario?



Also, for blu-ray and hddvd material, should I always use "--colormatrix bt709" ?


Thanks.

nurbs
5th October 2010, 11:45
I don't convert to fullrange, but for Blu Ray content it doesn't hurt to add the --colormatrix command. --transfer and --colorprim is also used in many Blu Ray presets, so it can't hurt using it here too. Some players will ignore it and decide depending on the resolution what to use, but others like the WDTV require it if you want correct output. Personally I'd just leave everything at TV scale since that's what is usually used so you are probably less likely to run into problems with standalone players.

simps
5th October 2010, 11:51
Aren't pc monitors and new tvs (lcd / led / plasma) all fullrange, and only old tvs (crt) limited to 16-235? Or lcd / led / plasma tvs are also limited to 16-235?

nurbs
5th October 2010, 12:37
Speaking purely from a compatibility standpoint fact is that DVDs, Blu-Rays and digital broadcasts (AFAIK) are TV range and that's what players expect. If your player doesn't respect the fullrange flag it will takes the 16-235 information and expand it to full range or directly pass it on to your TV. Either way you end up with wrong colours.
I suppose that new TVs all expand the TV range input to full range internally unless told otherwise.
With my TV (LCD) I can select the range for the separate inputs, but the player has to output the range I set on the TV or the display won't be correct. Both my player and TV default to limited range. I only use the full range on the TV when I hook my laptop up to it and that hardly ever happens.

Basically I don't see a benefit from converting it before encoding and it invites trouble on playback.

simps
5th October 2010, 13:12
Speaking purely from a compatibility standpoint fact is that DVDs, Blu-Rays and digital broadcasts (AFAIK) are TV range and that's what players expect. If your player doesn't respect the fullrange flag it will takes the 16-235 information and expand it to full range or directly pass it on to your TV. Either way you end up with wrong colours.
I suppose that new TVs all expand the TV range input to full range internally unless told otherwise.
With my TV (LCD) I can select the range for the separate inputs, but the player has to output the range I set on the TV or the display won't be correct. Both my player and TV default to limited range. I only use the full range on the TV when I hook my laptop up to it and that hardly ever happens.

Basically I don't see a benefit from converting it before encoding and it invites trouble on playback.



blu-rays are tv-range? I didn't know this... can someone else confirm if this is true?

nixo
5th October 2010, 14:56
@simps

PC/TV scale doesn't matter when frameserving with avisynth.
To quote the manual:

"This option affects conversion to RGB, which occurs in only two places in DGMPGDec: 1) in the display window of DGIndex, and 2) the video served by DGVfapi"

You're not converting to RGB and therefore not changing anything.

Edit: It would be interesting to take a full range source – I would think the Sintel png's would qualify – do a ConvertToYV12(matrix="PC.709") and encode to a BD with --fullrange in x264. I'd be curious to see if Blu-ray players would respect the flag.

--
Nikolaj

simps
5th October 2010, 16:25
nixo,

from DGindex manual

When you use DGVfapi to frame serve, the video is always converted to RGB. This option specifies how the colorspace conversion to RGB is to be performed.

■PC scale - Map output RGB to full range: YUV [16, 235(Y)/240(UV)] -> RGB [0, 255]
■TV scale - Map output RGB to clipped range: YUV [16, 235(Y)/240(UV)] -> RGB [16, 235]

From this, I understand that dgindex will give me RBG either with 0-255 or 16-236.

Are you saying that once RGB is converted to YV12 (for x264) it doesn't matter if it was 0-255 or 16-235?

I really don't think so. Maybe someone with more experience can help us here?

nixo
5th October 2010, 16:42
But you're not using DGVfapi. You're using DGdecode in Avisynth – I would hope.

--
Nikolaj

nurbs
5th October 2010, 16:44
nixo already posted the sentence following the part you quoted. This doesn't effect decoding. MPEG2Source and AVCSource will both spit out YV12 just like it was in the source video.

If the programs did output RGB and there isn't a ConvertToYV12 somewhere in your script x264 wouldn't encode it, since that's the only colorspace it currently supports. The range doesn't matter for x264. Unless you use --fullrange limited will be expected, but it's only a flag and doesn't change anything in the encoding process.

If you had RGB you'd have to do a color conversion to YV12 for x264, but you don't. Range and colormatrix don't actually matter for the encoder. As long as the decoder knows what it is, by reading the flags or doing some heuristics (e.g. HD -> Rec709), you'll get a good picture.

Manao
5th October 2010, 18:10
As a rule of thumb :
- SD content on anything but a PC : bt601 TV range.
- HD content on anything but a PC : bt709 TV range
- On a PC, do whatever you want, the odds are there will always be a player that doesn't support what you do, and another one that requires what you do.

You should always signaled properly the colormatrix/range with x264 if you plan to play it on a TV. To ensure you actually signal what you're encoding, use the colormatrix filter in avisynth. Some source filters (dgdecode for example) communicate with colormatrix so that it does the proper conversion. If colormatrix/range isn't signaled in the source, or if it is lost by the source filter, you can still force colormatrix to do the proper conversion.

simps
5th October 2010, 19:00
nixo, yes I'm using dgdecode / avisynth.

You guys are saying that MPEGSource and AVCSource will give me yv12. Ok even if it is yv12, isn't there 0-255 and 16-235 possibility in yv12? Or is it only for RGB?

Things are still not clear for me.

poisondeathray
5th October 2010, 19:07
You are just passing through levels in the same Y'CbCr (YV12) colorspace, so you don't have to specify a range (presumably you want input = output)

Whenever you do Y'CbCr<=>RGB conversions you have to specify if conversion is done full range (0-255) or limited range (16-235) ; this is where the confusions and errors usually occur . This doesn't apply in your case, unless you're converting to RGB (maybe using some vdub filters)

nurbs
5th October 2010, 19:11
Ok even if it is yv12, isn't there 0-255 and 16-235 possibility in yv12?
It will decode to the same range as the source is. Since most sources are TV scale that's what you'll most likely get.

simps
5th October 2010, 20:40
well, after reading this thread again, I think this is what I will do:

--fullrange
Not going to use it. It is just a flag, and most media players / decoders won't even pay attention to it anyway. Also, may cause compatibility issues.

--colormatrix
I will follow Manao's rule of thumb:
SD content: bt601
HD content: bt709

I hope this is the right thing for me...

Manao
6th October 2010, 05:35
It's not only a matter of proper signaling. If you use with x264 --no-fullrange --colormatrix bt709 on a content which is fullrange bt601, you won't get the proper color. The only way to get it is to convert the content to what you're going to signal.

Your content will probably already be TV range (DVD, bluray, capture ought to be TV range), but bt601/bt709 will be incorrect as soon as you switch from SD to HD or from HD to SD, or if your content isn't very well authored. In those cases, I still strongly recommend to use colormatrix filter.

hydra3333
8th October 2010, 10:59
but others like the WDTV require it if you want correct output. Uh oh, I wonder if I'm mucking my conversions up by leaving --fullrange off the commandline ? PAL land.


--colormatrix
I will follow Manao's rule of thumb:
SD content: bt601
HD content: bt709

Oh what X264 switches to use for playback with WDTV live ?

Some of my conversions are
TV capture "SD" mpeg2 720x576i -> same res in mpe4, so use --colormatrix bt601 --fullrange ?
TV capture "HD" mpeg2 1440x1080i -> same res in mpe4, so use --colormatrix bt709 --fullrange ?
TV capture "HD" mpeg2 1440x1080i -> "SD" 720x576i in mpeg4, so use --colormatrix bt709 --fullrange ?
other source (eg DV capture etc or still camera clip etc) -> "SD" 720x576i in mpeg4, so use --colormatrix bt601 --fullrange ?

my standard switches for target WDTVlive SD 720x576i are
--thread-input --threads 3 --profile high --level 4.1 --preset fast --interlaced --tff --no-cabac --bitrate 3000 --sar 16:11

my standard switches for target WDTVlive HD 1440x576i are
--thread-input --threads 3 --profile high --level 4.1 --preset fast --interlaced --tff --no-cabac --bitrate 8000 --sar 4:3

nm
8th October 2010, 11:06
Uh oh, I wonder if I'm mucking my conversions up by leaving --fullrange off the commandline ? PAL land.

Nope. Only use "--fullrange on" if you have full range content, which is rare. Just set colormatrix and you should be fine.

hydra3333
8th October 2010, 11:08
OK thanks. what about the HD->SD colormatrix (which one to select) ?

nm
8th October 2010, 11:10
OK thanks. what about the HD->SD colormatrix ?

You might want to convert to bt601 with AviSynth so that players that use the frame size to determine the color standard will get it right. I don't know what WDTV does in this case.

simps
8th October 2010, 11:35
I made this test today.
I encoded 2 videos, with exactly the same settings, but one with --fullrange on.
The video was a trimmed blu-ray movie, and as you guys are saying, blu-ray should be limited range.

There is absolutly no difference between the 2 encoded files during playback.
The one with fullrage flag, and the other without the fullrange flag, have identical luma and croma during playback.
I didn't test it with a tv system, just on my computer, with several media players. MPC, WMP, VLC, ZOOM, etc... I think all of them are ignoring the fullrange flag.

I might upload the videos for you guys too.

hydra3333
8th October 2010, 11:39
You might want to convert to bt601 with AviSynth so that players that use the frame size to determine the color standard will get it right. OK, I'll have to look up how to do that conversion now. And double-check Aus "HD" is in fact broadcast as bt709 as you never know what our dyslexic tv broadcasters are likely to do.

edit:

? maybe use
BT709ToBT601
or more up to date tcritical's
ColorMatrix(clip, interlaced=true, mode="Rec.709->Rec.601")

Yes, DGindex reports BT709 and BT709* for the 1440x1080i TV capture material from all Aus "HD" channels which I guess is close enough.

nm
8th October 2010, 11:56
or more up to date tcritical's
ColorMatrix(clip, interlaced=true, mode="Rec.709->Rec.601")

Yep, I'd use that.

hydra3333
9th October 2010, 07:45
OK so my avisynth for PAL tv capture "HD" -> "SD" should now include
ColorMatrix(interlaced=true,mode="Rec.709->Rec.601")

and my x264 commandline for WDTVlive compatible "SD" .mp4 is
--thread-input --threads 3 --profile high --level 4.1 --preset fast --interlaced --tff --no-cabac --bitrate 3000 --sar 16:11 --colormatrix bt601

and my x264 commandline for target WDTVlive HD 1440x576i becomes (with nothing additional in the avisynth)
--thread-input --threads 3 --profile high --level 4.1 --preset fast --interlaced --tff --no-cabac --bitrate 8000 --sar 4:3 --colormatrix bt709

Just checking, using DG's NV tools to deinterlace/resize a clip which I then reinterlace - it doesn't alter the bt709 in itself I hope.

hydra3333
14th October 2010, 13:17
Well, I've misinterpreted something.

PAL space. I'd thought there was a "--colormatrix bt601" option ... is there supposed to be one ? (V1732 32 bit xp-sp3 from http://x264.nl/ tells me no such option)

Open to ideas.

kemuri-_9
14th October 2010, 13:32
look at table E-3 (Colour Primaries) in the H.264 spec:

bt470bg = bt601 625 = bt1358 625 = bt1700 625 (PAL/SECAM)
smpte170m = bt601 525 = bt1358 525 = bt1700 NTSC

(yes, PAL and NTSC have different bt601 matrices here)

Selur
14th October 2010, 13:33
yup there's only:
--colormatrix <string> Specify color matrix setting ["undef"]
- undef, bt709, fcc, bt470bg
smpte170m, smpte240m, GBR, YCgCo
-> bt470bg should be the right one,... (see: kemuri-_9s post)

hydra3333
14th October 2010, 15:54
look at table E-3 (Colour Primaries) in the H.264 spec:
bt470bg = bt601 625 = bt1358 625 = bt1700 625 (PAL/SECAM)
smpte170m = bt601 525 = bt1358 525 = bt1700 NTSC
(yes, PAL and NTSC have different bt601 matrices here)
Thanks. bt470bg it is. So bt601 isn't really "fixed" then since it depends on PAL or NTSC source :) That's amazing.

I wonder what tcritical's avisynth plugin ColorMatrix(clip, interlaced=true, mode="Rec.709->Rec.601") does ?

Manao
14th October 2010, 18:51
look at table E-3 (Colour Primaries) in the H.264 spec:Actually, it's not color_primaries that control the RGB<->YUV conversion, but matrix_coefficients. And the coefficients for bt470 and smpte170m are the same. So avisynth's colormatrix doesn't need to now if it's SD PAL or SD NTSC, since the matrix is the same.

x264's --colormatrix should make the distinction between bt470bg and smpte170m. However, if you use the incorrect one, I don't know what will happen (the RGB values will be correct, and I don't know whose job it is to interpret color_matrix and transfer_characteristics, and it's more than likely that the information is lost anyway).

kemuri-_9
14th October 2010, 23:54
Yes, i mistakenly looked at color primaries (Table E-3) instead of matrix coefficients (Table E-5) from the spec.

As Manao pointed out, the matrix coefficients for the two types are equivalent, though they are different for color primaries.

the VUI color-based parameters are a mess IMO though.
If people in charge were actually thinking straight, then such things like the following wouldn't exist:

for color primaries, smpte170m and smpte240m are equivalent.
for transfer characteristics, bt709 and smpte170m are equivalent.
for color matrices, bt470bg and smpte170m are equivalent.

while the values are different otherwise.

Lyris
16th October 2010, 04:31
blu-rays are tv-range? I didn't know this... can someone else confirm if this is true?

Yes. Regardless of the format, all Video stuff uses Video levels.

vmrsss
21st October 2010, 19:22
thanks for this thread, it is useful.

so, if i have an HD source (and thus supposedly in bt709) which i encode to a SD resolution (by scaling it down say with x264's own swscale), should I add --colormatrix bt709 to declare the "right" colormatrix (because it is not the one a player would expect in a SD media)?

nurbs
21st October 2010, 19:33
Either that or you use Colormatrix() to convert it to bt601 and add the appropriate tag. The latter might be more compatible since there are players that will ignore the tag and decide based on resolution.