如何从H264 RTP数据包中检测I/P/B帧 [英] How to detect I/P/B frame from H264 RTP packet

查看:521
本文介绍了如何从H264 RTP数据包中检测I/P/B帧的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从RTSP流中获得了H264 RTP数据包.因此,我想检测框架是否为I框架. 下面是我从第一次开放流中获得的第一个数据包.因此,我相信这是一个I帧(我先向您展示160个字节).

I got H264 RTP packet from RTSP stream. So I want to detect whether the frame is I frame or not. And below is the first packet I got from the first time open stream. So I believe that it is a I-frame (I show you 160 bytes first).

packet:
00 00 00 01 67 4D 00 1F 95 A8 14 01 6E 40 00 00 00 01 68 EE 3C 80 00 00 00 01 06 E5 01 33 80 00 00 00 01 65 B8 00 00 08 52 90 9F F6 BE D6 C6 9C 3D F6 D4 2F 49 FB F7 13 F2 A9 C7 27 2D A4 75 59 6C DB FF 35 27 A4 C7 B6 E7 69 A2 E0 FB 0E FF 2D 0E E0 6F 25 43 78 BF B9 69 22 1B 24 E3 CA 60 56 44 16 6C 15 44 DA 55 29 C2 39 24 86 CE D6 75 BB E0 0C F4 F4 EC C5 76 E4 7B 59 B9 40 2D B3 ED 19 E4 1D 94 B7 54 9B B3 D0 8F 24 58 CD 3C F3 FA E0 D4 7D 88 70 0E 49 79 12 B2 14 92 BA B6 9C 3A F7 8D 13 78 6B 4C CD C0 CC C8 39 6A AC BE 3D AA 00 9A DB D2 68 70 5F C4 20 B7 5C FC 45 93 DB 00 12 9F 87 5A 66 2C B2 B8 E7 63 C4 87 0B A4 AA 2E 6D AB 42 3F 02 C2 A6 F9 41 E5 FE 80 64 49 14 38 3D 52 4B F6 B2 E7 53 DD 3E F6 BB A8 EB 13 23 BB 71 B1 C9 90 06 92 3E 5F 15 F2 C0 39 43 EA 24 5A 86 AE 11 27 D4 C5 4B 5C CD 6C 90 2B 44 80 18 76 95 6E 16 DF 5D 86 49 25 5A B6 66 23 E6 40 D4 25 6B CE A2 4C EE 13 DD 7B 88 FF A0 64 EC 33 44 B1 DC B7 0B 89 5B 8F 85 68 3C 65 3E 55 0F 41 4B 32 C9 C8 56 78 1A 15 14 8C C7 F5 17 40 D4 EC BC 5B 62 8A 24 66 6A C3 7E 3B DB 44 A8 EC D8 EE 37 E0 DE ...........

然后我使用下面的代码确定框架

Then I used the below piece of code to determine the frame

public static bool isH264iFrame(byte[] paket)
    {
        int RTPHeaderBytes = 0;

        int fragment_type = paket[RTPHeaderBytes + 0] & 0x1F;
        int nal_type = paket[RTPHeaderBytes + 1] & 0x1F;
        int start_bit = paket[RTPHeaderBytes + 1] & 0x80;

        if (((fragment_type == 28 || fragment_type == 29) && nal_type == 5 && start_bit == 128) || fragment_type == 5)
        {
            return true;
        }

        return false;
   }

我的问题是我无法确切地知道RTPHeaderByte的值.在这种情况下,我的数据包始终以"00 00 00 01"开头.

My problem is that I cannot know excactly the value of RTPHeaderByte. In this case my packets always start with "00 00 00 01".

谢谢 田沃

推荐答案

您将必须解析有效负载.请参阅SO答案序列/图片的可能位置H.264流的参数集.对于IDR,所有VCL NALU的类型均为5.对于B/P,您需要解析exp-golmb编码数据以找到分片类型.

You will have to parse the payload. see the SO answer Possible Locations for Sequence/Picture Parameter Set(s) for H.264 Stream. For IDR, all VCL NALUs will be type 5. As for B/P you will need to parse out the exp-golmb encoded data to find the slice type.

这篇关于如何从H264 RTP数据包中检测I/P/B帧的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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