Видео с прозрачным фоном, созданное с помощью AVAssetWriterInputPixelBufferAdaptor, превращается в черный фон

Я создаю видео, захватывая изображения экрана с контекстом рендеринга каждые 0,01 секунды. Захваченные изображения с прозрачным фоном. Но при создании видео с этими изображениями с помощью AVAssetWritter, AVAssetWriterInputPixelBufferAdaptor его прозрачный фон становится черным.

Я использую следующий код: -

canvasAssetWriter = [[AVAssetWriter alloc] initWithURL:[self tempFileURL:@"output.mp4"] fileType:AVFileTypeQuickTimeMovie error:&error];

NSParameterAssert(canvasAssetWriter);

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

NSLog(@"System Version : %f WindowWidth : %f, windowHeight : %f",kSystemVersion,kWindowWidth,kWindowHeight);

NSDictionary* videoSettings = [NSDictionary dictionaryWithObjectsAndKeys:
                               AVVideoCodecH264, AVVideoCodecKey,
                               [NSNumber numberWithInt:(kSystemVersion < 8.0)?kWindowHeight:kWindowWidth], AVVideoWidthKey,
                               [NSNumber numberWithInt:(kSystemVersion < 8.0)?kWindowWidth:kWindowHeight], AVVideoHeightKey,
                               videoCompressionProps, AVVideoCompressionPropertiesKey,
                               nil];

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

NSParameterAssert(canvasVideoAssetWriterInput);
canvasVideoAssetWriterInput.expectsMediaDataInRealTime = NO;


NSDictionary* bufferAttributes = [NSDictionary dictionaryWithObjectsAndKeys:
                                  [NSNumber numberWithInt:kCMPixelFormat_32ARGB], kCVPixelBufferPixelFormatTypeKey, nil];

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

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

CVPixelBufferRef пиксельный буфер = NULL; CGImageRef cgImage = CGImageCreateCopy([capturedImage CGImage]);

            CFDataRef image = CGDataProviderCopyData(CGImageGetDataProvider(cgImage));


        pixelBuffer = [self pixelBufferFasterWithImage:cgImage];

            if(pixelBuffer !=nil)
            {
                // set image data into pixel buffer
                CVPixelBufferLockBaseAddress( pixelBuffer, 0 );
                uint8_t* destPixels = CVPixelBufferGetBaseAddress(pixelBuffer);
                CFDataGetBytes(image, CFRangeMake(0, CFDataGetLength(image)), destPixels);  //XXX:  will work if the pixel buffer is contiguous and has the same bytesPerRow as the input data

                BOOL success = [avAdaptor appendPixelBuffer:pixelBuffer withPresentationTime:time];

person Parminder Kaur    schedule 18.12.2015    source источник
comment
взломайте эту ссылку stackoverflow.com/ вопросы/23476605/   -  person Nikunj    schedule 18.12.2015
comment
Вы не можете записать видео H264 с альфа-каналом, хотя его можно прочитать с помощью обходного пути: stackoverflow.com/a/12128695/ 763355   -  person MoDJ    schedule 14.03.2016