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

查看:17
本文介绍了获取 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..

推荐答案

NO!!!

您必须运行复杂的函数才能从序列参数集中提取视频维度.这个怎么做?那么首先你必须编写你自己的 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 帧中的第一个字节),您可以在 SDP 中的 sprop-parameter-sets 下找到它作为 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 PAYLOAD 后跟 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 字节)时,你需要执行一个函数来解析这个字节数组中的位.这是解析所有参数的函数(整个文档可以在这里找到:http://www.itu.int/rec/T-REC-H.264-201003-I/en 及其免费):

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,你就会得到你的宽度和高度.享受... :)

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

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

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