Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Decode H264 frames C#

I am using Managed Media Aggregation in C# - https://net7mma.codeplex.com/.

I have a Rtsp Client that receives RTP Frames encoded in h264 (payload type 96). I want to be able to save the frames into a video file, and also be bale to tell when the video starts\ends.

I did some reading and I read that its a problem to decode h264 frames one-by-one.. didn't really understand why.

Here is the method that is raised for each RTP frame that I receive

void Client_RtpFrameChanged(object sender, Media.Rtp.RtpFrame frame)
{
    // Decode
}
  1. Can someone explain why its a problem to decode h264 frames one-by-one?
  2. Is there a open source/library/dll for this?

Thanks a lot!

like image 213
Ofek Agmon Avatar asked Nov 01 '22 17:11

Ofek Agmon


1 Answers

There is an included class in the RtspServer project.

The class is RFC6184Media, it contains methods for packetization and depacketiation and handles all defined Nal Unit types.

After you call Depacketize there is a Buffer which contains the Raw Bit Stream Payload, you will have to add a start code consisting of 0x000001 and then the data contained in the raw bitstream.

There are several examples in the Discussion area for the project.

After that you can feed the stream to a decoder for decoding and only then can the frames can be displayed; usually by conversion from Yuv to Rgb respective to the sub sampling used when encoding.

I can see about adding a small demo for a few static packets which corresponds to a frame and show how to achieve the desired result.

In the future if you make a discussion on the project page I will probably get to it much quicker.

like image 124
Jay Avatar answered Nov 08 '22 08:11

Jay