Access MPEG Transport Packages via .NET

I have to deal with MPEG 2 transport packages using .NET. What is the best way to do this? I am currently considering using OpenCV for this, but not sure if this is possible.

+8
c # opencv mpeg mpeg-2
source share
5 answers

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.

+6
source share

You can find the traditional DirectShow filter development path more useful, for example, using this component package.

0
source share

SDP files are amazing. I don't know if you need to handle this at the package level, but I usually script from an SDP file. All the media players I've tested with - Windows Media, VLC, Quicktime - support them. Then, if you need to embed the media in a web page, form or entry, this can be easily achieved using apis for the corresponding player.

An SDP file conveys information about the container, encoding, and network that the player needs to capture the stream itself.

I spent a lot of time playing with direct shows until I realized that Windows Media Player is a good implementation and it will create all your filters based on the SDP file. This is pretty easy. Here is the specification:

http://www.ietf.org/rfc/rfc4566.txt

VLC also has a very good api for this kind of thing.

0
source share

I'm not sure if I fully understand your question, if you do .NET and capture MPEG packages and then you need to do some processing, OpenCV will be fine, but will suggest using Aforge.NET This will help you avoid writing hooks for OpenCV. It contains a wide range of video processing libraries and should be useful to you.

0
source share

http://net7mma.codeplex.com has a class for reading, among other types of container formats, mpeg and non mpeg.

All ts variations are also supported correctly, including atsc.

(De) Muxing from one to another will also be supported soon.

0
source share

All Articles