iOS 14.3 AVAssetWriter produces full range color video
Originator: | cellsworth | ||
Number: | rdar://FB8934914 | Date Originated: | 2020-12-09 |
Status: | Open | Resolved: | |
Product: | AVFoundation | Product Version: | 14.3 |
Classification: | Unexpected behavior | Reproducible: | Yes |
A basic AVAssetReader/AVAssetWriter setup produces full color range video (yuvj420p(pc, bt709)) on iOS 14.3 and TV range video (yuv420p(tv, bt709)) on iOS 14.1. Is this expected behavior, and if so, is there a way to control this? --- AVAsset *const asset = [AVAsset assetWithURL:url]; AVAssetTrack *const videoTrack = [[asset tracksWithMediaType:AVMediaTypeVideo] firstObject]; NSError *error = nil; AVAssetReader *const assetReader = [AVAssetReader assetReaderWithAsset:asset error:&error]; XCTAssertNil(error); AVAssetWriter *const assetWriter = [AVAssetWriter assetWriterWithURL:outputUrl fileType:AVFileTypeMPEG4 error:&error]; XCTAssertNil(error); NSMutableDictionary *const compressionProperties = [NSMutableDictionary new]; compressionProperties[AVVideoAverageBitRateKey] = @(bitRate); if (profile) { compressionProperties[AVVideoProfileLevelKey] = profile; } AVAssetWriterInput *const input = [[AVAssetWriterInput alloc] initWithMediaType:AVMediaTypeVideo outputSettings:@{ AVVideoCodecKey: codec, AVVideoWidthKey: @(720), AVVideoHeightKey: @(1280), AVVideoCompressionPropertiesKey: compressionProperties, }]; input.transform = videoTrack.preferredTransform; AVAssetReaderOutput *const output = [[AVAssetReaderTrackOutput alloc] initWithTrack:videoTrack outputSettings:@{ (id)kCVPixelBufferPixelFormatTypeKey: @(kCVPixelFormatType_32BGRA), }]; [assetReader addOutput:output]; [assetWriter addInput:input]; XCTAssertNil(assetReader.error); XCTAssertNil(assetWriter.error); CFTimeInterval start = CACurrentMediaTime(); [assetReader startReading]; [assetWriter startWriting]; [assetWriter startSessionAtSourceTime:kCMTimeZero]; const dispatch_queue_t queue = dispatch_queue_create("transcode", DISPATCH_QUEUE_SERIAL); const dispatch_semaphore_t transcode = dispatch_semaphore_create(0); [input requestMediaDataWhenReadyOnQueue:queue usingBlock:^{ while ([input isReadyForMoreMediaData]) { const CMSampleBufferRef sampleBuffer = [output copyNextSampleBuffer]; XCTAssertNil(assetReader.error); XCTAssertNil(assetWriter.error); if (sampleBuffer) { [input appendSampleBuffer:sampleBuffer]; CFRelease(sampleBuffer); } else { [input markAsFinished]; dispatch_semaphore_signal(transcode); } } }]; dispatch_semaphore_wait(transcode, DISPATCH_TIME_FOREVER); const dispatch_semaphore_t write = dispatch_semaphore_create(0); [assetWriter finishWritingWithCompletionHandler:^{ dispatch_semaphore_signal(write); }]; XCTAssertNil(assetWriter.error); dispatch_semaphore_wait(write, DISPATCH_TIME_FOREVER);
Comments
Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!