获取H264Video流的尺寸 [英] Fetching the dimensions of a H264Video stream

查看:255
本文介绍了获取H264Video流的尺寸的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从H264流中获取尺寸(高度和宽度).我知道要从mpeg2流中获取相同的详细信息,您必须查看序列头起始码((01B3))之后的四个字节. H264可以使用相同的逻辑吗?希望得到我的任何帮助.

I am trying to fetch the dimensions (Height and width) from a H264 stream. I know that to fetch the same details from a mpeg2 stream you have to look at the four bytes following the sequence header start code ((01B3)). Will the same logic work for H264? Would appreciate any help I get..

推荐答案

否!

您必须运行复杂的函数才能从序列参数集"中提取视频尺寸.这该怎么做?首先,您必须编写自己的Exp-Golomb解码器,或者在线找到一个...在live555源代码中,例如在某个地方...

You must run a complex function to extract video dimensions from Sequence Parameter Sets. How to do this? Well first you must write your own Exp-Golomb decoder, or find one online... in live555 source code somewhere there is one for example...

然后,您必须获得一个SPS框架.它具有NAL=0x67(NAL是H.264帧中的第一个字节),您可以在sprop-parameter-sets下找到它作为SDP中Base64编码的字符串,它是第一个逗号之前的第一个Base64字符串.其他用逗号分隔的字符串还有图片参数集...这是SDP Z0KAKYiLQDIBL0IAAB1MAAK/IAg=中的一个SPS,您需要将类似的内容从Base64解码为字节数组.

Then you must get one SPS frame. It has NAL=0x67 (NAL is the first byte in a H.264 frame) and you can find it as Base64 encoded string in SDP under sprop-parameter-sets its the first Base64 string before the first comma. Other comma separated strings there are Picture Parameter Sets... This is one SPS from SDP Z0KAKYiLQDIBL0IAAB1MAAK/IAg= you need to decode something like this from Base64 into a byte array.

然后,您必须提取RAW BYTE SEQUENCE有效载荷,然后在该字节数组中提取NAL UNIT HEADER !!!它通常是一个字节长,但请确保继续阅读... RBSP包含运行seq_parameter_set_data( )函数所需的字节.因此,您需要先剥离NAL UNIT HEADER(一个或多个字节).

Then you must extract RAW BYTE SEQUENCE PAYLOAD that is followed by NAL UNIT HEADER in that byte array!!! It is usually one byte long, but read on just to be sure... RBSP contains the bytes needed to run the seq_parameter_set_data( ) function. So you need to strip off the NAL UNIT HEADER first (one or more bytes).

这里是从SPS NAL UNIT提取RBSP字节的功能:

Here it is the function that extracts RBSP bytes from SPS NAL UNIT:

然后,当您拥有SPS(RBSP字节)时,您需要执行解析此字节数组中的位的功能.这是其中解析了所有参数的函数(可以在此处找到整个文档:

Then when you have SPS (RBSP bytes) you need to perform a function that parses bits in this byte array. Here's the function with all the parameters parsed there (whole document can be found here: http://www.itu.int/rec/T-REC-H.264-201003-I/en and its free):

您会看到一些奇怪的东西...首先,视频尺寸的计算如下:

There you can see some strange stuff... first, your video dimensions are calculated like this:

Width = ((pic_width_in_mbs_minus1 +1)*16) - frame_crop_right_offset*2 - frame_crop_left_offset*2;
Height = ((2 - frame_mbs_only_flag)* (pic_height_in_map_units_minus1 +1) * 16) - (frame_crop_top_offset * 2) - (frame_crop_bottom_offset * 2);

此代码表的DESCRIPTOR列中的第二个也是最重要的一点是,应说明如何读取第一列中的粗体文本参数.这就是其中的值的意思:

Second, and most important, in DESCRIPTOR column of this code table, is stated what you should do to read the bold text parameter in the first column. This is what values in there mean:

  • u(N)-读取N位长的无符号数字
  • s(N)-读取一个N位长的带符号数字
  • ue(v)-读取未签名的Exp-Golomb编号(v表示可变长度,因此与ue()相同)
  • se(v)-读取签名的Exp-Golomb号码
  • u(N) - Read an unsigned number which is N bits long
  • s(N) - Read a signed number which is N bits long
  • ue(v) - Read an unsigned Exp-Golomb number (v is for variable length, so its same as ue())
  • se(v) - Read a signed Exp-Golomb number

这是您的Exp-Golomb解码器派上用场的地方...

This is where your Exp-Golomb decoder comes in handy...

因此,实现此功能,解析SPS,您将获得Width和Height.享受...:)

So, implement this function, parse SPS, and you will get your Width and Height. Enjoy... :)

这篇关于获取H264Video流的尺寸的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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