This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm whether you accept or reject these cookies being set.

A cookie will be stored in your browser regardless of choice to prevent you being asked this question again. You will be able to change your cookie settings at any time using the link in the footer.

[BUG] Vapoursynth: Image Stream Luma TV Range not working correctly (??)
#11
That worked.

Cu Selur
Reply
#12
Problem is your input isn't TV scale but PC scale.
So you need to use 'pc' scale when in the Imagesequence dialog and the colors stay the same while converting between RGB and YUV.

So the script used by Hybrid:
# Imports
import vapoursynth as vs
core = vs.get_core()
# loading source: C:/Users/Selur/Desktop/ImgStrmVStest/000000.png
# color sampling RGB24@24, matrix:709, scantyp: progressive
# luminance scale PC
# resolution: 1312x960
# frame rate: 1 fps
# Loading C:\Users\Selur\Desktop\ImgStrmVStest\%06d.png using vsImageReader
clip = core.imwri.Read("C:/Users/Selur/Desktop/ImgStrmVStest/%06d.png", firstnum=0)
clip = core.std.Trim(clip=clip, length=51)
# Input color space is assumed to be RGB24.
# making sure frame rate is set to 25
clip = core.std.AssumeFPS(clip, fpsnum=25, fpsden=1)
# Setting color range to PC (full) range.
clip = core.std.SetFrameProp(clip=clip, prop="_ColorRange", intval=0)
# adjusting output color from: RGB24 to YUV420P8 for x264Model (i420)
clip = core.resize.Bicubic(clip=clip, format=vs.YUV420P8, matrix_s="709", range_s="full")
# Output
clip.set_output()
for the conversion should be correct.

I attached the source frame and the snapshow from the vsPreview.
I also attached the Levels graphs of the source and the vsPreview png created with Paint.Net.

The whole mess you encountered happens when you use the wrong luma range. Wink
Hybrid assumes your value to be correct and what happens is that the source then gets clamped (not scaled) to 15-235 which causes the contrast to be 'off'.

Cu Selur
Reply
#13
Except, the output video file is at "PC" range instead of "TV" range. Shoudn't the x264 output range change to "TV" if "Range Conversion" -> "full to limited (pc -> tv)" is specified on the "Color" tab for Vapoursynth?

[Image: PNIOy86.png]

# Imports
import vapoursynth as vs
core = vs.get_core()
# Loading E:\USER\fin\Joga\Bjork - Joga_%1d.00x_1312x960_Gaia-HQ_png\000000.png using vsImageReader
clip = core.imwri.Read("E:/USER/fin/Joga/Bjork - Joga_%1d.00x_1312x960_Gaia-HQ_png/000000.png", firstnum=2)
clip = core.std.Trim(clip=clip, length=100)
# Input color space is assumed to be RGB24.
# making sure frame rate is set to 25
clip = core.std.AssumeFPS(clip, fpsnum=25, fpsden=1)
# Setting color range to PC (full) range.
clip = core.std.SetFrameProp(clip=clip, prop="_ColorRange", intval=0)
clip = core.resize.Point(clip, range_in_s="full", range_s="limited")
# Setting color range to TV (limited) range.
clip = core.std.SetFrameProp(clip=clip, prop="_ColorRange", intval=1)
# adjusting output color from: RGB24 to YUV420P8 for x264Model (i420)
clip = core.resize.Bicubic(clip=clip, format=vs.YUV420P8, matrix_s="709", range_s="limited")
# Output
clip.set_output()

The Vapoursynth preview stays looking correct when toggling "Range Conversion" -> "full to limited (pc -> tv)" on and off.

So shouldn't this produce a "TV" range mp4 file?


[Image: t4MV2uR.png]

I guess I'm not understanding why it works differently in AviSynth.

The only way to get a "TV" range mp4 file (as in AviSynth), is to import at TV range and enable the "Levels" filter in Vapoursynth:

# Color Adjustment
clip = core.std.Levels(clip=clip, min_in=0, max_in=255, min_out=16, max_out=235)

Anyways, at least we know it's not a bug! Blush

By the way, what program did you use to take the "levels" screenshots? Smile
Reply
#14
Quote:Except, the output video file is at "PC" range instead of "TV" range. Shoudn't the x264 output range change to "TV" if "Range Conversion" -> "full to limited (pc -> tv)" is specified on the "Color" tab for Vapoursynth?
Yes, the video would be tv range, the same as the source images.
If you want to produce TV range out of PC range you should use the Color Matrix filters.

# Setting color range to PC (full) range.
clip = core.std.SetFrameProp(clip=clip, prop="_ColorRange", intval=0)
clip = core.resize.Point(clip, range_in_s="full", range_s="limited")
# Setting color range to TV (limited) range.
clip = core.std.SetFrameProp(clip=clip, prop="_ColorRange", intval=1)
this does a PC -> TV range conversion, which is okay, but your VUI signaling does not match your content your playback thus the colors in your output will be 'off'.
If you use the Levels filter this does the same.

If you use the Range Conversion to TV scale or change the luma levels using make sure you signal TV scale and not PC scale in your encoding settings, otherwise your output will be 'off'. My guess this is what causes part of the confusion. (In some cases Hybrid tries to adjust the encoding settings, but not in all, since it can't be sure what is done why. Wink)

----
I can't say what's happening when you use Avisynth, since you did not share the used script and encoding settings.

Cu Selur
Reply
#15
Doh I thought I did!

So importing at Luma range "TV" previews and exports the same as the source png's in AviSynth (exported mp4 is at "TV" luma range):

ClearAutoloadDirs()
LoadPlugin("C:\PROGRA~1\Hybrid\32bit\AVISYN~1\ImageSeq.dll")
SetFilterMTMode("DEFAULT_MT_MODE", MT_MULTI_INSTANCE)
# loading source: E:/USER/fin/Joga/GaiaHQ/%06d.png
#  input color sampling RGB32@8, matrix:Rec.709, scantyp: progressive
#  input luminance scale tv
ImageReader(file="E:\USER\fin\Joga\GaiaHQ\%06d.png", start=0, end=99, fps=25, use_DeviL=true, pixel_type="RGB24")
# current resolution: 1312x960
# adjust color to YV12
ConvertToYV12(matrix="Rec709")
PreFetch(4)
return last


x264 --preset veryslow --crf 18.00 --profile high --level 4.1 --ref 6 --sync-lookahead 12 --qpmax 51 --vbv-maxrate 62500 --vbv-bufsize 78125 --sar 1:1 --qpfile GENERATED_QP_FILE --non-deterministic --range tv --colormatrix bt709 --demuxer raw --input-res 1312x960 --input-csp i420 --input-range tv --input-depth 8 --fps 24000/1001 --output-depth 8 --output "C:\Users\Administrator\AppData\Local\Temp\GaiaHQ.264" -

If I switch over to Vapoursynth, it's now got the off contrast/color problem, unless I import it at "PC" range. But then I don't know how to get Hybid to output an mp4 file that is at "TV" range. To do that, I have to import at TV range, then enable the levels filter. (Correct behavior?)
Reply
#16
Your source is PC range, so you need to:
1. Import as PC range
2. Use the range filter (pc->tv)
3. set the VUI color signaling in the output to TV

Cu Selur
Reply
#17
Thanks Selur, I think I understand now. Although I would suggest, that if "Range conversion: full to limited (pc->tv)" is selected in Vapoursynth, then Hybrid should probably change --range pc to --range tv in the command line automatically. Wink
Reply
#18
I'll think about it.
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)