View Full Version : using VapourSynth in .NET application
stax76
14th June 2015, 11:11
Hello,
I'm a bit disappointed by the fact that I cannot use QTGMC with AviSynth+ x64, not even single threaded is usable because of the frame drop problem. I want to support VapourSynth in StaxRip as alternative to AviSynth but have some problem. I use VFW avifile API like so:
AVIFileInit()
Sourcefile = path
Const OF_SHARE_DENY_WRITE = 32
If AVIFileOpen(AviFile, path, OF_SHARE_DENY_WRITE, IntPtr.Zero) <> 0 Then
Throw New Exception("AVIFileOpen failed")
End If
If AVIFileGetStream(AviFile, AviStream, mmioStringToFOURCC("vids", 0), 0) <> 0 Then 'FourCC for vids
Throw New Exception("AVIFileGetStream failed")
End If
FrameCountValue = AVIStreamLength(AviStream)
If FrameCountValue = 240 Then
Dim o = Marshal.GetObjectForIUnknown(AviFile)
If Not o Is Nothing Then
Dim i = CType(o, IAvisynthClipInfo)
If Not i Is Nothing Then
Dim ptr As IntPtr
If i.GetError(ptr) = 0 Then
ErrorMessageValue = Marshal.PtrToStringAnsi(ptr)
End If
Marshal.ReleaseComObject(i)
End If
End If
Else
ErrorMessageValue = Nothing
End If
StreamInfo = New _AVISTREAMINFO()
If AVIStreamInfo(AviStream, StreamInfo, Marshal.SizeOf(StreamInfo)) <> 0 Then
Throw New Exception("AVIStreamInfo failed")
End If
Problem with VapourSynth is apparently it cannot return RGB which I need for .NET drawing, it would be useful if both AviSynth and VapourSynth could return RGB even if the script isn't RGB, as the code above shows I can get a AviSynth COM+ interface from the avifile API. Am I right to assume AviSynth and VapourSynth could easily provide a interface allowing to config the color space to return? The reason why I prefer VFW is it's lightweight without need for a wrapper DLL.
Myrsloik
14th June 2015, 12:12
Hello,
I'm a bit disappointed by the fact that I cannot use QTGMC with AviSynth+ x64, not even single threaded is usable because of the frame drop problem. I want to support VapourSynth in StaxRip as alternative to AviSynth but have some problem. I use VFW avifile API like so:
AVIFileInit()
Sourcefile = path
Const OF_SHARE_DENY_WRITE = 32
If AVIFileOpen(AviFile, path, OF_SHARE_DENY_WRITE, IntPtr.Zero) <> 0 Then
Throw New Exception("AVIFileOpen failed")
End If
If AVIFileGetStream(AviFile, AviStream, mmioStringToFOURCC("vids", 0), 0) <> 0 Then 'FourCC for vids
Throw New Exception("AVIFileGetStream failed")
End If
FrameCountValue = AVIStreamLength(AviStream)
If FrameCountValue = 240 Then
Dim o = Marshal.GetObjectForIUnknown(AviFile)
If Not o Is Nothing Then
Dim i = CType(o, IAvisynthClipInfo)
If Not i Is Nothing Then
Dim ptr As IntPtr
If i.GetError(ptr) = 0 Then
ErrorMessageValue = Marshal.PtrToStringAnsi(ptr)
End If
Marshal.ReleaseComObject(i)
End If
End If
Else
ErrorMessageValue = Nothing
End If
StreamInfo = New _AVISTREAMINFO()
If AVIStreamInfo(AviStream, StreamInfo, Marshal.SizeOf(StreamInfo)) <> 0 Then
Throw New Exception("AVIStreamInfo failed")
End If
Problem with VapourSynth is apparently it cannot return RGB which I need for .NET drawing, it would be useful if both AviSynth and VapourSynth could return RGB even if the script isn't RGB, as the code above shows I can get a AviSynth COM+ interface from the avifile API. Am I right to assume AviSynth and VapourSynth could easily provide a interface allowing to config the color space to return? The reason why I prefer VFW is it's lightweight without need for a wrapper DLL.
I'd really suggest you spend the time to use the interfaces directly because it's very simple to add a conversion at the end in both avisynth and vapoursynth that way.
Or simply save a modified version of the script with an rgb conversion at the end.
vs.set_output(vs.get_output().resize.Bicubic(format... ))
Open with that with vfw instead...
stax76
14th June 2015, 14:39
I get an error from IAvisynthClipInfo:
'VFW module doesn't support RGB24 output'
script looks OK, VapourSynth Editor preview works
import vapoursynth as vs
core = vs.get_core()
ret = core.ffms2.Source(source="E:\Samples\MKV\DTS-MA - PGS.mkv")
ret = ret.resize.Bicubic(format=vs.RGB24)
ret.set_output()
Myrsloik
14th June 2015, 15:28
I get an error from IAvisynthClipInfo:
'VFW module doesn't support RGB24 output'
script looks OK, VapourSynth Editor preview works
import vapoursynth as vs
core = vs.get_core()
ret = core.ffms2.Source(source="E:\Samples\MKV\DTS-MA - PGS.mkv")
ret = ret.resize.Bicubic(format=vs.RGB24)
ret.set_output()
You want COMPATBGR32 as the output format.
stax76
14th June 2015, 17:29
Thanks, works like a charm so far. Can ffmpeg open vpy? Would be handy I could use it for piping.
LoRd_MuldeR
14th June 2015, 17:44
Thanks, works like a charm so far. Can ffmpeg open vpy? Would be handy I could use it for piping.
Why not simply use vspipe.exe that ships with VapourSynth?
stax76
14th June 2015, 19:24
Why not simply use vspipe.exe that ships with VapourSynth?
It's a bit extra work, it helps however that it's included with VapourSynth.
captainadamo
14th June 2015, 19:27
it would be useful if both AviSynth and VapourSynth could return RGB even if the script isn't RGB
No, that would actually be a terrible idea. Neither should be doing such a conversion unless it's explicitly asked for.
stax76
14th June 2015, 20:05
No, that would actually be a terrible idea. Neither should be doing such a conversion unless it's explicitly asked for.
I thought if I can get a interface with error info then it would be nice if there would be a interface exposing some more features like the possibility to config the output color space.
I know that everybody is thinking I should give up VFW, main problem is that there is work involved, easily 1-2 days, possibly more since I'm clumsy in C++. Also I prefer a pure managed solution over a unmanaged wrapper DLL.
captainadamo
14th June 2015, 21:21
I know that everybody is thinking I should give up VFW, main problem is that there is work involved, easily 1-2 days, possibly more since I'm clumsy in C++. Also I prefer a pure managed solution over a unmanaged wrapper DLL.
Or you could use a tool (http://www.swig.org/index.php) to do the work for you.
Myrsloik
14th June 2015, 21:28
I thought if I can get a interface with error info then it would be nice if there would be a interface exposing some more features like the possibility to config the output color space.
I know that everybody is thinking I should give up VFW, main problem is that there is work involved, easily 1-2 days, possibly more since I'm clumsy in C++. Also I prefer a pure managed solution over a unmanaged wrapper DLL.
You don't need a wrapper dll to use vapoursynth, you can use it directly since the api is pure C. See this as an opportunity for self-improvement.
captainadamo
14th June 2015, 22:43
You don't need a wrapper dll to use vapoursynth, you can use it directly since the api is pure C. See this as an opportunity for self-improvement.
Yeah, it's really not that hard. Using SWIG to generate the P/Invoke calls I wrote a simple .NET app to call the Vapoursynth API in less than an hour just as an experiment. And it was using way less code than the VfW wrapper code that stax posted above.
stax76
14th June 2015, 23:16
Or you could use a tool (http://www.swig.org/index.php) to do the work for you.
interesting, never heard of it
You don't need a wrapper dll to use vapoursynth, you can use it directly since the api is pure C. See this as an opportunity for self-improvement.
good to know there is a pure C API
vBulletin® v3.8.11, Copyright ©2000-2026, vBulletin Solutions Inc.