Welcome to Doom9's Forum, THE in-place to be for everyone interested in DVD conversion.

Before you start posting please read the forum rules. By posting to this forum you agree to abide by the rules.

 

Go Back   Doom9's Forum > Capturing and Editing Video > VapourSynth

Reply
 
Thread Tools Search this Thread Display Modes
Old 4th December 2019, 15:25   #41  |  Link
vkusnyashka
Registered User
 
Join Date: Nov 2017
Posts: 12
Sorry, my problem from the previous post is not related to this topic. I found this setting in the VapourSynth Editor - https://i3.imageban.ru/out/2019/12/0...c97d14d8c2.png
In AvsPmod the color matrix is determined based on the resolution of the clip, by default - https://i5.imageban.ru/out/2019/12/0...8b1eb17255.png
I completely forgot about it, so I did not think that the problem was in the preview.
Initially, I found a problem when using another VS-script viewer, in which there is no choice of colors matrix for viewing. I switched between the clip after deinterlacing and the clip where avsw.Eval goes next.
vkusnyashka is offline   Reply With Quote
Old 4th December 2019, 18:24   #42  |  Link
_Al_
Registered User
 
Join Date: May 2011
Posts: 321
Yes, same old quantum physics principle - you look at YUV values only to see different 8bit RGB values. :-) So looking at it, you never see a real thing.

RGB preview values next to those real YUV values in VapourSynth Editor could help regarding these issues, because one could notice the same YUV values for both videos but different RGB values for preview.
Or to always change your YUV to RGB24 or COMPATBGR32 yourself before preview where typing that mandatory matrix_in value would strike you right away as well.
Code:
rgb = core.resize.Point(clip, format = vs.COMPATBGR32, matrix_in_s = '470bg')
VapourSynth Editor loosely translated to Python using PyQt5 uses this to emit RGB values on screen via Qt modules, so your rgb would not be changed:
Code:
kernel = "Point"          # chroma resampling filter in its menu, besides other parameters - chroma placement, b,c,tap parameters omitted in this example
matrix_in_s = "470bg"   # in the settings menu as matrix coefficients
_resize = getattr(core.resize, kernel)
rgb = _resize(clip, format = vs.COMPATBGR32, matrix_in_s = matrix_in_s) 
stride = rgb.get_frame(frame_number).get_stride(0)
#to get one frame 305 for example:
img = QImage(rgb.get_frame(305).get_read_array(0), rgb.width, rgb.height, stride, QImage.Format_RGB32).mirrored()  #it is 8bit Qt  image format
#also Format_RGB32 in Qt means four 8bit interleaved planes with alpha, vapoursynths' COMPATBGR32 equivalent, so it is 8bit
pix = QPixmap.fromImage(img).scaled(scale_w, scale_h, **modes)  #getting 8bit Qt pixmap that is emited on screen  
#if not zooming -> scale_w, scale_h are the same as resolution -> exactly same values
#modes = {'aspectRatioMode':Qt.KeepAspectRatio,'transformMode':Qt.FastTransformation}
#that modes is in the vs editor menu as well, above scripted modes means nearest resize in Qt, that one you want to investigate true  RGB equivalents of YUV pixel values

Last edited by _Al_; 4th December 2019 at 18:57.
_Al_ is offline   Reply With Quote
Old 5th December 2019, 06:57   #43  |  Link
vkusnyashka
Registered User
 
Join Date: Nov 2017
Posts: 12
_Al_, thank you for the explanation.
With
Code:
rgb = core.resize.Point (clip, format = vs. RGB24, matrix_in_s = '470bg')
the colors are the same.
With
Code:
rgb = core.resize.Point (clip, format = vs. COMPATBGR32, matrix_in_s = '470bg')
error
Quote:
vapoursynth.Error: Eval: only special filters may accept compat input
_________________
Quote:
Originally Posted by _Al_ View Post
RGB preview values next to those real YUV values in VapourSynth Editor could help regarding these issues, because one could notice the same YUV values for both videos but different RGB values for preview.
Nevertheless, I am interested, can you explain why at standard values for the preview color changes are visible only after "avsw.Eval"? I made a comparison of 3 screenshots (switch between them through 1-2-3 or ← →) - https://slow.pics/c/qzQumaqM
vkusnyashka is offline   Reply With Quote
Old 5th December 2019, 17:16   #44  |  Link
_Al_
Registered User
 
Join Date: May 2011
Posts: 321
That RGB24 or COMPATBGR32 conversion is just for preview, to make sure yourself, what's going on, to bypass vsedit Preview or any other software preview conversion to RGB, to avoid setting defaults for matrix or pulling them from menu:
Code:
import vapoursynth as vs
from vapoursynth import core
clip = core.std.BlankClip(width=200, height=200, color=[220, 0, 20])
matrix = core.resize.Bicubic(clip, format=vs.YUV420P8, matrix_s="470bg")
avs = core.avsw.Eval("trim(0,0)", clips=[matrix], clip_names=["last"])
avs_preview = core.resize.Point (avs, format = vs. COMPATBGR32, matrix_in_s = '470bg') #or vs.RGB24
avs_preview.set_output(0) #just for preview in RGB 8bit so previewer does not uses matrix for conversion
avs.set_output(1)  #for encoding: vspipe --outputindex 1 script.vpy - --y4m | x264 ....

#or both for preview as well if you have some previewer that can switch between outputs 
#or Previewer that accepts clip arguments:
#Preview([avs_preview, avs])
#Preview([vs.get_output(0), vs.get_output(1)])
you were pushing COMPATBGR32 into avsw.Eval() or something so you got that error, that simple COMPATBGR32 conversion should not give you error

As for that comparison , as I said, I cannot confirm that, I have the same colors in all cases. But I thought, you sorted that out by using proper Matrix in vs editor menu or some other (by the picture). Just use that script I just posted and load both outputs or switch between outputs. If color is different then that viewer us using wrong matrix for that YUV output.

And if both outputs are wrong, then at least we know , it is not a matrix issue with preview, I have no idea what that would be.

Last edited by _Al_; 5th December 2019 at 18:03.
_Al_ is offline   Reply With Quote
Old 6th December 2019, 06:57   #45  |  Link
vkusnyashka
Registered User
 
Join Date: Nov 2017
Posts: 12
Quote:
Originally Posted by _Al_ View Post
That RGB24 or COMPATBGR32 conversion is just for preview, to make sure yourself, what's going on, to bypass vsedit Preview or any other software preview conversion to RGB, to avoid setting defaults for matrix or pulling them from menu:
I understood this very well, just wrote you about the results

Quote:
Originally Posted by _Al_ View Post
you were pushing COMPATBGR32 into avsw.Eval()
No, before avsw.Eval(). I just did not check that the option of inserting this line after "avsw.Eval ()" will work.

Quote:
Originally Posted by _Al_ View Post
Code:
import vapoursynth as vs
from vapoursynth import core
clip = core.std.BlankClip(width=200, height=200, color=[220, 0, 20])
matrix = core.resize.Bicubic(clip, format=vs.YUV420P8, matrix_s="470bg")
avs = core.avsw.Eval("trim(0,0)", clips=[matrix], clip_names=["last"])
avs_preview = core.resize.Point (avs, format = vs. COMPATBGR32, matrix_in_s = '470bg') #or vs.RGB24
avs_preview.set_output(0) #just for preview in RGB 8bit so previewer does not uses matrix for conversion
avs.set_output(1)  #for encoding: vspipe --outputindex 1 script.vpy - --y4m | x264 ....

#or both for preview as well if you have some previewer that can switch between outputs 
#or Previewer that accepts clip arguments:
#Preview([avs_preview, avs])
#Preview([vs.get_output(0), vs.get_output(1)])
YUV to RGB value set to defoault (BT709). Screenshots:
avs_preview.set_output avs.set_output

Now I just replaced the line
Code:
avs = core.avsw.Eval("trim(0,0)", clips=[matrix], clip_names=["last"])
with the line
Code:
avs = core.std.Trim(matrix, 0, matrix.num_frames-1)
Screenshots:
avs_preview.set_output avs.set_output

I’m just wondering why in the first case I see color changes, but in the second I don’t see
vkusnyashka is offline   Reply With Quote
Old 6th December 2019, 07:47   #46  |  Link
poisondeathray
Registered User
 
Join Date: Sep 2007
Posts: 5,346
@vkusnyashka-

If you are using vsedit, it has to do with the frame props assigned. That's what it's using for the preview. The preview settings are only used if there are no frame props , no metadata or "unknown"

Whenever it passes through avsw.Eval, it loses the frame props

In the second case, replacing with internal std.Trim retains the frame props from the previous matrix. You can see this with avs = core.text.FrameProps(avs) , where matrix is "5" now (which is bt470bg). So that is used for the RGB conversion for the preview, not the editor settings. So both left (where you forced 470bg) and right (using props) should and do look the same

In the first case, the left side "avs_preview" specified 470bg for RGB conversion,"avs" did not and has no props assigned (it "lost" them through avsw.Eval), therefore it uses the settings in the editor. So you get expected difference in color for the preview since it's set to 709.

Note in both cases the actual values in YUV are the same, only the RGB converted preview representation is changed
poisondeathray is offline   Reply With Quote
Old 6th December 2019, 09:20   #47  |  Link
_Al_
Registered User
 
Join Date: May 2011
Posts: 321
vkusnyashka - I had persistence in color results because if using vsedit for preview I had in Advanced settings always proper matrix coefficients.

Then you'd have same colors even after going from avsw.Eval() and it looses '709' - that's a good catch!
So pdr says you should do this to reset that proper matrix again (if not making sure in that menu for setting matrix or making RGB for preview yourself):
Code:
avs = core.avsw.Eval("trim(0,0)", clips=[matrix], clip_names=["last"])
avs = core.std.SetFrameProp(avs, prop="_Matrix", intval=1) #1 for '709' or 5 if '470bg'
avs.set_output(0)
I just printed props from those clips to visually depict what pdr says:
matrix clip has these props if set to '709':
Code:
  _ChromaLocation          0=left
  _ColorRange              1=limited range
  _DurationDen             24
  _DurationNum             1
  _Matrix                  1=709
  _Primaries               2=unspec
  _Transfer                2=unspec
avs looses all props and has None, again good catch, we could save couple of days if the idea was there earlier :-)

another follow up idea is to paste some props from that matrix clip back to the new avs clip, but that could be kind of redundant even dangerous (avs script can change things) because you write that script and you know what those props are if needed in script
Code:
import vapoursynth as vs
from vapoursynth import core

def copy_property(n, f):
    fout = f[1].copy()
    props = ['_Matrix', '_ChromaLocation', '_Primaries', '_Transfer']
    for prop in props:
        try:
            fout.props[prop] = f[0].props[prop]
        except:
            pass
    return fout

clip = core.std.BlankClip(width=200, height=200, color=[220, 0, 20])
matrix = core.resize.Bicubic(clip, format=vs.YUV420P8, matrix_s="709")

avs = core.avsw.Eval("trim(0,0)", clips=[matrix], clip_names=["last"])
avs = core.std.ModifyFrame(avs, clips=[matrix, avs], selector=paste_property)
avs.set_output(0)

Last edited by _Al_; 6th December 2019 at 10:23.
_Al_ is offline   Reply With Quote
Old 6th December 2019, 14:36   #48  |  Link
vkusnyashka
Registered User
 
Join Date: Nov 2017
Posts: 12
poisondeathray, thanks for the explanation!
_Al_, thank you too!
vkusnyashka is offline   Reply With Quote
Old 3rd February 2023, 10:23   #49  |  Link
gmail123
Registered User
 
Join Date: Dec 2014
Posts: 36
I plan to use the avs script Avisynth AiUpscale v1.2.0 within vs (https://forum.doom9.org/showthread.p...le),but failed。
Quote:
import vapoursynth as vs
core = vs.get_core()
red = core.std.BlankClip(color=[255, 0, 0])
green = core.std.BlankClip(color=[0, 255, 0])
c = core.avsw.Eval("Merge(r, g)", clips=[red, green], clip_names=["r", "g"])
c.set_output()
run successfully。

Last edited by gmail123; 3rd February 2023 at 11:17.
gmail123 is offline   Reply With Quote
Old 3rd February 2023, 10:25   #50  |  Link
gmail123
Registered User
 
Join Date: Dec 2014
Posts: 36
but,my vs script(32bit avs dll) :
Quote:
core = vs.core

core.max_cache_size = 60000
ret = core.lsmas.LWLibavSource(r'C:\Users\Administrator\Desktop\1.mp4')
c = core.avsw.Eval('AddAutoloadDir("C:\Program Files (x86)\AviSynth+\plugins+") AiUpscale (Luma = "hq")', clips=[ret], clip_names=[ret],slave_log=r"D:\x.txt")
ret.set_output()
x.txt:
Quote:
[observe @ :376] load avisynth DLL from ''
[send_async @ :465] async send command type 0: 4294967295
[recv_thread_func @ :295] received command type 6: 4294967295 => 1
[observe @ :457] set script var 'VideoNode
Format: YUV420P8
Width: 720
Height: 480
Num Frames: 19810
FPS: 30000/1001
'
[observe @ :466] remote clip 0: 720x480 1/1/1
[send_async @ :465] async send command type 0: 4294967295
[recv_thread_func @ :295] received command type 7: 4294967295 => 2
[observe @ :501] begin eval script
AddAutoloadDir("C:\Program Files (x86)\AviSynth+\plugins+") AiUpscale (Luma = "hq")[observe @ :503] end eval script
[send_async @ :465] async send command type 1: 4294967295
[run_loop @ :135] class avs::AvisynthError_: Script error: Invalid arguments to function 'AiUpscale'.

Last edited by gmail123; 3rd February 2023 at 10:28.
gmail123 is offline   Reply With Quote
Old 3rd February 2023, 10:43   #51  |  Link
gmail123
Registered User
 
Join Date: Dec 2014
Posts: 36
I'm using avs 3.72, and my avs script works fine. What is the problem?
gmail123 is offline   Reply With Quote
Old 3rd February 2023, 14:59   #52  |  Link
gmail123
Registered User
 
Join Date: Dec 2014
Posts: 36
modify:
Quote:
c = core.avsw.Eval('AddAutoloadDir("C:\Program Files (x86)\AviSynth+\plugins+") AiUpscale (Luma = "hq")', clips=[ret], clip_names=["last"],slave_log=r"D:\x.txt")
but:
Quote:
AddAutoloadDir("C:\Program Files (x86)\AviSynth+\plugins+") AiUpscale (Luma = "hq") [observe @ :503] end eval script
[send_async @ :465] async send command type 1: 4294967295
[run_loop @ :135] class avs::AvisynthError_: Script error: There is no function named 'ConvertToShader'.
(C:/Program Files (x86)/AviSynth+/plugins+/AiUpscale.avsi, line 292)
(C:/Program Files (x86)/AviSynth+/plugins+/AiUpscale.avsi, line 294)
(C:/Program Files (x86)/AviSynth+/plugins+/AiUpscale.avsi, line 146)
(C:/Program Files (x86)/AviSynth+/plugins+/AiUpscale.avsi, line 147)
ConvertToShader is a command for the AviSynthShader plugin, but I've put it in the plugin directory and avs works fine. How do I call AviSynthShader?
Quote:
AiUpscale
This is a script to test some Super-resolution convolutional neural networks implemented as hlsl pixel shaders, through Avisynth Shader

Last edited by gmail123; 3rd February 2023 at 15:04.
gmail123 is offline   Reply With Quote
Old 3rd February 2023, 15:35   #53  |  Link
poisondeathray
Registered User
 
Join Date: Sep 2007
Posts: 5,346
Quote:
Originally Posted by gmail123 View Post
I'm using avs 3.72, and my avs script works fine. What is the problem?
The other option is to use AVISource to load the working .avs directly
poisondeathray is offline   Reply With Quote
Old 3rd February 2023, 15:49   #54  |  Link
gmail123
Registered User
 
Join Date: Dec 2014
Posts: 36
Quote:
Originally Posted by poisondeathray View Post
The other option is to use AVISource to load the working .avs directly
my working .vpy:
Quote:
ret=core.lsmas.LWLibavSource(r'C:\Users\Administrator\Desktop\1.mp4')
core = vs.core
ret =scunet(ret,model=3)
aiupscale() #avs script
ret = core.resize.Bicubic(ret, format=vs.YUV420P8, matrix_s="470bg", range_s="full")
ret.set_output()
how to use AVISource to load the working .avs directly?thx
gmail123 is offline   Reply With Quote
Old 3rd February 2023, 15:58   #55  |  Link
poisondeathray
Registered User
 
Join Date: Sep 2007
Posts: 5,346
Quote:
Originally Posted by gmail123 View Post
my working .vpy:

Quote:
ret=core.lsmas.LWLibavSource(r'C:\Users\Administrator\Desktop\1.mp4')
core = vs.core
ret =scunet(ret,model=3)
aiupscale() #avs script
ret = core.resize.Bicubic(ret, format=vs.YUV420P8, matrix_s="470bg", range_s="full")
ret.set_output()
how to use AVISource to load the working .avs directly?thx

AVISource won't work for the order that you have that script.

AVISource can only load .avs scripts in a .vpy script as the output node of the avs script, so it must be first filter in the vpy script. You cannot apply in the middle of a vpy script

If you use scunet, then avs aiupscale, you would need to import the vpy into the avs script eg. using vapoursoursce, then apply aiupscale, then import that back into the vpy. The problem is RGBS cannot be sent through vapoursource - not a supported pixel format. (vs-scunet requires RGBS or RGBH). So you'd have to downconvert after scunet in the vpy script output node, (before vapoursource in the avs script) to a supported pixel format in the AIUpscale avs script . I would use the output node of avisynth instead of sending back to vapoursynth in that case. All the piping has overhead (slow)

Last edited by poisondeathray; 3rd February 2023 at 16:06.
poisondeathray is offline   Reply With Quote
Old 3rd February 2023, 16:03   #56  |  Link
gmail123
Registered User
 
Join Date: Dec 2014
Posts: 36
Quote:
Originally Posted by poisondeathray View Post
AVISource won't work for the order that you have that script.

AVISource can only load .avs scripts in a .vpy script as the output node of the avs script, so it must be first filter in the vpy script. You cannot apply in the middle of a vpy script

If you use scunet, then avs aiupscale, you would need to import the vpy into the avs script eg. using vapoursoursce, then apply aiupscale, then import that back into the vpy. The problem is RGBS cannot be sent through vapoursource - not a supported pixel format. (vs-scunet requires RGBS or RGBH). So you'd have to downconvert in the vpy script before vapoursource in the AIUpscale avs script if sending back to vapoursynth, or use the output of avisynth instead of sending back to vapoursynth
how to import the vpy into the avs script? I can import the avsscript into the vs script
gmail123 is offline   Reply With Quote
Old 3rd February 2023, 16:07   #57  |  Link
poisondeathray
Registered User
 
Join Date: Sep 2007
Posts: 5,346
Quote:
Originally Posted by gmail123 View Post
how to import the vpy into the avs script? I can import the avsscript into the vs script
Vapoursource - VSImport() or VSEval()
poisondeathray is offline   Reply With Quote
Old 3rd February 2023, 16:09   #58  |  Link
gmail123
Registered User
 
Join Date: Dec 2014
Posts: 36
Quote:
Originally Posted by poisondeathray View Post
Vapoursource - VSImport() or VSEval()
yes ,i will try it
gmail123 is offline   Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 16:04.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.