需要解码h264流并获取像素缓冲区
我知道在iOS 8上使用视频工具箱是可行的
1.如何将h264流转换为CMSampleBufferRef?
2.如何使用视频工具箱进行解码?
发布于 2014-10-01 17:34:47
我假设你得到了附件B格式的流,如果它已经是AVCC格式(阅读MP4),那么你就可以使用AssetReader了,不需要做太多的事情。
对于附件B流(这是ppl。通常称为原始h264流)。
WWDC提供了一个预设值,更详细地解释了这些步骤,并提供了示例代码。
发布于 2015-02-02 14:19:42
尝试将编码的CMSampleBufferRef转换为sampleBuffer。
if(!decompressionSession)
{
CMFormatDescriptionRef formatDescription=CMSampleBufferGetFormatDescription(sampleBuffer);
decompressionSession = NULL;
VTDecompressionOutputCallbackRecord callBackRecord;
callBackRecord.decompressionOutputCallback=didDecompress;
callBackRecord.decompressionOutputRefCon = (__bridge void *)self;
OSStatus status1= VTDecompressionSessionCreate(kCFAllocatorDefault, formatDescription, NULL, NULL, &callBackRecord, &decompressionSession);
}
else
{
VTDecodeFrameFlags flags = kVTDecodeFrame_EnableAsynchronousDecompression;
VTDecodeInfoFlags flagOut;
VTDecompressionSessionDecodeFrame(decompressionSession, sampleBuffer, flags, NULL, &flagOut);
VTDecompressionSessionWaitForAsynchronousFrames(decompressionSession);
}
Decompression all back
static void didDecompress( void *decompressionOutputRefCon, void *sourceFrameRefCon, OSStatus status, VTDecodeInfoFlags infoFlags, CVImageBufferRef imageBuffer, CMTime presentationTimeStamp, CMTime presentationDuration ){
if(status==noErr)
{
NSLog(@"SUCCESS PROCEED FROM HERE !!!!");
}
}//请记住,您提供了正确的演示时间,而encoding.Here我正在为您提供编码详细信息。
//ENCODING-------------------ENCODING---------------ENCODING
if(!_compression_session)
{
NSDictionary* pixelBufferOptions = @{
(NSString*) kCVPixelBufferWidthKey : @(widthOFCaptureImage),
(NSString*) kCVPixelBufferHeightKey : @(heightOFCaptureImage),
(NSString*) kCVPixelBufferOpenGLESCompatibilityKey : @YES,
(NSString*) kCVPixelBufferIOSurfacePropertiesKey : @{}};
_compression_session=NULL;
CFMutableDictionaryRef encoderSpecifications = NULL;
err = VTCompressionSessionCreate(
kCFAllocatorDefault,
widthOFCaptureImage,
heightOFCaptureImage,
kCMVideoCodecType_H264,
encoderSpecifications,
(__bridge CFDictionaryRef)pixelBufferOptions,
NULL,
compressionCallback,
(__bridge void *)self,
&_compression_session);
}
else
{
CMTime presentationTimeStamp = CMSampleBufferGetPresentationTimeStamp(sampleBufferIs);
CVPixelBufferRef pixelbufferPassing= CMSampleBufferGetImageBuffer(sampleBufferIs);
OSStatus status1= VTCompressionSessionEncodeFrame(_compression_session, pixelbufferPassing, presentationTimeStamp, kCMTimeInvalid, NULL, NULL, NULL);
VTCompressionSessionEndPass(_compression_session, NO, NULL);
}//编码回调
static void compressionCallback(void *outputCallbackRefCon,
void *sourceFrameRefCon,
OSStatus status,
VTEncodeInfoFlags infoFlags,
CMSampleBufferRef sampleBuffer ){
}//最好的祝福:)编码快乐:)
https://stackoverflow.com/questions/26012146
复制相似问题