Iphone 提供蓝色视频文件的软件编写器

Iphone 提供蓝色视频文件的软件编写器,iphone,cocoa-touch,avassetwriter,Iphone,Cocoa Touch,Avassetwriter,我正在使用AVAssetWriter类从应用程序的屏幕上录制视频。 录像带。但录像带是蓝色的。 下面是我设置AVAssetWriter的代码 -(BOOL) setUpWriter { NSError* error = nil; videoWriter = [[AVAssetWriter alloc] initWithURL:[self tempFileURL] fileType:AVFileTypeAppleM4V error:&error]; NSParame

我正在使用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;
}
我的代码中有任何错误吗。
如何解决此问题

您的AVAssetWriterInput需要ARGB,但您可能正在为其提供RGBA

这将看到可能的100%阿尔法被解释为蓝色,而红色成分被丢弃,这将解释你的蓝色色调


如果看不到屏幕录制代码,很难判断。

您的AVAssetWriterInput需要ARGB,但您可能提供了RGBA

这将看到可能的100%阿尔法被解释为蓝色,而红色成分被丢弃,这将解释你的蓝色色调


如果看不到屏幕录制代码,很难判断。

可能问题出在不正确的像素格式上,尝试使用kCVPixelFormatType_32BGRA

可能问题出在不正确的像素格式上,尝试使用kCVPixelFormatType_32BGRA

是的,我想是的,我正在从openglview(COCOOS2D场景)查看图像,它是RGBA。其中我可以将ARGB更改为rgb。我已经更改了“NSDictionary*bufferAttributes=[NSDictionary Dictionary WithObjectsAndKeys:[NSNumber numberWithInt:kCVPixelFormatType_32ARGB],kCVPixelBufferPixelFormatTypeKey,nil];”到“NSDictionary*bufferAttributes=[NSDictionary Dictionary WithObjectsAndKeys:[NSNumber numberWithInt:kCVPixelFormatType_32RGBA],kCVPixelBufferPixelFormatTypeKey,nil];”它在“CFDataGetBytes(image,CFRangeMake(0,CFDataGetLength(image)),destPixels);”处崩溃这并不是那么简单-对于RGB iOS,AVFoundation更喜欢kCVPixelFormatType_32BGRA,因此在写入之前必须交换像素组件。如果您使用的是OpenGLES2,那么您可以使用GPU高效地“旋转”组件。这里的更多信息:得到了解决方案,刚刚将ARGB图像转换为RGBA图像。我是从紫色女孩亚那里得到这个想法的,我想是的,我是从openglview(cocos2d场景)中得到的超高图像,它是RGBA。其中我可以将ARGB更改为rgb。我已经更改了“NSDictionary*bufferAttributes=[NSDictionary Dictionary WithObjectsAndKeys:[NSNumber numberWithInt:kCVPixelFormatType_32ARGB],kCVPixelBufferPixelFormatTypeKey,nil];”到“NSDictionary*bufferAttributes=[NSDictionary Dictionary WithObjectsAndKeys:[NSNumber numberWithInt:kCVPixelFormatType_32RGBA],kCVPixelBufferPixelFormatTypeKey,nil];”它在“CFDataGetBytes(image,CFRangeMake(0,CFDataGetLength(image)),destPixels);”处崩溃这并不是那么简单-对于RGB iOS,AVFoundation更喜欢kCVPixelFormatType_32BGRA,因此在写入之前必须交换像素组件。如果您使用的是OpenGLES2,那么您可以使用GPU高效地“旋转”组件。这里的更多信息:得到了解决方案,刚刚将ARGB图像转换为RGBA图像。我是从紫色女孩那里得到这个主意的嗨,我试过你的密码,但是我有一个我不明白的问题。我的videoWriter成功完成,但在outputURL上找不到该文件。请帮帮我。avAdaptor是做什么的?嗨,我试过你的这个代码,但我有一个我不明白的问题。我的videoWriter成功完成,但在outputURL上找不到该文件。请帮帮我。avAdaptor做什么?