简体   繁体   中英

FFMPeg Windows C# H264

I am trying to use SharpFFMpeg

http://sourceforge.net/projects/sharpffmpeg/

I found avcodec-52.dll and avformat-52.dll somewhere on the Net...

When I use SharpFFMpeg and make calls like av_init_packet

I get PInvoke errors like so

PInvokeStackImbalance was detected Message: A call to PInvoke function 'WpfApplicationFFMpegTest!FFmpegSharp.Interop.FFmpeg::av_init_packet' has unbalanced the stack. This is likely because the managed PInvoke signature does not match the unmanaged target signature. Check that the calling convention and parameters of the PInvoke signature match the target unmanaged signature.

In a nutshell I am trying to decode H264 and display the incoming stream from a camera...

Just wondering if anyone has been able to do this succesfully in C#?

Thanks

Sounds like invoke is trying to use the wrong calling convention. Needs to use __stdcall or __cdecl should work.

What Benjamin wants to say is that you should try to open the SharpFFmpeg sources and change inside AVFormat.cs the lines

[DllImport("avformat.dll"), SuppressUnmanagedCodeSecurity]
public static extern void av_init_packet(IntPtr pAVPacket);

into

[DllImport("avformat.dll", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
public static extern void av_init_packet(IntPtr pAVPacket);

and recompile the SharpFFmpeg project. I didn't test that, since I haven't the DLLs.

When this helps (av_init_packet disappears in the exception message), try to add CallingConvention.Cdecl on every PInvoke method.

Depending on whether your OS is 64 or 32 bit, you'll need to ensure that the stack is aligned to sufficiently large byte amounts to make this work.

On my 64bit Windows 7 computer, I can only use FFMpeg libraries in 64bit applications, which ensures the stack stays aligned to 16byte increments, resolving many of those problems.

I'm not sure how to solve your particular problem, but I hope this helps.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM