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

Tar*_*run 3 ffmpeg codec h.264 libavcodec smooth-streaming

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

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

基本上,我期待使用ffmpeg创建自定义应用程序以创建流畅的表示

Aki*_*Aki 13

请注意,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
Run Code Online (Sandbox Code Playgroud)

如果你只是想从一个单一的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
Run Code Online (Sandbox Code Playgroud)

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

h264_analyze my_funny_video.h264
Run Code Online (Sandbox Code Playgroud)

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