5

我有以下 AVAssetWriterInputPixelBufferAdaptor:

NSMutableDictionary *attributes = [[NSMutableDictionary alloc] init];
[attributes setObject:[NSNumber numberWithUnsignedInt:kCVPixelFormatType_420YpCbCr8BiPlanarVideoRange] forKey:(NSString*)kCVPixelBufferPixelFormatTypeKey];
[attributes setObject:[NSNumber numberWithUnsignedInt:frameSize.width] forKey:(NSString*)kCVPixelBufferWidthKey];
[attributes setObject:[NSNumber numberWithUnsignedInt:frameSize.height] forKey:(NSString*)kCVPixelBufferHeightKey];

adaptor = [AVAssetWriterInputPixelBufferAdaptor assetWriterInputPixelBufferAdaptorWithAssetWriterInput:writerInput   sourcePixelBufferAttributes:attributes];

我正在尝试使用以下内容附加从 2 个平面(视频格式类型 kCVPixelFormatType_420YpCbCr8BiPlanarVideoRange)创建的像素缓冲区:

//Pixel buffer
CVPixelBufferRef buffer = NULL;

/*Pixel options*/
NSDictionary *options = [NSDictionary dictionaryWithObjectsAndKeys:
                       [NSNumber numberWithBool:YES],     kCVPixelBufferCGImageCompatibilityKey,
                       [NSNumber numberWithBool:YES], kCVPixelBufferCGBitmapContextCompatibilityKey,
                       nil]

void* planesAdress[2] = { (void*)firstFrameGray, (void*)firstFrameUV};
size_t planesWitdh[2] = {640, 320};
size_t planesHeight[2] = { 480, 240};
size_t planesBytesPerRow[2] = { 640, 640};


CVReturn retw = CVPixelBufferCreateWithPlanarBytes(kCFAllocatorDefault, 640, 480, kCVPixelFormatType_420YpCbCr8BiPlanarVideoRange, nil, nil, 2,planesAdress, planesWitdh, planesHeight, planesBytesPerRow, NULL, NULL, NULL, &buffer);

此时我可以检查缓冲区不为空并且 CVPixelBufferIsPlanar 为真。

但是每次我尝试附加缓冲区时,它都会为调用返回 NO(此调用仅用于第一帧)

[adaptor appendPixelBuffer:buffer withPresentationTime:kCMTimeZero];

错误是 Error Domain=AVFoundationErrorDomain Code=-11800 "操作无法完成" UserInfo=0x9ad800 {NSLocalizedFailureReason=发生未知错误 (-12780), NSUnderlyingError=0x9aa200 "操作无法完成。(OSStatus 错误 - 12780.)", NSLocalizedDescription=操作无法完成}

4

0 回答 0