H.264 over RTP - 标识SPS和PPS帧 [英] H.264 over RTP - Identify SPS and PPS Frames

查看:356
本文介绍了H.264 over RTP - 标识SPS和PPS帧的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有来自IP摄像机的原始H.264流包装在RTP帧中。我想把原始的H.264数据转换成一个文件,所以我可以用 ffmpeg 转换。

I have a raw H.264 Stream from an IP Camera packed in RTP frames. I want to get raw H.264 data into a file so I can convert it with ffmpeg.

我想把数据写入我的原始H.264文件,我发现它看起来像这样:

So when I want to write the data into my raw H.264 file I found out it has to look like this:

00 00 01 [SPS] 
00 00 01 [PPS]
00 00 01 [NALByte]
[PAYLOAD RTP Frame 1]     // Payload always without the first 2 Bytes -> NAL
[PAYLOAD RTP Frame 2]
[... until PAYLOAD Frame with Mark Bit received]  // From here its a new Video Frame
00 00 01 [NAL BYTE]
[PAYLOAD RTP Frame 1]
....

c $ c> SPS 以及会话描述协议中的 PPS RTSP 通信。此外,在开始视频流本身之前,摄像机在两个单独的消息中发送 SPS PPS

So I get the SPS and the PPS from the Session Description Protocol out of my preceding RTSP communication. Additionally the camera sends the SPS and the PPSin two single messages before starting with the video stream itself.

因此,我按照以下顺序捕获邮件:

So I capture the messages in this order:

1. Preceding RTSP Communication here ( including SDP with SPS and PPS )
2. RTP Frame with Payload: 67 42 80 28 DA 01 40 16 C4    // This is the SPS 
3. RTP Frame with Payload: 68 CE 3C 80                   // This is the PPS
4. RTP Frame with Payload: ...  // Video Data

然后有一些帧有效负载,在某些时候有一个RTP帧与标记位= 1 。这意味着(如果我得到它正确),我有一个完整的视频帧。为此,我再次从有效载荷写入前缀序列( 00 00 01 )和 NAL 相同的程序。

Then there come some Frames with Payload and at some point a RTP Frame with the Marker Bit = 1. This means ( if I got it right) that I have a complete video frame. Afer this I write the Prefix Sequence ( 00 00 01 ) and the NALfrom the payload again and go on with the same procedure.

现在,我的相机每8个完整的视频帧后发送给我 SPS PPS 。 (再次在两个RTP帧中,如上例所示)。我知道特别是 PPS 可以在流媒体之间改变,但这不是问题。

Now my camera sends me after every 8 complete Video Frames the SPS and the PPS again. ( Again in two RTP Frames, as seen in the example above ). I know that especially the PPS can change in between streaming but that's not the problem.

我的问题是:

1。我需要每第8个视频帧写SPS / PPS吗?

如果我的 SPS 我的 PPS 不更改它应该足够让他们写在我的文件的开头,没有什么?

If my SPS and my PPS don't change it should be enough to have them written at the very beginning of my file and nothing more?

2。如何区分SPS / PPS和正常的RTP帧?

在我的C ++代码中解析传输的数据,我需要在RTP帧正常有效载荷携带 SPS / PPS 的载荷。我如何区分他们?好的, SPS / PPS 帧通常较小,但这不是一个依赖的保存调用。因为如果我忽略它们我需要知道哪些数据我可以抛弃,或者如果我需要写他们我需要把 00 00 01 前缀在他们面前。 ?

In my C++ Code which parses the transmitted data I need make a difference between the RTP Frames with normal Payload an the ones carrying the SPS/PPS. How can I distinguish them? Okay the SPS/PPS frames are usually way smaller, but that's not a save call to rely on. Because if I ignore them I need to know which data I can throw away, or if I need to write them I need to put the 00 00 01 Prefix in front of them. ? Or is it a fixed rule that they occur every 8th Video Frame?

推荐答案


  1. 如果SPS和PPS不改变,你可以省略它们,除了第一个。

  2. 你需要解析每个NAL的nal_unit_type字段,SPS,nal_unit_type == 7;对于PPS,nal_unit_type == 8。

我记得,nal_unit_type是帧的第1个字节的低5位。 / p>

As I remember, nal_unit_type is the lower 5 bits of the 1st byte of a frame.

nal_unit_type = frame[0] & 0x1f;

这篇关于H.264 over RTP - 标识SPS和PPS帧的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆