View Full Version : vsavsreader -- AviSynth script reader for VapourSynth
Chikuzen
21st September 2012, 10:05
I wrote a VapourSynth (http://forum.doom9.org/showthread.php?t=165771) plugin a few days ago.
This plugin works as a source filter on VapourSynth.
you will be able to use avisynth filters which does not exist yet for VS(e.g. DirectShowSource) and has some compatibility issue like ColorMatrix() with this plugin.
vsavsreader-1.0.0.zip (https://github.com/chikuzen/VS_AvsReader/releases/tag/1.0.0)
requirement:
VapourSynth-r30 or later
AviSYnth2.6/avisynth+
Microsoft Visual C++ 2015 Redistributable Packages
tebasuna51
23rd September 2012, 10:41
I get this error when load the plugin:
Traceback (most recent call last):
File "Version.py", line 6, in <module>
c.avs.LoadPlugin(path=r'C:\Temp\Python\plugins\vsavsreader.dll')
File "vapoursynth.pyx", line 741, in vapoursynth.Function.__call__ (src/cython\vapoursynth.c:10611)
vapoursynth.Error: 'Avisynth Loader: no entry point found'
Same error with vsavsreader.dll in same folder and:
c.avs.LoadPlugin('vsavsreader.dll')
VS r8
AviSynth 2.6.0a3
XP SP3
tebasuna51
23rd September 2012, 18:09
Thanks. My mistake.
I copied other LoadPlugin without see the Readme.txt.
Chikuzen
27th September 2012, 13:41
updated for VS-r9
see first post.
Myrsloik
28th September 2012, 01:09
I looked at the source and spotted this small problem:
****vsapi->propSetInt(props, "_DurationNum", ah->avs_vi->fps_denominator * n, 0);
Should be
****vsapi->propSetInt(props, "_DurationNum", ah->avs_vi->fps_denominator, 0);
Chikuzen
28th September 2012, 07:20
fixed. :thanks:
Reel.Deel
1st October 2012, 12:24
Hi Chikuzen, thanks for this usefull plugin.
Since there are some plugins/scripts that can work with dither's lsb in/out.
I was wondering if would it be possible to add a function that can merge msb/lsb into a compatible YUVxxxP16 format?
Chikuzen
1st October 2012, 12:42
The clips loaded by vsavsreader could not be spliced. :scared:
I think that this is a VS's bug.
from vsstdlib.c
static int findCommonVi(const VSNodeRef **nodes, int num, VSVideoInfo *outvi, int ignorelength, const VSAPI *vsapi) {
int mismatch = 0;
int i;
const VSVideoInfo *vi;
*outvi = *vsapi->getVideoInfo(nodes[0]);
for (i = 1; i < num; i++) {
vi = vsapi->getVideoInfo(nodes[i]);
if (outvi->width != vi->width || outvi->height != vi->height) {
outvi->width = 0;
outvi->height = 0;
mismatch = 1;
}
if (outvi->format != vi->format) {
outvi->format = 0;
mismatch = 1;
}
if ((outvi->numFrames < vi->numFrames && outvi->numFrames) || (!vi->numFrames && outvi->numFrames)) {
outvi->numFrames = vi->numFrames;
if (!ignorelength)
mismatch = 1;
}
}
return mismatch;
}
Neither ”!=” nor "==" is used for comparison of two structs (http://stackoverflow.com/questions/141720/how-do-you-compare-structs-for-equality-in-c).
Chikuzen
1st October 2012, 12:44
Hi Chikuzen, thanks for this usefull plugin.
Since there are some plugins/scripts that can work with dither's lsb in/out.
I was wondering if would it be possible to add a function that can merge msb/lsb into a compatible YUVxxxP16 format?
use dither interleaved format.
stacked format is not supported.
clip = core.avsr.Import('foo.avs', bitdepth=16)
Myrsloik
1st October 2012, 12:49
I think that this is a VS's bug.
...
Neither ”!=” nor "==" is used for comparison of two structs (http://stackoverflow.com/questions/141720/how-do-you-compare-structs-for-equality-in-c).
You're probably on to something in there but that comparison is legal. It's pointer to struct,not struct.
Chikuzen
1st October 2012, 12:58
You're probably on to something in there but that comparison is legal. It's pointer to struct,not struct.
Then, is pointing out the same address right as for format of node[0] and format of node[1] ?
Myrsloik
1st October 2012, 13:03
I found the problem. You're never supposed to create a format struct yourself, you query it from the core.
format->id = table[i].id;
strcpy(format->name, table[i].name);
format->colorFamily = table[i].color_family;
format->bitsPerSample = ah->bitdepth;
format->bytesPerSample = (ah->bitdepth + 7) / 8;
format->subSamplingW = table[i].subsample_w;
format->subSamplingH = table[i].subsample_h;
format->numPlanes = avs_is_y8(ah->avs_vi) ? 1 : 3;
return format;
should simply be:
return vsapi->getFormatPreset(table[i].id, core);
The whole function set_vs_format() function can also be simplified to one call to vsapi->registerFormat()
something like:
return registerFormat(cmYuv/cmRgb/cmGray, stInteger, bitsPerSample, subSamplingW, subSamplingH, core);
If you register a duplicate a pointer to the already registered format struct will be returned. => the same format always has the same pointer so the comparison I make is valid.
Chikuzen
1st October 2012, 13:13
ok, I understood.
Since this plugin was written when the source code had not been opened yet, I was not using vsapi in the place which needs it.
Reel.Deel
1st October 2012, 13:21
use dither interleaved format.
stacked format is not supported.
clip = core.avsr.Import('foo.avs', bitdepth=16)
Did not know I could do that. Thanks Chikuzen.
* Edit *
Maybe it's not such a bad idea to add that information to the readme.
Chikuzen
1st October 2012, 14:10
fixed Splice issue.
please download fixed version from the link of first post.
I appreciate advice of Myrsloik.
Chikuzen
1st October 2012, 17:43
Maybe it's not such a bad idea to add that information to the readme.
I'm not good at english to write such complicated descriptions.
If you write them, I'll add them into the readme.
Reel.Deel
2nd October 2012, 13:05
I'm not good at english to write such complicated descriptions.
If you write them, I'll add them into the readme.
Sounds like a deal. I'll put something together in the next couple of days.
I wish my Japanese were half as good as your English. :D
* Edit *
Here's the description I wrote on how to import Dither's msb/lsb format into Vapoursynth.
I'm not an expert so I hope it makes sense.
VsAvsReader is able to convert Dither's interleaved MSB/LSB format into a compatible Vapoursynth YUV4xxP9/10/16 format.
Dither's MSB/LSB must be interleaved, stacked format is not supported.
Only YUV planar formats are allowed.
example 1: Use VsAvsReader's Import function to load external Avisynth script.
Vapoursynth script
# Core
import vapoursynth as vs
core = vs.Core(accept_lowercase=True)
# Import plugins
core.std.LoadPlugin('C:/vsavsreader.dll')
# Use "Import" to load interleaved MSB/LSB Avisynth script.
clip = core.avsr.Import('C:/script.avs', bitdepth=16)
External Avsiynth script being imported.
# script.avs
LoadPlugin("C:/plugins/DGDecode.dll")
LoadPlugin("C:/plugins/Dither.dll")
Import("C:/scriptss/Dither.avsi")
MPEG2Source("D:/source.d2v")
Dither_convert_8_to_16()
Dither_resize16(1280, 720)
Dither_convey_yuv4xxp16_on_yvxx()
_____________________________________________________________________
Example 2: Use VsAvsReader's Eval function to create Avisynth script inside a Vapoursynth script.
Vapoursynth script
# Core
import vapoursynth as vs
core = vs.Core(accept_lowercase=True)
# Import plugins
core.std.LoadPlugin('C:/vsavsreader.dll')
# Use "Eval" to create interleaved MSB/LSB Avisynth script.
lines = '''
LoadPlugin("C:/plugins/DGDecode.dll")
LoadPlugin("C:/plugins/Dither.dll")
Import("C:/scriptss/Dither.avsi")
MPEG2Source("D:/source.d2v")
Dither_convert_8_to_16()
Dither_resize16(1280, 720)
Dither_convey_yuv4xxp16_on_yvxx()
'''
video = core.avsr.Eval(lines=lines, bitdepth=16)
Chikuzen
5th October 2012, 05:58
@Reel.Deel
added :thanks:
Chikuzen
6th October 2012, 13:21
update
vsavsreader-d219012.7z (http://www.mediafire.com/download.php?su989bbxajhxfm8)
* change RGB plane order from G->B->R to R->G->B.
Chikuzen
16th November 2012, 02:30
update
download it from the link of first post.
* support alpha channel
If input avs is RGB32, alpha will be stored in "_Alpha" prop.
Myrsloik
16th November 2012, 02:36
update
download it from the link of first post.
* support alpha channel
If input avs is RGB32, alpha will be stored in "_Alpha" prop.
Actually the more proper way to do it to return two clips from the filter. See the avisource code for an example. The basic idea is that you call setvideoinfo(array of two videinfo, 2, core)
And then in the filter's getframe function you call getOutputIndex () to know which of the two clips you should output a frame for. Slightly more complicated to implement but it makes more sense. Or so I think.
Chikuzen
11th January 2013, 17:45
updated to vsavsreader-0.1.0
* add new option 'alpha'
* change alpha channel support method.
RTW47
15th October 2013, 12:21
then I use Eval() function:
import vapoursynth as vs
core = vs.get_core()
core.std.LoadPlugin(r'C:\Program Files\VapourSynth\filters\vsavsreader.dll')
avs = """
LoadPlugin("C:\Program Files\AviSynth 2.5\plugins\LSMASHSource.dll")
LWLibavVideoSource("D:\amv\10bit.mp4", format="YUV420P8")
#ConvertToRGB24(matrix = "Rec709")
"""
video = core.avsr.Eval(lines = avs)
video.set_output()
In Python shell I get this:
Python 3.3.2 (v3.3.2:d047928ae3f6, May 16 2013, 00:03:43) [MSC v.1600 32 bit (Intel)] on win32
Type "copyright", "credits" or "license()" for more information.
>>> ================================ RESTART ================================
>>>
Traceback (most recent call last):
File "C:\Users\Edgaras\Desktop\py\1_vsavsreader # 'Eval' Libav FAIL.py", line 9, in <module>
video = core.avsr.Eval(lines = avs)
File "vapoursynth.pyx", line 983, in vapoursynth.Function.__call__ (src\cython\vapoursynth.c:15542)
vapoursynth.Error: 'Eval:
failed to invoke \nLoadPlugin("C:\\Program Files\\AviSynth 2.5\\plugins\\LSMASHSource.dll")
\nLWLibavVideoSource("D:\x07mv\x08bit.mp4", format="YUV420P8")\n#ConvertToRGB24(matrix = "Rec709")\n'
>>>
then importing same .avs script(s) using vsavsreader's Import() function, then there's no error.
-vapoursynth r20 RC3
-avisynth 2.6 alpha 5
-vsavsreader 0.1.0
Reel.Deel
14th December 2014, 23:00
Dumb question:
If there was a 64-bit version of this plugin could it be used to load 32-bit AviSynth scripts in a 64-bit VapourSynth? I know piping allows using applications interchangeably but that may be something completely different.
Myrsloik
14th December 2014, 23:13
Dumb question:
If there was a 64-bit version of this plugin could it be used to load 32-bit AviSynth scripts in a 64-bit VapourSynth? I know piping allows using applications interchangeably but that may be something completely different.
No. Avisynth is loaded into the same process so it has to be 64bit too. You need a more elaborate wrapper that runs avisynth in a 32bit environment for it to work.
Reel.Deel
14th December 2014, 23:19
No. Avisynth is loaded into the same process so it has to be 64bit too. You need a more elaborate wrapper that runs avisynth in a 32bit environment for it to work.
Understood, sounds like it's something feasible though. Pity that Chikuzen is no longer around...
Myrsloik
16th December 2014, 11:34
Understood, sounds like it's something feasible though. Pity that Chikuzen is no longer around...
What remaining avisynth things do you need?
Reel.Deel
16th December 2014, 16:53
What remaining avisynth things do you need?
I don't have a very strong case here but DGDecNV and DGMPGDec are really hard to leave behind considering how good they've been to me. I know there's d2vsource but as we all know is still a work in progress. On the other hand DGDecNV also comes in 64-bit so I'm wondering if a 64-bit vsavareader would work with 64-bit AviSynth+?
In the meantime I'm using AVFS to create a fake avi and then loading it with VS.
Myrsloik
16th December 2014, 17:19
I don't have a very strong case here but DGDecNV and DGMPGDec are really hard to leave behind considering how good they've been to me. I know there's d2vsource but as we all know is still a work in progress. On the other hand DGDecNV also comes in 64-bit so I'm wondering if a 64-bit vsavareader would work with 64-bit AviSynth+?
In the meantime I'm using AVFS to create a fake avi and then loading it with VS.
Yes, it should work with 64bit avs+ as well. I guess.
Reel.Deel
16th December 2014, 17:25
Yes, it should work with 64bit avs+ as well. I guess.
Unfortunately I only have Microsoft Visual C++ 2010 Express so I guess I'm SOL when it comes to trying to compile a 64-bit vsavsreader.
TheFluff
16th December 2014, 17:47
Unfortunately I only have Microsoft Visual C++ 2010 Express so I guess I'm SOL when it comes to trying to compile a 64-bit vsavsreader.
http://www.visualstudio.com/en-us/products/visual-studio-community-vs
Reel.Deel
16th December 2014, 17:59
Visual Studio Community 2013 seems very nice for someone who does this on a regular basis. I've successfully compiled at most 10 avs plugins in the last 2 years. Also I read somewhere that Community version is a very large download/install compared to the express edition.
TheFluff
16th December 2014, 18:30
there's a difference between being unable to do a thing and being too lazy to do a thing
Reel.Deel
16th December 2014, 19:17
I don't like to be mean so I deleted my post...
Myrsloik
16th December 2014, 19:33
I'm just going to add that using vs avisource to open an avisynth script and (if necessary) fmtconv's 16 bit avisynth compatibility functions should work just as well.
I completely forgot that this plugin kinda is obsolete now because avisource exists.
Reel.Deel
16th December 2014, 21:18
Good point Myrsloik, I completely forgot about avisource also.
Myrsloik
29th December 2014, 14:10
I just do some experiments, and 64-bit VS AVISource seems to conflict with a avs script using 64-bit DGDecNV as the source filter, while VirtualDub x64 can preview that same avs script without problem. The 64-bit vspipe crashed immediately when opening the vpy script. Do you have a supported NVIDIA card to test?
No, I don't have nvidia stuff. It's probably some kind of threading issue since VapourSynth will use multiple threads to request frames from vfw. Especially when using vspipe.
Try using an mt version of avisynth and see if it helps.
Otherwise you're going to have to run it all in a debugger to see why it dies.
asarian
9th May 2016, 10:07
Vapoursynth script
# Core
>>> import vapoursynth as vs
>>> core = vs.Core(accept_lowercase=True)
# Import plugins
>>> core.std.LoadPlugin('C:/vsavsreader.dll')
# Use "Import" to load interleaved MSB/LSB Avisynth script.
>>> clip = core.avsr.Import('C:/script.avs', bitdepth=16)
External Avsiynth script being imported.
#script.avs
LoadPlugin("C:/plugins/DGDecode.dll")
LoadPlugin("C:/plugins/Dither.dll")
Import("C:/scripts/Dither.avsi")
MPEG2Source("D:/source.d2v")
Dither_convert_8_to_16()
Dither_resize16(1280, 720)
Dither_convey_yuv4xxp16_on_yvxx()
I guess I'm missing the way this is supposed to work:
clip = core.avsr.Import('C:/script.avs', bitdepth=16
This loads clip into VapourSynth, I get that much. :) But, typically, Dither() et al. are an end-filter deal for me, like:
clip = whatever (clip)
clip = something else (clip)
....
clip = core.avsr.Import('C:/script.avs', bitdepth=16)
I don't see how that last AVS line builds upon the last state of clip at all. Or am I really missing something?!
Thanks.
asarian
9th May 2016, 23:07
^^ Perhaps I should clarify this a bit:
#script.avs
LoadPlugin("C:/plugins/DGDecode.dll")
LoadPlugin("C:/plugins/Dither.dll")
Import("C:/scripts/Dither.avsi")
MPEG2Source("D:/source.d2v")
Dither_convert_8_to_16()
Dither_resize16(1280, 720)
Dither_convey_yuv4xxp16_on_yvxx()
The source in this imported AS script is just MPEG2Source, independently of what happened to 'clip' in your VS script thus far. I don't see how that is useful at all (except, maybe, when it's your first line in your VS script).
I'd just rather we'd be able to import/use Dither.avsi (and dll) itself, so you can use the Dither functions directly in VapourSynth. :) (Kinda makes me wonder whether Dither() even exists for 64-bit)
Reel.Deel
9th May 2016, 23:34
I'd just rather we'd be able to import/use Dither.avsi (and dll) itself, so you can use the Dither functions directly in VapourSynth. :) (Kinda makes me wonder whether Dither() even exists for 64-bit)
Why not just use fmtconv (http://forum.doom9.org/showthread.php?t=166504)? Also, zimg (http://forum.doom9.org/showthread.php?t=171334) was integrated into VapourSynth a while back. See documentation (http://www.vapoursynth.com/doc/functions/resize.html) for more information. As for MPEG2Source, use D2VSource (https://github.com/dwbuiten/d2vsource). Case closed :).
asarian
9th May 2016, 23:43
I am already using fmtconv. That wasn't really my point, though. Nor is the use of MPEG2Source (frankly, I don't care what source filter that avs script uses). I was merely contemplating the usefulness of vsavsreader, when the imported avs script uses its own source, from stratch, instead of building on what you have so far in your VapourSynth script.
Case reopened. :)
Reel.Deel
9th May 2016, 23:58
I am already using fmtconv. That wasn't really my point, though. Nor is the use of MPEG2Source (frankly, I don't care what source filter that avs script uses). I was merely contemplating the usefulness of vsavsreader, when the imported avs script uses its own source, from stratch, instead of building on what you have so far in your VapourSynth script.
Case reopened. :)
Sorry I missed your point, it wasn't really clear to me, still isn't. Anyways, vsavsreader was created in 2012 when VapourSynth had very limited use so this plugin helped to fill that void. Nowadays is kinda obsolete since most of the useful scripts and plugins have been ported to VapourSynth. Also VS can load AVS 2.6 plugins directly so... Hence why your the first person to post in this thread since Dec. 2014.
And don't forget about AviSource:
I'm just going to add that using vs avisource to open an avisynth script and (if necessary) fmtconv's 16 bit avisynth compatibility functions should work just as well.
I completely forgot that this plugin kinda is obsolete now because avisource exists.
asarian
10th May 2016, 00:03
Sorry I missed your point, it wasn't really clear to me, still isn't. Anyways, vsavsreader was created in 2012 when VapourSynth had very limited use so this plugin helped to fill that void. Nowadays is kinda obsolete since most of the useful scripts and plugins have been ported to VapourSynth. Also VS can load AVS 2.6 plugins directly so... Hence why your the first person to post in this thread since Dec. 2014.
And don't forget about AviSource:
Fair enough. :) I'm just going to go with the new stuff, I reckon. Didn't realize vsavsreader was that old, really.
Lynx_TWO
21st September 2018, 12:48
there's a difference between being unable to do a thing and being too lazy to do a thing
Oh man I wish there was a voting system in this forum. This is the comment of the decade, and I can personally attest to this. Another thing I wish we had was more time. Sleeping is such a time-suck!
Wilbert
21st September 2018, 13:14
Unfortunately I only have Microsoft Visual C++ 2010 Express so I guess I'm SOL when it comes to trying to compile a 64-bit vsavsreader.
* You need to install the Windows SDK 7.1 too and make it current.
* Your registry should have similar entries as here (but then for Windows SDK 7.1): https://web.archive.org/web/20140121132420/http://blogs.msdn.com/b/windowssdk/archive/2008/05/29/windows-sdk-registry-keys.aspx
Then you will be able to compile 64-bit stuff.
vBulletin® v3.8.11, Copyright ©2000-2025, vBulletin Solutions Inc.