如何在mp4中找到H264编解码器中的SPS和PPS字符串

时间:2013-07-09 06:10:29

标签: ffmpeg h.264 codec libavcodec smooth-streaming

众所周知,在Smooth Stream客户端清单文件中,视频标记中包含“CodecPrivateData”属性。在我初步调查之后,我发现这个字符串是使用SPS和PPS形成的,它们基本上是NAL单位。

我正在寻找一种从视频GOP中提取该信息的方法,以便我可以使用相同的方法创建清单文件并手动替换编解码器私有数据

基本上,我期待创建自定义应用程序以使用ffmpeg

创建平滑表示

1 个答案:

答案 0 :(得分:12)

请注意,SPS / PPS与mp4文件中的视频轨道分开存储在一个全局标题中(全局标题的avcC部分)。

这是格式:  每ISO / IEC 14496-10 8个字节

                 = long unsigned offset + long ASCII text string 'avcC'
                -> 1 byte version = 8-bit hex version  (current = 1)
                -> 1 byte H.264 profile = 8-bit unsigned stream profile
                -> 1 byte H.264 compatible profiles = 8-bit hex flags
                -> 1 byte H.264 level = 8-bit unsigned stream level
                -> 1 1/2 nibble reserved = 6-bit unsigned value set to 63
                -> 1/2 nibble NAL length = 2-bit length byte size type
                  - 1 byte = 0 ; 2 bytes = 1 ; 4 bytes = 3
                -> 1 byte number of SPS = 8-bit unsigned total
                -> 2+ bytes SPS length = short unsigned length
                -> + SPS NAL unit = hexdump
                -> 1 byte number of PPS = 8-bit unsigned total
                -> 2+ bytes PPS length = short unsigned length
                -> + PPS NAL unit = hexdump

如果您只想从单个.mp4中提取SPS / PPS,您可以使用十六进制编辑器并根据上面的MP4格式规范通过检查获取SPS / PPS(通过搜索结束查找“avcC”字符串的文件);然后将SPS / PPS字节添加到c样式数组供您使用。

否则,您可以将ffmpeg与h264bitstream实用程序一起使用来提取SPS / PPS。首先在命令行上运行ffmpeg以提取h264流:

ffmpeg -i my_funny_video.mp4 -vcodec copy -vbsf h264_mp4toannexb -an my_funny_video.h264

然后从h264bitstream实用程序运行h264_analyze:

h264_analyze my_funny_video.h264

将对您的SPS / PPS和其他NAL进行详细分析。