Log in

View Full Version : Python guru to help with calling directly the avisynth dll?


ShawnFumo
26th March 2005, 20:17
Hey.. a question for anyone more experienced with python than me. I'd pretty much decided on using wxPython to build a NLE on top of avisynth. At first I thought the best way to do it would just be to write out .avs files and load WMP as activex to preview it. But then it was pointed out to me that it'd be much more efficient to call avisynth.dll directly, since I wouldn't have to write out text files or reload the original video clip when changing filters.

My lack of experience with c wrapping and python in general is making this really hard for me though. I found ctypes for python, which lets you call a c dll directly. That meant I should be able to call either avisynth_c, or Myrsloik's c wrapper called asif:
http://kevin.atkinson.dhs.org/avisynth_c/
http://yatta.mellbin.org/asif.rar

Now it seems like I should be able to call those fine with ctypes, but my problem is getting the data structures worked out in python to send to and receive from the dll. I tried using the h2xml utility that comes with ctypes (which would be followed by xml2py), but can't get that to work. In asif, it gives an error about needing MSVC (I think because of the "__cdecl" in it). Then I tried grabbing the stdcall version of avisynth_c, but that errored out with no information to tell me what was wrong.

If I can just manage to get the python equivilant of asif.pas and asifadditions.pas in Myrsloik's package, I think I'd be set. As it stands now, though, I may be stuck embedding media player and reloading avs files. I think I'll be able to make that work ok, but it seems like calling avisynth directly would be a better solution in the end. I suppose I could also try writing my program in C++ with regular wxWidgets (no wrapping needed then), but wxPython seemed like a nice solution for building a GUI quickly (and I could also leverage the NLE OpenVIP, which was made in wxPython).

If anyone has any ideas, I'd be very thankful! It is just frustrating because I think I can make a useful app, but I'm really inexperienced with more low-level programming like this. If I can just get past these initial groundwork stages, I should be able to do the rest on my own...

Thanks!
Shawn

Bidoche
27th March 2005, 11:47
Well I have an idea :

Boost has a library to expose C++ objects to Python. (http://www.boost.org/libs/python/doc/index.html)
Maybe it could do the trick, by exposing a env wrapper...

vion11
28th March 2005, 14:18
Sometimes it is usefull to think about what
users expect from an application:

Let's say there is a long movie and user wants
to look complete movie with a simple effect
or something cutted, looped, trimmed or other
mainly 'realtime effects'. Here it doesn't matter
if clip and player is (re)loaded from nothing.
Just a few seconds against a complete movie.

Now user wants to define a frame for cutting,
or as an effect starting point. I this case
the preview window solution from latest AVSedit
is applicable. It may work with retrieving
bitmaps out of the avifile using winapi functions.
Nevertheless it will help gui developper when
this source gets released.

Next thing is more interesting. User has defined
a range of 10sec with a lot of time consuming effects
and wants a realtime preview. I like the After Effect
solution: it plays the movie first (slideshow) and
tells the user this is not realtime!
On top it buffers all frames and next time user plays
same range AE playes from buffer in realtime.
Of course there should be a timer controlled 'blitter'
to achieve correct fps.

All three cases can be realized without getting too deep
into avisynth, you will get lost there...... and another
plus you'll stay version independent.

ShawnFumo
28th March 2005, 22:00
bidoche:

Thanks for the link. That may very well be helpfull down the road. Good to know that sort of thing exists.

vion11:

Thanks much for the response. I think you're 100% right. That is actually more like my original train of thought, but I was starting to second-guess myself lately. I already know that I can embed WMP pretty easily and as you said, I can control speed by having a viewing area. Since the app is more focused on editing than adjusting real-time filters, I think I'll be ok. As far as specifying a cut point in a video, I think I can also just show the original clip and seek it for the display.

I think I'll also try to see how much I can keep in avs files. Instead of having a monolithic avs file for everthing, I think it'll be better if I have one (or even multiple ones) for each source video, which get imported into the final. The files for each clip could even import a project settings type file which resizes them all to the correct size. I think it'd be pretty interesting if I could have the program's file format be avs files with special comments for metadata or something. I'll have to see how practical that ends up being.

Thanks guys,
Shawn