AVAssetWriter提供蓝色视频文件

时间:2012-02-15 12:35:54

标签: iphone cocoa-touch avassetwriter

我正在使用AVAssetWriter类从我的应用程序屏幕重新编码视频。 视频记录。但重新编码的视频是蓝色的。 我设置AVAssetWriter的代码在

之下
-(BOOL) setUpWriter {
    NSError* error = nil;
    videoWriter = [[AVAssetWriter alloc] initWithURL:[self tempFileURL] fileType:AVFileTypeAppleM4V error:&error];
    NSParameterAssert(videoWriter);

    //Configure video
    NSDictionary* videoCompressionProps = [NSDictionary dictionaryWithObjectsAndKeys:
                                           [NSNumber numberWithDouble:1024.0*1024.0], AVVideoAverageBitRateKey,
                                           nil ];

    CGSize size=[CCDirector sharedDirector].winSize;
    NSDictionary* videoSettings = [NSDictionary dictionaryWithObjectsAndKeys:
                                   AVVideoCodecH264, AVVideoCodecKey,
                                   [NSNumber numberWithInt:size.width], AVVideoWidthKey,
                                   [NSNumber numberWithInt:size.height], AVVideoHeightKey,
                                   videoCompressionProps, AVVideoCompressionPropertiesKey,
                                   nil];

    videoWriterInput = [[AVAssetWriterInput assetWriterInputWithMediaType:AVMediaTypeVideo outputSettings:videoSettings] retain];

    NSParameterAssert(videoWriterInput);
    videoWriterInput.expectsMediaDataInRealTime = YES;
    NSDictionary* bufferAttributes = [NSDictionary dictionaryWithObjectsAndKeys:
                                      [NSNumber numberWithInt:kCVPixelFormatType_32ARGB], kCVPixelBufferPixelFormatTypeKey, nil];

    avAdaptor = [[AVAssetWriterInputPixelBufferAdaptor assetWriterInputPixelBufferAdaptorWithAssetWriterInput:videoWriterInput sourcePixelBufferAttributes:bufferAttributes] retain];

    //add input
    [videoWriter addInput:videoWriterInput];
    [videoWriter startWriting];
    [videoWriter startSessionAtSourceTime:CMTimeMake(0, 1000)];

    return YES;
}

我的代码中是否有任何错误。 我该如何解决这个问题

2 个答案:

答案 0 :(得分:3)

您的AVAssetWriterInput期待ARGB,但您可能正在为其提供RGBA。

那会看到可能的100%alpha被解释为蓝色而红色组件被丢弃,这可以解释你的蓝色色调。

很难说没有看到你的屏幕录制代码。

答案 1 :(得分:3)

可能问题是像素格式不正确,请尝试使用kCVPixelFormatType_32BGRA