使用视频工具箱在iOS 8中解码h264 [英] Decoding h264 in iOS 8 with video tool box

查看:217
本文介绍了使用视频工具箱在iOS 8中解码h264的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

需要解码h264流并获取像素缓冲区

Need to decode h264 stream and get the pixel buffers

我知道它可以在iOS 8上使用视频工具箱

I know its possible with video tool box on iOS 8

1.如何将h264流转换为 CMSampleBufferRef

1.How do I convert the h264 stream to CMSampleBufferRef ?

2.如何使用要解码的视频工具箱?

2.How do I use the video tool box to decode?

推荐答案

我假设您已经获得附件B格式的流,如果它已经是AVCC格式(阅读MP4),那么你可以使用AssetReader并且不需要做太多。

I assume you get the stream in Annex B format, if it is already in AVCC format (read MP4), then you can you the AssetReader and do not need to do much.

对于附件B流(这是ppl。通常称为原始h264流)。

For an Annex B stream (this is what ppl. often call raw h264 stream).


  1. 提取SPS / PPS NAL单位并从此创建参数集。你定期收到它们。它们包含用于解码帧应如何解码的信息。

  1. extract SPS/PPS NAL units and create a parameter set from then. You receive them periodically. They contain information for the decode how a frame is supposed to be decoded.

创建具有持续时间的TimingInfo数组(您可以从解析VUI部分获取它) SPS)和呈现时间戳和解码时间戳。如果以MPEG2 TS的形式接收流,则从PESr获取时间戳。如果不仅仅根据您的计算提供缺失信息。

create the TimingInfo Array with the duration (you can take it from parsing the VUI part of SPS) and presentation time stamp and decoding timestamp.Iif the stream is received as MPEG2 TS take the timestamps from the PESr. If not just supply missing info based on your calculations.

将VLC NAL单元包装在CMBlockBuffer中。你可以把多于一个。如果您通过RTP收到可能对NAL单元进行分段的流,请确保每个NAL单元都已完成。

Wrap the VLC NAL units in a CMBlockBuffer. You can put more then one into them. If you receive your stream over RTP that might fragment the NAL units make sure every NAL unit is complete.

将NAL单元包装在CMBlock缓冲区中时,请替换3 - 或带有长度标题的4字节起始码。

When wrapping the NAL unit in a CMBlockbuffer replace the 3- or 4-byte start code with a length header.

将信息提供给CMSampleBufferCreate,您可以在VTDecompressionSession中解码帧

Supply the information to CMSampleBufferCreate and you can decode the frame in VTDecompressionSession

WWDC提供了预设,可以更详细地解释这些步骤,并提供示例代码。

There is a presetation from WWDC available that explains these steps a bit more in detail ans also provide sample code.

这篇关于使用视频工具箱在iOS 8中解码h264的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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