Log in

View Full Version : TV vs. PC level problem, when converting image sequence to x264


Selur
30th June 2018, 22:33
I got an image:
and use this script:
# Imports
import os
import sys
import vapoursynth as vs
core = vs.get_core()
# Import scripts folder
scriptPath = 'G:/Hybrid/64bit/vsscripts'
sys.path.append(os.path.abspath(scriptPath))
# Loading Plugins
core.std.LoadPlugin(path="G:/Hybrid/64bit/vsfilters/SourceFilter/Imagemagick/libimwri.dll")
core.std.LoadPlugin(path="G:/Hybrid/64bit/vsfilters/SourceFilter/LSmashSource/vslsmashsource.dll")
# Import scripts
import finesharp
# Loading C:\Users\Selur\Desktop\Test\Image sequence test.png using vsImageReader
clip = core.imwri.Read(["C:/Users/Selur/Desktop/Test/Image sequence test.png"])
clip = core.std.Loop(clip=clip, times=100)
# Input color space is assumed to be RGB24.
# making sure frame rate is set to 25/1
clip = core.std.AssumeFPS(clip, fpsnum=25, fpsden=1)
# Making sure input color range is set to PC (full) range.
clip = core.std.SetFrameProp(clip=clip, prop="_ColorRange", intval=0)
# Input resolution is 1280x720.
# adjusting color space from RGB24 to YUV444P16 for FineSharp
clip = core.resize.Bicubic(clip=clip, format=vs.YUV444P16, matrix_s="709")
# sharpening using FineSharp
clip = finesharp.sharpen(clip=clip)
# adjusting output color from: YUV444P16 to YUV420P8 for x264Model (i420)
clip = core.resize.Bicubic(clip=clip, format=vs.YUV420P8)
which then encode with x264 using:
vspipe "H:\Temp\encodingTempSynthSkript_23_21_51_4410.vpy" - --y4m | x264 --crf 18.00 --profile high --level 4.1 --direct auto --sync-lookahead 27 --qcomp 0.5 --no-mbtree --partitions i4x4,p8x8,b8x8 --no-fast-pskip --subme 5 --trellis 0 --weightp 1 --aq-mode 0 --vbv-maxrate 62500 --vbv-bufsize 78125 --sar 1:1 --non-deterministic --range pc --colormatrix bt709 --demuxer y4m --input-csp yuvj420p --input-range pc --fps 25/1 --output-depth 8 --output "H:\Temp\23_21_51_4410_02.264" -
Problem is the contrast changed,
I also extended the script to compare it against the image sequence to confirm the problem.

-> seems like I'm doing something wrong, but I don't see where I go wrong.

When I just use:
# Imports
import vapoursynth as vs
core = vs.get_core()
# Loading Plugins
core.std.LoadPlugin(path="G:/Hybrid/64bit/vsfilters/SourceFilter/Imagemagick/libimwri.dll")
# Loading C:\Users\Selur\Desktop\Test\Image sequence test.png using vsImageReader
clip = core.imwri.Read(["C:/Users/Selur/Desktop/Test/Image sequence test.png"])
clip = core.std.Loop(clip=clip, times=100)
# Input color space is assumed to be RGB24.
# making sure frame rate is set to 25/1
clip = core.std.AssumeFPS(clip, fpsnum=25, fpsden=1)
# Making sure input color range is set to PC (full) range.
clip = core.std.SetFrameProp(clip=clip, prop="_ColorRange", intval=0)
# Input resolution is 1280x720.
# adjusting output color from: RGB24 to YUV420P8 for x264Model (i420)
clip = core.resize.Bicubic(clip=clip, format=vs.YUV420P8, matrix_s="709")
# Output
clip.set_output()
So no finesharp and no RGB24 -> YUV4416 conversion, a similar problem occurs, but the contrast change isn't that prominent.

Does anyone see the problem/mistake?

Thanks!

Cu Selur

Ps.: uploaded the files I created and the source image to: https://drive.google.com/open?id=1mzyfc-ZjXsD77DtY7P7-1-XBTcCa0FVS
(using '--input-csp yuv420p' instead of '--input-csp yuvj420p' doesn't help either)

Selur
30th June 2018, 22:48
Okay, using: '--input-range auto' seems to fix the problem.

Cu Selur

MasterNobody
1st July 2018, 02:02
VapourSynth R43 documentation:Resize (http://www.vapoursynth.com/doc/functions/resize.html)
range:

Output pixel range. For integer formats, this allows selection of the legal code values. Even when set, out of range values (BTB/WTW) may be generated. If the input format is of a different color family, the default range is studio/limited for YUV and full-range for RGB.

Selur
1st July 2018, 07:46
Hmm, using 'range=0':
# Imports
import os
import sys
import vapoursynth as vs
core = vs.get_core()
# Import scripts folder
scriptPath = 'G:/Hybrid/64bit/vsscripts'
sys.path.append(os.path.abspath(scriptPath))
# Loading Plugins
core.std.LoadPlugin(path="G:/Hybrid/64bit/vsfilters/SourceFilter/Imagemagick/libimwri.dll")
# Import scripts
import finesharp
# Loading C:\Users\Selur\Desktop\Test\Image sequence test.png using vsImageReader
clip = core.imwri.Read(["C:/Users/Selur/Desktop/Test/Image sequence test.png"])
clip = core.std.Loop(clip=clip, times=100)
# Input color space is assumed to be RGB24.
# making sure frame rate is set to 25/1
clip = core.std.AssumeFPS(clip, fpsnum=25, fpsden=1)
# Making sure input color range is set to PC (full) range.
clip = core.std.SetFrameProp(clip=clip, prop="_ColorRange", intval=0)
# Input resolution is 1280x720.
# adjusting color space from RGB24 to YUV444P16 for FineSharp
clip = core.resize.Bicubic(clip=clip, format=vs.YUV444P16, matrix_s="709", range=0)
# sharpening using FineSharp
clip = finesharp.sharpen(clip=clip)
# adjusting output color from: YUV444P16 to YUV420P8 for x264Model (i420)
clip = core.resize.Bicubic(clip=clip, format=vs.YUV420P8, range=0)
# Output
clip.set_output()
doesn't help while using '--input-range pc', only using '--input-range auto' seems to help.

Cu Selur

Ps.: Got the same problem with x265 and there's no option like 'input-range' :( Also when creating a y4m with vspipe, the colors look fine, so my guess is that I make a mistake (or there is a bug) when feeding pc scale content to x264 and x265.

Selur
1st July 2018, 09:32
ARGH,.. range needs to be set to 1 not 0 like with ColorRange,..

MasterNobody
1st July 2018, 09:48
If I read Resize documentation and source code correctly than pc (full) range for resize function would be range=1 (and range=0 would tv (limited) range) because that is consts from zimg.h (https://github.com/sekrit-twc/zimg/blob/master/src/zimg/api/zimg.h#L196). Or better use range_s="full".

Selur
1st July 2018, 09:49
Thanks will use 'range_s' :)