Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to encode/decode video using C#?

Tags:

c#

.net

wpf

A little background, I was given the task of fixing a few "small" bugs and maintaining this solution for streaming video across the network between two instances of our application. The solution was written by someone who is no longer here so there is some mystery in the code as well as some really fun pitfalls. The solution was written using ffmpeg with C++ code written to wrap the encoding/decoding related code as well as some of the streaming code. This C++ was then wrapped with SWIG so that it could interop with C# and pass the video frames up where they are rendered using VideoRendererElement which lives in a WPF control. The main reason the frames are passed up is because we have some custom protocols we need to send video data over and those are written using C# so as the video frames are passed up we wrap them in our own packets and send them out on the wire. This solution works and we can stream video using our custom protocols though it is something of a nightmare to maintain and work with.

My question is there a better way to go about this? I'm looking for ways to work at a lower level with the video data (in C#) so that I can take the video frames and package them in our own packets and send them out and be able to receive and rebuild the video on the other side. ffmpeg seems to be the common solution but I've run into a lot of issues with it and the GPL/LGPL thing I think is a problem.

The basic flow I'm looking to achieve, video file -> encode -> wrap in packet -> send over wire on protocol X -> get video data from packet -> decode -> render / save to disk

like image 543
DH. Avatar asked Dec 02 '09 17:12

DH.


1 Answers

DirectShow is your friend. DirectShow is the low level layer used by most of the windows "multimedia" applications like Media Player, Audio Encoders, and so on.

Even if this library has been made for native developers you can access it from the managed world thanks to DirectShow.net. http://directshownet.sourceforge.net This is a well known and stable managed wrapper for DirectShow.

The only thing you have to do is to learn a little bit DirectShow to understand the concept of graphes and filters and then to create your own filters and graphes to use the power of DirectShow !

like image 77
PatriceVB Avatar answered Oct 25 '22 04:10

PatriceVB