TheWommies
TheWommies

Reputation: 5072

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

Upvotes: 1

Views: 5196

Answers (3)

Myles Hathcock
Myles Hathcock

Reputation: 443

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.

Upvotes: 0

ulrichb
ulrichb

Reputation: 20044

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.

Upvotes: 3

J Benjamin
J Benjamin

Reputation: 4782

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

Upvotes: 3

Related Questions