Selur's Little Message Board

Full Version: Vapoursynth: Image Stream Luma TV Range not working correctly (??)
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
I know you're away but I found some issues with image streams and lossless encoding and if I don't post while this is fresh in my head I'm going to lose it. Tongue

Not sure if this is a bug or expected behavior.

I have an image stream of PNG files that were processed from a source that has a Luma Range of Limited/TV.

I import with the following settings:

[Image: 1YgdI8L.png]

In AviSynth preview, these behave as expected and look the same as the source.

But in Vapoursynth preview, they are different than the source (source is on the left):

[Image: 4vmgQYj.png][Image: wYP16M2.png]

Code:
# Imports
import vapoursynth as vs
core = vs.get_core()
# Loading E:\USER\fin\Joga\ImgStrmVStest\%06d.png using vsImageReader
clip = core.imwri.Read("E:/USER/fin/Joga/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 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()

If I add the following VapourSynth filter:

[Image: 5VYrZBp.png]

That seems to fix it and it now looks correct (source is on the left):

[Image: 4vmgQYj.png][Image: fyaPjIS.png]

Code:
# Imports
import vapoursynth as vs
core = vs.get_core()
# Loading E:\USER\fin\Joga\ImgStrmVStest\%06d.png using vsImageReader
clip = core.imwri.Read("E:/USER/fin/Joga/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 TV (limited) range.
clip = core.std.SetFrameProp(clip=clip, prop="_ColorRange", intval=1)
# Color Adjustment
clip = core.std.Levels(clip=clip, min_in=0, max_in=255, min_out=16, max_out=235)
# 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()

Is that expected behavior, or a bug? What's weird, is that even though that filter is changing the levels from 0 to 16, 100% black pixels remain black. Running the Levels filter in AviSynth lightens 100% black pixels.

Here's a zip of the image stream:

https://www67.zippyshare.com/v/a3vg0LOZ/file.html
Will look at it on Monday. Got no access to a pc over the weekend.

Cu Selur
Behavior is the same in Hybrid dev version 2020.07.20.1!

Image stream input Luma range is set to TV. But on output and on Vapoursynth preview, it doesn't match.

If I enable the Vapoursynth Color->Levels filter and change the "In" range to 0 / 255 (as shown above), then the frames match exactly, at least to the eye.

Again, not sure if this is expected behavior, or a Vapoursynth bug, or a Hybrid bug.
Didn't have time to look at it so far, but this is probably as it should be, depending on your color matrix choice during the opening of the image sequence.

What you look at during the preview are the RGB values.
Based on the color matrix choice you tell Hybrid how to do RGB↔YUV conversions.
Quote:string matrix = "Rec601"

Controls the colour coefficients and scaling factors used in RGB↔YUV conversions.

"Rec601" : Uses Rec.601 coefficients; scale full range [0d..255d] RGB ↔ TV range [16d..235d] YUV.
"Rec709" : Uses Rec.709 (HD) coefficients; scale full range RGB ↔ TV range YUV.
"Rec2020" : Uses Rec.2020 (UHD) coefficients; scale full range RGB ↔ TV range YUV. AVS+
"PC.601" : Uses Rec.601 coefficients; keep range unchanged.
"PC.709" : Uses Rec.709 (HD) coefficients; keep range unchanged.
"Average" : Uses averaged coefficients (the luma becomes the average of the RGB channels); keep range unchanged.
see: http://avisynth.nl/index.php/Convert
Have you checked the actual color range using the Histogram in the preview?


Cu Selur
These are the options I have for image stream input (Hybrid Dev 2020.07.20.1):

[Image: M1Xl59s.png]

I selected "bt709"; before I was selecting "unknown" but it was just using bt709 so I'm guessing that's why "unknown" was removed.

When I do that and set the Luma range to "tv", it looks correct in AviSynth preview and outputs correctly. It looks wrong in Vapoursynth preview and outputs incorrectly, unless I enable that levels filter.

I didn't need a histogram... I selected "save snapshot" from Vapoursynth preview, then opened it in an Irfanview window, then opened the original .png of the same frame in another Ifranview window, then toggled between them. It's definitely different!

I attached the png's I'm using in an archive on Zippyshare above if you have time to try and see if it happens to you.


From above:

Source png frame (resized):
[Image: ubDGTbs.png]

Vapoursynth preview snapshot save (resized):
[Image: o3G2icl.png]

If I open the .png's via Image Stream as PC instead of TV, it looks correct in Vapoursynth, but will output a PC range video file. It looks incorrect in AviSynth (too dark).

If on the Vapoursynth "Color" tab at the very bottom of the filter list, I select "Range Conversion" -> "full to limited (pc -> tv)", it stays looking correct, but it will not output a TV range video file... the video file output will be at the PC range.

This "feels" like a bug. But I'm not sure!
https://www67.zippyshare.com/v/a3vg0LOZ/file.html -> 403 Forbidden
'unknown' was removed since it did not make sense.
Color Matrix and Luma range have to be selected by the user to match the source or what he wants to happen with the source.

Okay,..
1st I need a short sequence of the images you use
2nd I need to know what settings you use in
3rd I need to know what you want to achieve
4th I need to know that your settings you use for video encoding are, especially the color signaling settings.

Cu Selur
Okay, good and bad news:
Good news: I can reproduce the issue.
Bad news: no clue why Vapoursynth is behaving like it does.
-> I opened a thread about it over at doom9s (https://forum.doom9.org/showthread.php?p=1919110) where I know that all the main Vapoursynth authors are frequently.
So with a bit of luck they can tell me how to do this properly and adjust Hybrid accordingly.
Using the 'Range conversion' option does not seem like the proper way, but iirc. a similar unexplained color issue like this was that caused me to add that option in the beginning. Smile
So fingers crossed that someone over at doom9 knows the answer.


Cu Selur
Thanks for investing the time in this... it's not MAJOR as there is a workaround (levels filter).

403 on Zippyshare typically indicates an IP range ban. If you still need it, try pasting the below url here.

Code:
https://www67.zippyshare.com/v/a3vg0LOZ/file.html
Doesn't work either.
When pressing the 'Download now' button nothing happens.

Cu Selur
Untick the "Remove Scripts" from the "Options" section to the left of where you paste the URL. Blush
Pages: 1 2