NOTE. I assume you are using windows since you want to target .NET.
I have done this in the past. As far as I know, there is no complete .NET source code that you can use.
EDIT: OpenCV will not help you with your task. You can use OpenCV to display video (it uses FFMPEG internally). But you will not have access to the packages. Also hacking the FFMPEG library that comes with OpenCV is not easy to do, as it will be precompiled on Windows.
The path to action depends on your needs. However, if you need to work at the packet level, you will have to study the TS MPEG2 specification. Wikipedia is a good place to start, but in the end you will have to read the iso13818-1 specification and optionally iso13818-2. You can find copies of it online - just google. You can find some reference implementations in C / C ++ VLC, FFMPEG, libmpeg gstreamer (in bad plugins), however I can assure you that they are difficult to read and not very well documented. Also, writing a complete and reliable MPEG multiplexer or demultiplexer is a complex task requiring tedious examination of the documentation. There is a .NET tool called the MPEG-2 Transport Stream Packet Analyzer, written in .NET. It looks like a full implementation, but the code is not freely available - perhaps my author is ready to sell it to you. You can access it from http://www.pjdaniel.org.uk/mpeg/
Depending on your C / C ++ skills and programming skills, I recommend one of the following options:
- NO C / C ++ Skills, but very high programming skills. Or you just need to do basic work with packages:
Read the documents you need. - Good C / C ++ skills and patience for compiling FFMPEG with MinGW and reading other people's code:
Take FFMPEG (libavcodec) and take a look at the MpegTS implementation, write your hooks into it, and export simple C functions that you can interact with .NET.
I would recommend the second option if you do not need to do remuxing or other types of serious manipulations on the bit stream itself.
You should notice that given the complexity of the TS protocol, it is easier to manipulate using C / C ++ (which was done at the end after starting from C #) and inerop it with .NET.
I had to write my own demultiplex and multiplexer for a specific project that had very specific needs. It was not an easy task (all this took about 300 hours for the correct implementation), and as a result, the result was not as reliable as a commercial multiplexer or demultiplex from Elecard or MainConcept. However, products from the shelf will not do what we need. I wrote them in C ++ - used DirectShow (In C ++) to write the original filter decoded using Elecard (which worked better than MainConcept at that time) and wrote my own Renderer to display the actual video. The entire DirectShow chain was controlled using C # using interop.
Once you have chosen the path, you must make some other decisions, depending on what you do with the packages. If you want to send them to a decoder or multiplexer, you can use DirectShow to do this. You will have to put everything you do into a source filter, a filter filter, or a destination filter, depending on where you get the data. If you want to implement your filter in .NET, you can use "Pure.NET DirectShow Filters in C #". Maxim Kartavenkov form http://www.codeproject.com/Articles/421167/Pure-NET-DirectShow-Filters-in-Csharp . (Or buy the Elecard.NET SDK if you need commercial support). There are several link filters to get started, although you will also have to read the DirectShow documentation. If you just look at the packages, perhaps change them and write them, then you can write your own clean implementation for this or hack the mpegts libavcodec implementation, itβs not so difficult, just hours of fun figuring out whatβs happening is very instructive. libavcodec has a very clean interface, so you can easily return modified packages - you will also have to read the documents for this.
So I'm not sure you need the answer, but there is no easy way to what you want.