View Full Version : How to run Avisynth scripts within VapourSynth
Stephen R. Savage
27th December 2017, 23:07
README:
Embed 32-bit Avisynth 2.6 or Avisynth+ environment within 64-bit VapourSynth.
avsw.Eval(string script, clip[] "clips", string[] "clip_names", string "avisynth", string "slave", string "slave_log")
script - Avisynth script fragment
clips - VapourSynth clips ("nodes") to inject into Avisynth environment
clip_names - Avisynth variable name corresponding to injected clip
avisynth - Path to Avisynth DLL. The default uses the process DLL search path.
slave - Path to avshost_native.exe slave procecss. The plugin path is searched by default.
slave_log - Log file for slave process.
The function returns the result of the Avisynth script, which may be an integer, float, string, or clip. If the result is a clip, the name of the return value is "clip", otherwise it is "result".
Example:
import vapoursynth as vs
core = vs.get_core()
red = core.std.BlankClip(color=[255, 0, 0])
green = core.std.BlankClip(color=[0, 255, 0])
# Before executing the Avisynth script, "r" and "g" are set to the bound clips.
c = core.avsw.Eval("Merge(r, g)", clips=[red, green], clip_names=["r", "g"])
c.set_output()
Link. (https://github.com/sekrit-twc/avsproxy/releases/download/r1a/avsproxy_r1a.7z)
ChaosKing
28th December 2017, 01:53
NICE!!
c = core.std.BlankClip(color=[255, 0, 0])
c = core.avsw.eval('AddAutoloadDir("D:\\AvisynthRepository\\SCRIPTS") mpeg2source("D:\\01.d2v") AnimeIVTC(mode=1)', clips=[c], clip_names=["last"])
clip=c
This avs script crashed via Avisource and with avfs.exe, but avsproxy is stable.
Two questions:
- Is it possible to use avisynth x64 with this filter?
- Would be a "portable" avisynth possible as long as avisynth.dll is in the same folder? (or via path parameter in avsw)
Stephen R. Savage
28th December 2017, 02:15
Two questions:
- Is it possible to use avisynth x64 with this filter?
You can load 64-bit plugins directly. It looks like your script does not need the clip binding feature, so you should be able to use VFW.
- Would be a "portable" avisynth possible as long as avisynth.dll is in the same folder? (or via path parameter in avsw)
You can provide the Avisynth library path via "avisynth" argument (link in original post updated).
Boulder
28th December 2017, 14:46
Holy smoke, thank you very much! I've been waiting to get my hands on SmoothD2 in 64-bit Vapoursynth since we are still waiting for a proper port, and with this tool, it's possible :)
ChaosKing
28th December 2017, 16:53
You can load 64-bit plugins directly. It looks like your script does not need the clip binding feature, so you should be able to use VFW.
But I can't load avs scripts directly ( AnimeIVTC is a script )
And loading my sample script via VFW aka Avisource is not possible -> instant crash in VS ( No problems in Virtualdub-64). That's why I asked if x64 would possible.
Myrsloik
28th December 2017, 18:36
But I can't load avs scripts directly ( AnimeIVTC is a script )
And loading my sample script via VFW aka Avisource is not possible -> instant crash in VS ( No problems in Virtualdub-64). That's why I asked if x64 would possible.
Instant crash? Does it output any error like bad mmx state if you try to output it with vspipe?
ChaosKing
28th December 2017, 19:44
No output. Tested like this with R41-test4
.\VSPipe.exe -i 'D:\Test.vpy' .
My vs script
clip = core.avisource.AVISource(r'D:\ivtc.avs')
clip.set_output()
But it works without tfm or animeivtc.
AddAutoloadDir("D:\AvisynthRepository\SCRIPTS")
mpeg2source("D:\01\VTS_01_CHAPTER_03_1.d2v")
tfm(mode=6, PP=5, slow =2, d2v="D:\01\VTS_01_CHAPTER_03_1.d2v") <- bad boy
But this forced me to switch to vivtc, and after some conditionalDeintStillCombed magic I got similar/better results.:D
Myrsloik
28th December 2017, 20:27
No output. Tested like this with R41-test4
.\VSPipe.exe -i 'D:\Test.vpy' .
My vs script
clip = core.avisource.AVISource(r'D:\ivtc.avs')
clip.set_output()
But it works without tfm or animeivtc.
AddAutoloadDir("D:\AvisynthRepository\SCRIPTS")
mpeg2source("D:\01\VTS_01_CHAPTER_03_1.d2v")
tfm(mode=6, PP=5, slow =2, d2v="D:\01\VTS_01_CHAPTER_03_1.d2v") <- bad boy
But this forced me to switch to vivtc, and after some conditionalDeintStillCombed magic I got similar/better results.:D
Can you put all the scripts and a sample script and the plugins into an archive? That way I can test with the same versions as you and don't need to go on a treasure hunt. And reveal your avisynth version too while you're at it. I'd really like to get to the bottom of this...
ChaosKing
28th December 2017, 22:26
Here is my x64 r2544 avs folder (plugins, scripts & sample script)
LINK (https://www.dropbox.com/s/bwxiquo3dr3ddiu/AVS_tfm_fail.rar?dl=0)
//EDIT
Same crash with r2580
ChaosKing
29th December 2017, 00:01
Thx, woking now. Loading an external avisynth.dll too!
Myrsloik
29th December 2017, 17:47
Here is my x64 r2544 avs folder (plugins, scripts & sample script)
LINK (https://www.dropbox.com/s/bwxiquo3dr3ddiu/AVS_tfm_fail.rar?dl=0)
//EDIT
Same crash with r2580
I found one crash in avisource. Try it again when I release the next R41 build.
Myrsloik
30th December 2017, 19:49
Here is my x64 r2544 avs folder (plugins, scripts & sample script)
LINK (https://www.dropbox.com/s/bwxiquo3dr3ddiu/AVS_tfm_fail.rar?dl=0)
//EDIT
Same crash with r2580
Try again with R41-RC1
ChaosKing
30th December 2017, 20:22
Try again with R41-RC1
vapoursynth.Error: Avisynth read error:
CAVIStreamSynth: System exception - Access Violation at 0x000001D41A5DB6D0
2017-12-30 20:16:58.862
Core freed but 460800 bytes still allocated in framebuffers
Core freed but 460800 bytes still allocated in framebuffers
2017-12-30 20:17:05.392
Bad MMX state detected when creating new core
same error in vspipe and vs editor, only that the mmx line is only shown in the vs editor. Tested with colorbars() + tfm(mode=6)
Myrsloik
30th December 2017, 20:29
vapoursynth.Error: Avisynth read error:
CAVIStreamSynth: System exception - Access Violation at 0x000001D41A5DB6D0
2017-12-30 20:16:58.862
Core freed but 460800 bytes still allocated in framebuffers
Core freed but 460800 bytes still allocated in framebuffers
2017-12-30 20:17:05.392
Bad MMX state detected when creating new core
same error in vspipe and vs editor, only that the mmx line is only shown in the vs editor. Tested with colorbars() + tfm(mode=6)
At least we're making progress. It happens because of a bug in one of the avisynth plugins. Comment out the script gradually and locate which one it is. Someone forgot to use the emms instruction. Find the plugin author and shame them, or update to the latest version of whatever plugin it is.
ChaosKing
30th December 2017, 20:37
Working now. I had an old x64 TIVTC.dll from 2010, don't know why :-/
No problems with: https://github.com/pinterf/TIVTC/releases
EDIT: I guess I took it from this (outdated) list http://avisynth.nl/index.php/AviSynth%2B_x64_plugins
EDIT2: But it's still interessting that it only crashes in VS and not in VdubMod
ChaosKing
7th January 2018, 11:07
I should be able to pass a VS clip to Avisynth, right?
Because this works
c = core.avsw.eval('blankclip() Subtitle("Hello world!") ')
but not this
c = core.std.BlankClip(color=[255, 0, 0])
c = core.avsw.eval('Subtitle("Hello world!") ', clips=[c], clip_names=["last"])
vapoursynth.Error: Avisynth 32-bit proxy: command failed
ChaosKing
8th January 2018, 01:27
The original from Soureforge works, also 2.6 (MT) from here https://forum.doom9.org/showthread.php?t=148782
But the colors are shifted https://www.dropbox.com/s/7lft4ek9636li6p/vs_avs_color.PNG?dl=0
AVS+ would be nice for 16bit support (if possible)
ChaosKing
13th January 2018, 11:55
I totally forgot about stack16, thanks for the reminder!
Found a new issue:
I tried CropResize from here https://forum.doom9.org/showthread.php?t=175114 with Autocrop, but it gets stuck. Without AutoC=true it's ok. There's no output in vspipe. tested with avs+ and 2.6
core.avsw.Eval('AddAutoloadDir("D:\AvisynthRepository\SCRIPTS") pCropResize(AutoC=true)', clips=[c], clip_names=["last"], slave_log=r"D:\x.txt", avisynth =r"D:\AvisynthRepository\AVSPLUS_x86\Avisynth.dll")
[observe @ :376] load avisynth DLL from 'D:\AvisynthRepository\AVSPLUS_x86\Avisynth.dll'
[send_async @ :465] async send command type 0: 4294967295
[recv_thread_func @ :295] received command type 6: 4294967295 => 1
[observe @ :457] set script var 'last'
[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("D:\AvisynthRepository\SCRIPTS") pCropResize(AutoC=true)[observe @ :503] end eval script
[GetFrame @ :288] clip 0 frame 1 not prefetched
[send_sync @ :492] sync send command type: 8
[send_async @ :465] async send command type 8: 0
ChaosKing
15th January 2018, 00:54
Works flawlessly :D
EDIT: currently an avs error msg is not show like in virtualdub (or any other tool). It would be nice to see the actual avs error rather than "vapoursynth.Error: Avisynth 32-bit proxy: command failed". It's a nice to have feature (and if it isn't too hard to implement) ;)
Boulder
18th January 2018, 19:51
2.6 and avs+
AttributeError: There is no function named eval
What does this error actually mean? I was trying to test this script and got the message. The sample script from the first post works fine.
import vapoursynth as vs
core = vs.get_core()
core.avs.LoadPlugin(r'C:\\Program Files\\VapourSynth\\avs64\DGDecodeNV.dll')
c = core.avs.DGSource(r'C:\Temp\test.dgi')
clp = core.avsw.eval('SmoothD2(quant=2, shift=4)', clips=[c], clip_names=["last"])
clp.set_output()
ChaosKing
18th January 2018, 20:29
new syntax is: core.avsw.Eval
All posts by Stephen R. Savage are deleted?
//Edit
Deleted some of my posts too so that I don't look like I'm talking to myself all the time:D
Boulder
18th January 2018, 21:33
Thanks, missed that one :)
TheFluff
18th January 2018, 22:05
new syntax is: core.avsw.Eval
All posts by Stephen R. Savage are deleted?
You need to quote him when he posts because he deletes his own posts after a while for whatever paranoid reason.
monohouse
31st January 2018, 06:52
I like this idee, I am looking to use vaporsynth for nnedi3 but I need didee' daa3, is it possible to combine vaporsynth functions with avisynth functions ?
this is the daa3 code that I am using:
#controllable Anti-aliasing with contra-sharpening by Didée
FUNCTION daa3(clip c, int "nthreads", int "nsharp", int "neurons", int "q", int "size" ) {
nthreads = default(nthreads, 8)
nsharp = default(nsharp, 25)
neurons = default(neurons, 4)
q = default(q, 5)
size = default(size, 3)
Assert((nthreads>=1) ? true : false, chr(10) + "'nthreads' must be at least 1" + chr(10))
Assert((nsharp>=-1&&nsharp<=25) ? true : false, chr(10) + "'nsharp' must be between -1 and 25" + chr(10))
Assert((q>=0&&q<=5) ? true : false, chr(10) + "'q' must be between 0 and 5" + chr(10))
Assert((neurons>=0&&neurons<=4) ? true : false, chr(10) + "'neurons' must be between 0 and 4" + chr(10))
Assert((size>=1&&size<=6) ? true : false, chr(10) + "'size' must be between 1 and 6" + chr(10))
nn = (q == 0) ? c.nnedi3(field=-2,nsize=size,nns=neurons,qual=1,pscrn=2,fapprox=0,threads=nthreads) :
\ (q == 1) ? c.nnedi3(field=-2,nsize=size,nns=neurons,qual=1,pscrn=1,fapprox=0,threads=nthreads) :
\ (q == 2) ? c.nnedi3(field=-2,nsize=size,nns=neurons,qual=1,pscrn=0,fapprox=0,threads=nthreads) :
\ (q == 3) ? c.nnedi3(field=-2,nsize=size,nns=neurons,qual=2,pscrn=2,fapprox=0,threads=nthreads) :
\ (q == 4) ? c.nnedi3(field=-2,nsize=size,nns=neurons,qual=2,pscrn=1,fapprox=0,threads=nthreads) :
\ c.nnedi3(field=-2,nsize=size,nns=neurons,qual=2,pscrn=0,fapprox=0,threads=nthreads)
dbl = mt_average(selecteven(nn),selectodd(nn),U=3,V=3)
dblD = mt_makediff(c,dbl,U=3,V=3)
shrpD = nsharp==25 ? mt_makediff(dbl,dbl,U=3,V=3) : mt_makediff(dbl,dbl.removegrain(nsharp),U=3,V=3)
DD = shrpD.repair(dblD,13)
return dbl.mt_adddiff(DD,U=3,V=3) }
the goal is to run the nnedi3 portion using vaporsynth (with openCL version for speed)
while making sure the function that uses nnedi3 inside daa3 will function:
dbl = mt_average(selecteven(nn),selectodd(nn),U=3,V=3)
is sutch a thing is possible ?
poisondeathray
31st January 2018, 07:52
The newest havsfunc r27 has a daa version with NNEDI3CL, but it looks to be slightly different from your avs version . But maybe you can use it as a starting point
monohouse
31st January 2018, 10:22
yip :) the code is the same, it just the language that changed :) thank this HAVSfunc is the best, and he even created LSFmod too :)
I like the idee of vaporsynth, he just use python, whay make a new script language when there is already script language :)
FNSCAR
1st March 2018, 02:33
Thanks for your work!
I have not install avisynth so I use AddAutoLoadDir() in this environment but it doesn't work.
c = core.avsw.Eval('AddAutoLoadDir("F:\x86\plugins+") TFM()', clips=[src], clip_names=["last"],avisynth=r'F:\x86\AviSynth.dll')
Just get "Avisynth 32-bit proxy: command failed".
And avisynth built-in functions e.g. selecteven() work well.
What mistakes have I made?
ChaosKing
1st March 2018, 08:19
One way to debug it is to try to run your avs script in virtual dub first (copy avisynth dll inside vdubs dir) to see the error message. Could be a missing runtime dll.
Edit:
Also use "slave_log" parameter to see what's going on.
FNSCAR
1st March 2018, 08:57
The avs script can be previewed in avspmod and I have tried to feed the avs script to x264.exe and it start to encode normally.
[observe @ :376] load avisynth DLL from 'F:\x86\AviSynth.dll'
[send_async @ :465] async send command type 0: 4294967295
[recv_thread_func @ :295] received command type 6: 4294967295 => 1
[observe @ :457] set script var 'last'
[observe @ :466] remote clip 0: 640x360 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("F:\plugins+") TFM()[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 'TFM'.
This is my slave_log.
ChaosKing
1st March 2018, 09:12
There is no function named 'TFM'
- is it a 32bit dll?
- check for missing runtimes
- update to latest tivtc version https://github.com/pinterf/TIVTC/releases
FNSCAR
1st March 2018, 09:38
Thanks for your reply.
tivtc.dll is latest 32bit version from pinterf.
TIVTC is just an example.In fact I could not load any plugins with function AddAutoLoadDir() or LoadPlugin() if I used a portable avisynth.dll in avsproxy.
But if I installed avisynth,everything would be fine.
ChaosKing
1st March 2018, 12:30
As far as I remember the avisynth.dll also looks for DevIL.dll first and maybe for some other bundled dlls. Just copy all bundled dlls into the same folder and see if it helps
ChaosKing
23rd March 2018, 09:49
Does someone get a crash in vsedit preview with a simple 'info()'? Only this avs function crashes vsedit and only in preview. No error msg is shown. I'm using the latest avs+
[send_async @ :465] async send command type 0: 4294967295
[recv_thread_func @ :295] received command type 6: 4294967295 => 1
[observe @ :457] set script var 'last'
[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
info()[observe @ :503] end eval script
[send_avsvalue @ :575] local clip 0: 720x480 -1610612728
[send_async @ :465] async send command type 6: 4294967295
[recv_thread_func @ :295] received command type 8: 4294967295 => 3
[observe @ :517] GetFrame clip 0 frame 29827
[GetFrame @ :288] clip 0 frame 29827 not prefetched
[send_sync @ :492] sync send command type: 8
[send_async @ :465] async send command type 8: 0
[recv_thread_func @ :326] exit receiver thread after exception
[stop @ :363] stop IPC receiver thread
[stop @ :380] rethrow exception from receiver thread
[wmain @ :168] IPC error: remote process terminated unexpectedly
ChaosKing
25th March 2018, 09:36
I haven't change anything, but now it just works again. Must be something in my system :/
I only updated masktools ... but I doubt it had anything to do with it.
MysteryX
21st May 2018, 00:28
You can load 64-bit plugins directly.
AFAIK loading through AviSource doesn't allow passing clips and thus can only be used at the beginning of a script, while your script can be used anywhere in the script, so that's a big difference.
poisondeathray
21st May 2018, 18:05
AFAIK loading through AviSource doesn't allow passing clips and thus can only be used at the beginning of a script, while your script can be used anywhere in the script, so that's a big difference.
Is that what you meant to say ?
Actually, AVISource only allows passing clips (including avs scripts), and you can call the clip anywhere in the script
Plugins are loaded either through this avsproxy plugin, or through avs.LoadPlugin through the compatibility wrapper
http://www.vapoursynth.com/doc/functions/loadpluginavs.html
MysteryX
23rd May 2018, 18:27
Is that what you meant to say ?
Actually, AVISource only allows passing clips (including avs scripts), and you can call the clip anywhere in the script.
Plugins are loaded either through this avsproxy plugin, or through avs.LoadPlugin through the compatibility wrapper
http://www.vapoursynth.com/doc/functions/loadpluginavs.html
http://www.vapoursynth.com/doc/plugins/avisource.html
I mean AviSource cannot be inserted in the middle of a VapourSynth task because it cannot take any clip to feed into the Avisynth script.
If I want to run Denoise in VapourSynth, Deshaker in Avisynth, and frame interpolation in VapourSynth, this can only be done using this avsproxy, not AviSource.
Note that if you are really insane you can load Avisynth’s VirtualDub plugin loader and use VirtualDub plugins as well.
Saw this in the documentation. Was considering switching to VapourSynth and using the compatibility wrapper for Deshaker which is for VirtualDub. Does this work fine? I'm not crazy; on good days.
foxyshadis
24th May 2018, 03:19
http://www.vapoursynth.com/doc/plugins/avisource.html
I mean AviSource cannot be inserted in the middle of a VapourSynth task because it cannot take any clip to feed into the Avisynth script.
If I want to run Denoise in VapourSynth, Deshaker in Avisynth, and frame interpolation in VapourSynth, this can only be done using this avsproxy, not AviSource.
Saw this in the documentation. Was considering switching to VapourSynth and using the compatibility wrapper for Deshaker which is for VirtualDub. Does this work fine? I'm not crazy; on good days.
If you have AVS+ you'll already have a copy of VDubFilter.dll, loading that would be the way to go. The code (https://github.com/pinterf/AviSynthPlus/blob/master/plugins/VDubFilter/VDubFilter.cpp) isn't terribly difficult, I'd imagine I could convert it to pure VS in an evening if I had some time.
vkusnyashka
2nd December 2019, 14:58
del. Sorry, my problem is not related to this topic...
_Al_
4th December 2019, 00:55
I cannot confirm that, using this script:
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"])
I have same values for any pixel for both clip matrix and clip avs: YUV420P8 y:74 u:104 v:223 preview: r:219 g:0 b:19 (with obvious tiny errors because of YUV to RGB conversion for preview)
vkusnyashka
4th December 2019, 15:25
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/04/ce12df7018c304fba39a12c97d14d8c2.png :)
In AvsPmod the color matrix is determined based on the resolution of the clip, by default - https://i5.imageban.ru/out/2019/12/04/f69a8950a4033bd9d3ba7e8b1eb17255.png :rolleyes:
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.
_Al_
4th December 2019, 18:24
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.
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:
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
vkusnyashka
5th December 2019, 06:57
_Al_, thank you for the explanation.
With
rgb = core.resize.Point (clip, format = vs. RGB24, matrix_in_s = '470bg')
the colors are the same.
With
rgb = core.resize.Point (clip, format = vs. COMPATBGR32, matrix_in_s = '470bg')
error
vapoursynth.Error: Eval: only special filters may accept compat input
_________________
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
_Al_
5th December 2019, 17:16
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:
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.
vkusnyashka
6th December 2019, 06:57
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 :)
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.
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 https://i4.imageban.ru/out/2019/12/06/f36c68bcbf24505a11e83df3ef6bf98c.pnghttps://i2.imageban.ru/out/2019/12/06/0cf20c405ae7b7cb6e1408a9d5284298.png avs.set_output
Now I just replaced the line
avs = core.avsw.Eval("trim(0,0)", clips=[matrix], clip_names=["last"])
with the line
avs = core.std.Trim(matrix, 0, matrix.num_frames-1)
Screenshots:
avs_preview.set_output https://i6.imageban.ru/out/2019/12/06/1c833167a9dff2ad548436a69eabbbb1.pnghttps://i6.imageban.ru/out/2019/12/06/779b3a230d3b6e20f94974fdf43be4d9.png avs.set_output
I’m just wondering why in the first case I see color changes, but in the second I don’t see :confused: :)
poisondeathray
6th December 2019, 07:47
@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
_Al_
6th December 2019, 09:20
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):
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':
_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
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)
vkusnyashka
6th December 2019, 14:36
poisondeathray, thanks for the explanation!
_Al_, thank you too!
:thanks:
gmail123
3rd February 2023, 10:23
I plan to use the avs script Avisynth AiUpscale v1.2.0 within vs (https://forum.doom9.org/showthread.php?t=181665&highlight=aiupscale),but failed。
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。
gmail123
3rd February 2023, 10:25
but,my vs script(32bit avs dll) :
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:
[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'.
vBulletin® v3.8.11, Copyright ©2000-2025, vBulletin Solutions Inc.