To extract the RAW image buffer from uncompressed v210 (with the pixel format kCVPixelFormatType_422YpCbCr10) I tried to execute this excellent post:
Reading samples through AVAssetReader
The problem is that when it comes to startReading my Reader resource , I got AVAssetReaderStatusFailed (with setting the NSMutableDictionary kCVPixelBufferPixelFormatTypeKey object to output the setting for kCVPixelFormatType_422YpCbCr10). If I leave outputSettings equal to zero, it parses every frame, but the CMSampleBufferRef buffers are empty.
I tried many pixel formats like
- kCVPixelFormatType_422YpCbCr10
- kCVPixelFormatType_422YpCbCr8
- kCVPixelFormatType_422YpCbCr16
- kCVPixelFormatType_422YpCbCr8_yuvs
- kCVPixelFormatType_422YpCbCr8FullRange
- kCVPixelFormatType_422YpCbCr_4A_8BiPlanar
but none of them work.
What am I doing wrong?
Any comments are welcome ...
Here is my code:
NSError *error=[[NSError alloc]init];
NSString *filePathString=[[NSString alloc]
initWithString:@"/Users/johann/Raw12bit.mov"];
NSURL *movieUrl=[[NSURL alloc] initFileURLWithPath:filePathString];
AVURLAsset *movieAsset=[[AVURLAsset alloc] initWithURL:movieUrl options:nil];
CGSize size=[movieAsset naturalSize];
NSLog(@"movie asset natual size: size.width=%f size.height=%f",
size.width, size.height);
AVAssetReader *assetReader=[[AVAssetReader alloc] initWithAsset:movieAsset
error:&error];
NSArray *videoTracks=[movieAsset tracksWithMediaType:AVMediaTypeVideo];
AVAssetTrack *videoTrack0=[videoTracks objectAtIndex:0];
NSMutableDictionary* dictionary=[NSDictionary dictionaryWithObjectsAndKeys:
[NSNumber numberWithInt:kCVPixelFormatType_422YpCbCr10],
(NSString*)kCVPixelBufferPixelFormatTypeKey,
nil];
AVAssetReaderTrackOutput* assetReaderOutput=[[AVAssetReaderTrackOutput alloc]
initWithTrack:videoTrack0
outputSettings:dictionary];
NSInteger i=0;
if([assetReader canAddOutput:assetReaderOutput]){
[assetReader addOutput:assetReaderOutput];
NSLog(@"asset added to output.");
if([assetReader startReading]==YES){
CMSampleBufferRef buffer;
while([assetReader status]==AVAssetReaderStatusReading){
buffer=[assetReaderOutput copyNextSampleBuffer];
i++;
NSLog(@"decoding frame #%ld done.", i);
}
}
else {
NSLog(@"could not start reading asset.");
NSLog(@"reader status: %ld", [assetReader status]);
}
}
else {
NSLog(@"could not add asset to output.");
}
Regards, Johann
source
share