c - Python SWIG bindings with SomeType ** as function argument -


i couldn't find working python bindings ffmpeg, decided generate 1 swig. generation quick , easy (no customization, default swig interface), these problem using functions int avformat_open_input(avformatcontext **ps, const char *filename, avinputformat *fmt, avdictionary **options); libavformat/avformat.h. using c can run by:

avformatcontext *pformatctx = null; int status; status = avformat_open_input(&pformatctx, '/path/to/my/file.ext', null, null); 

in python try following:

>>> ppmpeg import * >>> av_register_all() >>> formatctx = avformatcontext() >>> formatctx <ppmpeg.avformatcontext; proxy of <swig object of type 'struct avformatcontext *' @ 0x173eed0> > >>> avformat_open_input(formatctx, '/path/to/my/file.ext', none, none) traceback (most recent call last):    file "<stdin>", line 1, in <module> typeerror: in method 'avformat_open_input', argument 1 of type 'avformatcontext **' 

problem python not have & equivalent. tried use cpointer.i , pointer_class (%pointer_class(avformatcontext, new_ctx)), new_ctx() returns pointer , not want definitely. %pointer_class(avformatcontext *, new_ctx) illegal , gives syntax error. grateful help. thanks.

edit: forgot mention tried use typemaps, don't know how write custom typemap struct , documentation has examples basic types int or float...

that looks it's out parameter. that's necessary in c because c allows 1 return value, python allows multiple. swig lets mark argument output or inout should accomplish want. see this.

you can manually typemap. typemap lets specify arbitrary conversion.

for example, need in , argout typemaps described in typemap docs.

note since you're using custom datatypes need make sure headers declare struct included in generated .cpp. if swig doesn't take care of automatically put @ top of .i

// block gets copied verbatim header area of generated wrapper.  %{ #include "the_required_header.h" %} 

Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -