1
我一直在嘗試使用VTDecompressionSessionDecodeFrame解碼H264,但得到錯誤。參數集已被創建並且看起來很好,到目前爲止沒有任何錯誤,所以它可能與我對CMSampleBufferRef中定時信息的理解有關。任何投入將不勝感激VTDecompressionSessionDecodeFrame失敗,代碼爲-kVTVideoDecoderBadDataErr
void didDecompress(void *decompressionOutputRefCon, void *sourceFrameRefCon, OSStatus status, VTDecodeInfoFlags infoFlags, CVImageBufferRef imageBuffer, CMTime presentationTimeStamp, CMTime presentationDuration){
NSLog(@"In decompression callback routine");
}
void decodeH264 {
VTDecodeInfoFlags infoFlags;
[NALPacket appendBytes: NalPacketSize length:4];
[NALPacket appendBytes: &NALCODE length:1];
[NALPacket appendBytes: startPointer length:buflen];
void *samples = (void *)[NALTestPacket bytes];
blockBuffer = NULL;
// add the nal raw data to the CMBlockBuffer
status = CMBlockBufferCreateWithMemoryBlock(
kCFAllocatorDefault,
samples,
[NALPacket length],
kCFAllocatorDefault,
NULL,
0,
[NALPacket length],
0,
&blockBuffer);
const size_t * samplesizeArrayPointer;
size_t sampleSizeArray= buflen;
samplesizeArrayPointer = &sampleSizeArray;
int32_t timeSpan = 1000000;
CMTime PTime = CMTimeMake(presentationTime, timeSpan);
CMSampleTimingInfo timingInfo;
timingInfo.presentationTimeStamp = PTime;
timingInfo.duration = kCMTimeZero;
timingInfo.decodeTimeStamp = kCMTimeInvalid;
status = CMSampleBufferCreate(kCFAllocatorDefault, blockBuffer, YES, NULL, NULL, formatDescription, 1, 1, &timingInfo, 0, samplesizeArrayPointer, &sampleBuffer);
CFArrayRef attachmentsArray = CMSampleBufferGetSampleAttachmentsArray(sampleBuffer, true);
for (CFIndex i = 0; i < CFArrayGetCount(attachmentsArray); ++i) {
CFMutableDictionaryRef attachments = (CFMutableDictionaryRef)CFArrayGetValueAtIndex(attachmentsArray, i);
CFDictionarySetValue(attachments, kCMSampleAttachmentKey_DoNotDisplay, kCFBooleanFalse);
CFDictionarySetValue(attachments, kCMSampleAttachmentKey_DisplayImmediately, kCFBooleanTrue);
}
// I Frame
status = VTDecompressionSessionDecodeFrame(decoder, sampleBuffer, kVTDecodeFrame_1xRealTimePlayback, (void*)CFBridgingRetain(currentTime), &infoFlags);
if (status != noErr) {
NSLog(@"Decode error");
}
請您詳細說明一下嗎?我從VTDecompressionSessionDecodeFrame()獲得相同的返回值,但是我無法從您的評論中判斷出您需要做什麼來避免此錯誤返回。謝謝! – rpj 2014-10-14 00:34:54
不幸的是,我不能,這是我的一些嘗試和錯誤。我正在通過網絡解碼一個比特流,每當我得到一個新的nal單元並在一個採樣緩衝區中準備它時,我需要將先前使用的採樣緩衝區設置爲NULL。有趣的是,我已經停止使用VTDecompressionDecodeFrame,並使用AVSampleBufferDisplayLayer,它在你的應用程序的圖層中顯示H264的效果很好。 – Md1079 2014-10-14 11:29:19
聽起來像你的問題與幀緩衝區的內存管理有關,最終也是我的問題。謝謝你的提示! – rpj 2014-11-20 01:49:42