Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using FFmpeg in .net?

Tags:

c#

video

ffmpeg

So I know its a fairly big challenge but I want to write a basic movie player/converter in c# using the FFmpeg library. However, the first obstacle I need to overcome is wrapping the FFmpeg library in c#. I've downloaded ffmpeg but couldn't compile it on Windows, so I downloaded a precompiled version for me. Ok awesome. Then I started looking for C# wrappers.

I have looked around and have found a few wrappers such as SharpFFmpeg (http://sourceforge.net/projects/sharpffmpeg/) and ffmpeg-sharp (http://code.google.com/p/ffmpeg-sharp/). First of all, I wanted to use ffmpeg-sharp as its LGPL and SharpFFmpeg is GPL. However, it had quite a few compile errors. Turns out it was written for the mono compiler, I tried compiling it with mono but couldn't figure out how. I then started to manually fix the compiler errors myself, but came across a few scary ones and thought I'd better leave those alone. So I gave up on ffmpeg-sharp.

Then I looked at SharpFFmpeg and it looks like what I want, all the functions P/Invoked for me. However its GPL? Both the AVCodec.cs and AVFormat.cs files look like ports of avcodec.c and avformat.c which I reckon I could port myself? Then not have to worry about licencing.

But I want to get this right before I go ahead and start coding. Should I:

  1. Write my own C++ library for interacting with ffmpeg, then have my C# program talk to the C++ library in order to play/convert videos etc.

OR

  1. Port avcodec.h and avformat.h (is that all i need?) to c# by using a whole lot of DllImports and write it entirely in C#?

First of all consider that I'm not great at C++ as I rarely use it but I know enough to get around. The reason I'm thinking #1 might be the better option is that most FFmpeg tutorials are in C++ and I'd also have more control over memory management than if I was to do it in c#.

What do you think? Also would you happen to have any useful links (perhaps a tutorial) for using FFmpeg?

like image 503
daniel Avatar asked Mar 27 '10 02:03

daniel


People also ask

Can you use FFmpeg in C#?

This FFmpegInterop component can be used as a template to utilize further functionality of the FFmpeg libraries. Moreover the FFmpegInterop object can be accessed by multiple programming languages including C#, CX/C++, and JavaScript.

How do you integrate FFmpeg?

Add the FFmpeg binary directory to the path. Click the New button to open a new blank line below the bottom-most path. Type C:\ffmpeg\bin . Or, if you placed the FFmpeg folder on a different drive or in a different folder, replace this path with that location instead (remember to leave \bin at the end). Click OK.


2 Answers

The original question is now more than 5 years old. In the meantime there is now a solution for a WinRT solution from ffmpeg and an integration sample from Microsoft.

like image 167
tobltobs Avatar answered Oct 03 '22 21:10

tobltobs


a few other managed wrappers for you to check out

  • FFMpeg.NET
  • FFMpeg-Sharp

Writing your own interop wrappers can be a time-consuming and difficult process in .NET. There are some advantages to writing a C++ library for the interop - particularly as it allows you to greatly simplify the interface that the C# code. However, if you are only needing a subset of the library, it might make your life easier to just do the interop in C#.

like image 43
Mark Heath Avatar answered Oct 03 '22 23:10

Mark Heath