[英]Decoding H264 VideoToolkit API fails with Error -12911 in VTDecompressionSessionDecodeFrame
[英]Decoding H264 VideoToolkit API fails with Error -8971 in VTDecompressionSessionCreate
我正在尝试使用硬件支持的视频工具包解码器编写视频解码器。 但是,如果我尝试初始化解码会话,如下面发布的示例,我在调用VTDecompressionSessionCreate时收到错误-8971。 谁能告诉我这里做错了什么?
感谢你并致以真诚的问候,
奥利弗
OSStatus status;
int tmpWidth = sps.EncodedWidth();
int tmpHeight = sps.EncodedHeight();
NSLog(@"Got new Width and Height from SPS - %dx%d", tmpWidth, tmpHeight);
const VTDecompressionOutputCallbackRecord callback = { ReceivedDecompressedFrame, self };
status = CMVideoFormatDescriptionCreate(NULL,
kCMVideoCodecType_H264,
tmpWidth,
tmpHeight,
NULL,
&decoderFormatDescription);
if (status == noErr)
{
// Set the pixel attributes for the destination buffer
CFMutableDictionaryRef destinationPixelBufferAttributes = CFDictionaryCreateMutable(
NULL, // CFAllocatorRef allocator
0, // CFIndex capacity
&kCFTypeDictionaryKeyCallBacks,
&kCFTypeDictionaryValueCallBacks);
SInt32 destinationPixelType = kCVPixelFormatType_420YpCbCr8BiPlanarVideoRange;
CFDictionarySetValue(destinationPixelBufferAttributes,kCVPixelBufferPixelFormatTypeKey, CFNumberCreate(NULL, kCFNumberSInt32Type, &destinationPixelType));
CFDictionarySetValue(destinationPixelBufferAttributes,kCVPixelBufferWidthKey, CFNumberCreate(NULL, kCFNumberSInt32Type, &tmpWidth));
CFDictionarySetValue(destinationPixelBufferAttributes, kCVPixelBufferHeightKey, CFNumberCreate(NULL, kCFNumberSInt32Type, &tmpHeight));
CFDictionarySetValue(destinationPixelBufferAttributes, kCVPixelBufferOpenGLCompatibilityKey, kCFBooleanTrue);
// Set the Decoder Parameters
CFMutableDictionaryRef decoderParameters = CFDictionaryCreateMutable(
NULL, // CFAllocatorRef allocator
0, // CFIndex capacity
&kCFTypeDictionaryKeyCallBacks,
&kCFTypeDictionaryValueCallBacks);
CFDictionarySetValue(decoderParameters,kVTDecompressionPropertyKey_RealTime, kCFBooleanTrue);
// Create the decompression session
// Throws Error -8971 (codecExtensionNotFoundErr)
status = VTDecompressionSessionCreate(NULL, decoderFormatDescription, decoderParameters, destinationPixelBufferAttributes, &callback, &decoderDecompressionSession);
// release the dictionaries
CFRelease(destinationPixelBufferAttributes);
CFRelease(decoderParameters);
// Check the Status
if(status != noErr)
{
NSLog(@"Error %d while creating Video Decompression Session.", (int)status);
continue;
}
}
else
{
NSLog(@"Error %d while creating Video Format Descripttion.", (int)status);
continue;
}
我还偶然发现了kVTVideoDecoderBadDataErr
。 在我的情况下,我正在改变标头0x00000001
与NAL包的大小,其中包括此标头的4个字节,这就是原因。 我将大小更改为不包括这4个字节( frame_size = sizeof(NAL) - 4
)。 此大小应以big-endian编码。
您需要从SPS和PPS创建CMFormatDescriptionRef
CMFormatDescriptionRef decoderFormatDescription;
const uint8_t* const parameterSetPointers[2] = { (const uint8_t*)[currentSps bytes], (const uint8_t*)[currentPps bytes] };
const size_t parameterSetSizes[2] = { [currentSps length], [currentPps length] };
status = CMVideoFormatDescriptionCreateFromH264ParameterSets(NULL,
2,
parameterSetPointers,
parameterSetSizes,
4,
&decoderFormatDescription);
此外,如果您以附件B格式获取视频数据,则需要删除起始代码并将其替换为4字节大小信息,以便解码器将其识别为avcc格式化(这是CMVideoFormatDescriptionCreateFromH264ParameterSets的第5个参数) 。
@Joride
参见http://www.szatmary.org/blog/25
它解释了NALU中每个缓冲区的头(第一个)字节描述了缓冲区的类型。 您需要屏蔽这些位并将它们与提供的表进行比较。 请注意有关位字段的注释。 您需要使用0x1f将字节掩码为类型值。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.