gpt4 book ai didi

objective-c - AVFoundation:从 mov 文件中读取 RAW 单帧(v210,未压缩的 10 位 4:2:2)

转载 作者:太空狗 更新时间:2023-10-30 03:54:14 26 4
gpt4 key购买 nike

为了从未压缩的 v210(像素格式为 kCVPixelFormatType_422YpCbCr10)中提取 RAW 图像缓冲区,我尝试关注这个很棒的帖子: Reading samples via AVAssetReader

问题是,当涉及到我的assetReaderstartReading 时,我得到了一个AVAssetReaderStatusFailed(为输出设置NSMutableDictionary 对象kCVPixelBufferPixelFormatTypeKey设置为 kCVPixelFormatType_422YpCbCr10)。如果我将 outputSettings 设为 nil,它会解析每一帧,但 CMSampleBufferRef 缓冲区为空。

我尝试了很多像素格式,例如

  • kCVPixelFormatType_422YpCbCr10
  • kCVPixelFormatType_422YpCbCr8
  • kCVPixelFormatType_422YpCbCr16
  • kCVPixelFormatType_422YpCbCr8_yuvs
  • kCVPixelFormatType_422YpCbCr8FullRange
  • kCVPixelFormatType_422YpCbCr_4A_8BiPlanar

但它们都不起作用。

我做错了什么?

欢迎任何评论...

这是我的代码:

/* construct an AVAssetReader based on an file based URL */
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];

/* determine image dimensions of images stored in movie asset */
CGSize size=[movieAsset naturalSize];
NSLog(@"movie asset natual size: size.width=%f size.height=%f",
size.width, size.height);

/* allocate assetReader */
AVAssetReader *assetReader=[[AVAssetReader alloc] initWithAsset:movieAsset
error:&error];

/* get video track(s) from movie asset */
NSArray *videoTracks=[movieAsset tracksWithMediaType:AVMediaTypeVideo];

/* get first video track, if there is any */
AVAssetTrack *videoTrack0=[videoTracks objectAtIndex:0];

/* set the desired video frame format into attribute dictionary */
NSMutableDictionary* dictionary=[NSDictionary dictionaryWithObjectsAndKeys:
[NSNumber numberWithInt:kCVPixelFormatType_422YpCbCr10],
(NSString*)kCVPixelBufferPixelFormatTypeKey,
nil];

/* construct the actual track output and add it to the asset reader */
AVAssetReaderTrackOutput* assetReaderOutput=[[AVAssetReaderTrackOutput alloc]
initWithTrack:videoTrack0
outputSettings:dictionary]; //nil or dictionary
/* main parser loop */
NSInteger i=0;
if([assetReader canAddOutput:assetReaderOutput]){
[assetReader addOutput:assetReaderOutput];

NSLog(@"asset added to output.");

/* start asset reader */
if([assetReader startReading]==YES){
/* read off the samples */
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.");
}

最好的问候,约翰

最佳答案

试试 kCVPixelFormatType_420YpCbCr8BiPlanarVideoRange,它对我来说效果很好。

关于objective-c - AVFoundation:从 mov 文件中读取 RAW 单帧(v210,未压缩的 10 位 4:2:2),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9469931/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com