Log in

View Full Version : x264 change in luminance from source


nhope
10th April 2008, 11:49
I'm making x264 MP4 videos from HDV source to embed in Flash Players.

I'm frameserving from Sony Vegas Pro 8 with Debugmode Frameserver, running through AviSynth, and encoding in MeGUI.

My AviSynth script looks like this (I'm halving the height of the videos to 540 lines, hence the blunt deinterlace method):

AviSource("d:\fs.avi")
SeparateFields()
SelectEven()
ConvertToYV12()
LanczosResize(960,540)

In MeGUI I'm using the CE-QuickTime profile but with the bitrate raised to 1500 kbps. I'm using this profile because I want to provide download links for my mp4 files and I don't want Quicktime to choke on them.

However I'm noticing a change in luminance in the resulting mp4 file compared to the original footage. It's generally paler than the originals when viewed in VLC Player or Quicktime or similar, whereas Xvid (done in VirtualDub) for example stays almost exactly the same.

I suspected that I needed to add a levels filter to my AviSynth script so I added this line:

ColorYUV(levels="TV->PC")

which apparently does the same as this line:

Levels(16, 1, 235, 0, 255, coring=false)

But the result is still generally more pale than the original footage.

I then tried x264 in an AVI wrapper done at default x264 settings in VirtualDub and the result of that is identical in luminance to the original. I could do it that way and put the AVIs in MP4 wrappers but I would rather use the up-to-date method, not x264VfW.

Another strange thing is that when the "pale" x264 video is played back in a Flash Player online it seems darker and more faithful to the original. The Flash 9 Player uses a MainConcept decoder doesn't it?

Can anyone explain what's happening? At which stage of the workflow is the luminance getting changed? How might I fix this short of just tweaking the levels in AviSynth?

Thanks!

check
11th April 2008, 12:36
x264 doesn't change the luminance of encodes, you should look elsewhere for your problems. Since the same video looks different in different players I'd say your playback renderer (more likely) or decoder is broken.

PlazzTT
11th April 2008, 19:14
I had this problem too. Turned out to be the renderer I was using in Media Player Classic.

Overlay Renderer looks okay for me now.

nhope
4th September 2009, 17:11
I have finally, after much digging, worked out what has been causing the loss of contrast/luminosity when I encode H.264 using x264 in MeGui.

The RGB to YV12 conversion using "ConvertToYV12()" in the AviSynth script actually scales the luma to the TV range [16,235], cutting off the blacks and whites. To maintain the full range [0,255] luma you need to add matrix="pc.601". My AviSynth script typically now looks like this:

AviSource("d:\fs.avi")
ConvertToYV12(matrix="PC.601")
TDeint(order=1)
LanczosResize(640,480)

Apparently PC.709 can also be used. I'm out of my depth with the specifics here so if anyone can shed light on the differences between Rec601, Rec604, Rec709 etc. then please do.

More at http://avisynth.org/mediawiki/ConvertToYV12.

juGGaKNot
4th September 2009, 18:06
echo AVIsource("%mypath%\%mymovie%.avi",audio=false) >> "%mypath%\%mpath%\T1\%mymovie%3.avs"
echo WriteFile("%mypath%\%mpath%\T1\res.txt", "WIDTH") >> "%mypath%\%mpath%\T1\%mymovie%3.avs"
"%mypath%\bin\ffmpeg.exe" -i "%mypath%\%mpath%\T1\%mymovie%3.avs"
set /p myres=<"%mypath%\%mpath%\T1\res.txt"

set rangepc=PC.601
if %myres% GEQ 160 GOTO A1
:A1
if %myres% LEQ 1279 GOTO SETBT601
GOTO A2
:A2
if %myres% GEQ 1280 GOTO SETBT709
GOTO END
:SETBT601
set rangepc=PC.601
GOTO END
:SETBT709
set rangepc=PC.709
GOTO END
:END

echo AVIsource("%mypath%\%mymovie%.avi") >> "%mypath%\%mpath%\T3\%mymovie%.avs"
echo ConvertToYV12(matrix="%rangepc%") >> "%mypath%\%mpath%\T3\%mymovie%.avs"
echo LoadPlugin("%mypath%\bin\autocrop.dll") >> "%mypath%\%mpath%\T3\%mymovie%.avs"
echo AutoCrop(0, 16, 16, threshold=0) >> "%mypath%\%mpath%\T3\%mymovie%.avs"



gl, simple but what i use ...

also --fulrange in x264 cmd

nhope
4th September 2009, 18:29
Thanks but I'm struggling with that to be honest because I don't know what LEQ 1279 and GEQ 1280 refer to.

If my source is DV or HDV, frameserved out of Vegas Pro to AviSynth as RGB AVI, should I be using PC.601 or PC.709?

juGGaKNot
4th September 2009, 18:34
Thanks but I'm struggling with that to be honest because I don't know what LEG 1279 and GEQ 1280 refer to.

If my source is DV or HDV, frameserved out of Vegas Pro to AviSynth as RGB AVI, should I be using PC.601 or PC.709?

if resolution under 1280 than 601, if over 709

the script detects the resolution ( WIDTH ), sets it to %myres% var

LEQ = lower than WIDTH
GEQ = higher than WIDTH

if lower than 1280 it sets it to pc.601, if higher than 1280 it sets it to 709

this is what you want, under 1280 pc.601, over pc.709

the rec ones are limited, [16:235] i think, pc is fullrange [0:255]

nhope
4th September 2009, 18:36
Thanks very much

juGGaKNot
4th September 2009, 18:39
ah you use megui

thats for bat ...

this is what you want, under 1280 pc.601, over pc.709

this applies to limited also ( movies )

under 1280 rec.601, over rec.709