動作する ffmpeg 用の Python バインディングが見つからなかったので、SWIG で生成することにしました。生成は迅速かつ簡単でした (カスタマイズはなく、デフォルトの SWIG インターフェイスのみ) が、 libavformat/avformat.h のような関数を使用すると問題が発生int avformat_open_input(AVFormatContext **ps, const char *filename, AVInputFormat *fmt, AVDictionary **options);
します。C を使用すると、次のように簡単に実行できます。
AVFormatContext *pFormatCtx = NULL;
int status;
status = avformat_open_input(&pFormatCtx, '/path/to/my/file.ext', NULL, NULL);
Pythonでは、次のことを試します:
>>> from ppmpeg import *
>>> av_register_all()
>>> FormatCtx = AVFormatContext()
>>> FormatCtx
<ppmpeg.AVFormatContext; proxy of <Swig Object of type 'struct AVFormatContext *' at 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 **'
問題は、Python に相当する & がないことです。cpointer.i
とそのpointer_class
( %pointer_class(AVFormatContext, new_ctx)
)を使用しようとしましたが、new_ctx()
ポインターが返され、これは確実に必要ではありません。%pointer_class(AVFormatContext *, new_ctx)
は違法であり、構文エラーが発生します。どんな助けにも感謝します。ありがとう。
編集: タイプマップを使用しようとしたことを忘れていましたが、構造体のカスタム タイプマップを記述する方法がわからず、ドキュメントには int や float などの基本的な型の例しかありません...