有一组使用.NET的的P / Invoke声明FFmpeg的,libavutil文件libavformat和libav codeC的? [英] Is there a set of working P/Invoke declarations for FFMpeg, libavutil, libavformat and libavcodec in .NET?

查看:285
本文介绍了有一组使用.NET的的P / Invoke声明FFmpeg的,libavutil文件libavformat和libav codeC的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在访问libavutil,从.NET了libavformat和libav codeC(FFmpeg中的一部分)。

I'm currently looking to access libavutil, libavformat and libavcodec (all part of FFMpeg) from .NET.

目前,我收到从自动化的库建立晚上Windows 32位。

Currently, I'm getting the libraries from the automated builds of the shared FFMpeg package performed every night for Windows 32-bit.

我还使用了code从 ffmpeg的锐利项目。在这个项目中,我已删除了一些类,没有编译(它们是包装类不是的P / Invoke的声明)。

I am also using the code from the ffmpeg-sharp project. In that project, I have removed a number of classes that were not compiling (they are wrapper classes not the P/Invoke declarations).

在code编译好,但我遇到的几个问题。

The code compiles fine, but I am running into a few issues.

首先,看来AV的构建* .dll文件使用 cdecl调用约定,因为我收到了许多 PInvokeStackImbalanceException 试图调用<当href="http://cekirdek.uludag.org.tr/~ismail/ffmpeg-docs/avformat_8h.html#9baec525f6e67ca07ce289a55cc60589"相对=nofollow> av_open_input_file 。这是很容易改变,以得到它的工作的权利。该 AVFormatContext 结构填充。

First, it appears that the build of av*.dll uses the cdecl calling convention, as I was receiving a number of PInvokeStackImbalanceException when trying to call av_open_input_file. This was easy enough to change to get it to work right. The AVFormatContext structure is populated.

在这之后,我想打电话给<一个href="http://cekirdek.uludag.org.tr/~ismail/ffmpeg-docs/avformat_8h.html#db71739e723184582491854960a5cb61"相对=nofollow> av_find_stream_info ,以获取有关文件中的数据流的信息。但是,打电话时,与 AVFormatContext 从通话中检索到 av_open_input_file ,一个 AccessViolationException 被抛出,表明我想读取或从受保护的内存写入。

After that, I want to call av_find_stream_info to get information about the streams in the file. However, when calling that with the AVFormatContext retrieved from the call to av_open_input_file, an AccessViolationException is thrown indicating that I am trying to read or write from protected memory.

用过的P / Invoke人通过P / Invoke来访问libavutil文件libavformat和libav codeC DLL库,并已经得到了它的工作?

Has anyone used P/Invoke to access the libavutil, libavformat and libavcodec dll libraries through P/Invoke and have gotten it to work?

我要指出,与FFmpeg中的命令行版本的工作,而一个解决方案,是不是在这种情况下,一个可行的解决方案,访问都必须通过该库。这样做的原因是,我不得不鞭打盘太多做我需要做的(我必须做一些非常高清晰度视频一帧一帧的分析),我想避免磁盘尽可能

I should mention that working with the command-line version of FFMpeg, while a solution, is not a viable solution in this case, access needs to occur through the libraries. The reason for this is that I'd have to thrash the disk way too much to do what I need to do (I have to do a frame-by-frame analysis of some very high definition video) and I want to avoid the disk as much as possible.

推荐答案

这是我想通了 - 即P的量好/调用在FFmpeg锐项目的声明是不正确的。也有他们使用结构中,封送回来声明的地方好一些,但后来,必须传入以后释放程序。

This is what I figured out - namely, a good amount of the P/Invoke declarations in the ffmpeg-sharp project are incorrect. There are a good number of places where they use structures in the declaration which are marshaled back, but subsequently, have to be passed to deallocation routines later.

由于指针已经失去了作为编组的一部分,这是什么造成的 AccessViolationException 努力的stucture传递到正在接受一个有效的指针(如Windows中的手柄)等方法时抛出。而不是把它们当作不透明的(他们应该,如Windows的API做),他们元帅的结构回来,失去了指针的过程中。

Because the pointer has been lost as part of the marshaling, this is what was causing the AccessViolationException to be thrown when trying to pass that stucture to other methods that are accepting a valid pointer (like a handle in Windows). Instead of treating them as opaque (as they should, like Windows APIs do) they marshal the structures back and lose the pointer in the process.

解决的办法是改变他们的API声明采取/返回的 的IntPtr ,并根据需要,不包括他们在P进行结构编组/ Invoke的声明。

The solution is to change their API declarations to take/return an IntPtr and perform marshaling of the structures as needed, not to include them in the P/Invoke declarations.

这篇关于有一组使用.NET的的P / Invoke声明FFmpeg的,libavutil文件libavformat和libav codeC的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆