简体   繁体   English

解码H264帧C#

[英]Decode H264 frames C#

I am using Managed Media Aggregation in C# - https://net7mma.codeplex.com/ . 我在C#中使用托管媒体聚合 - https://net7mma.codeplex.com/

I have a Rtsp Client that receives RTP Frames encoded in h264 (payload type 96). 我有一个Rtsp客户端接收以h264编码的RTP帧(有效负载类型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. 我做了一些阅读,我读到一个一个一个地解码h264帧的问题..并没有真正理解为什么。

Here is the method that is raised for each RTP frame that I receive 这是为我收到的每个RTP帧引发的方法

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? 有人可以解释为什么一个接一个地解码h264帧有问题吗?
  2. Is there a open source/library/dll for this? 是否有开源/库/ dll?

Thanks a lot! 非常感谢!

There is an included class in the RtspServer project. RtspServer项目中有一个包含的类。

The class is RFC6184Media, it contains methods for packetization and depacketiation and handles all defined Nal Unit types. 该类是RFC6184Media,它包含打包和解包的方法,并处理所有定义的Nal单元类型。

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. 在调用Depacketize后,有一个包含Raw Bit Stream Payload的Buffer,你必须添加一个由0x000001组成的起始码,然后是原始比特流中包含的数据。

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. 通常通过从Yuv到Rgb的转换分别对应于编码时使用的子采样。

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. 将来,如果你在项目页面上进行讨论,我可能会更快地完成它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM