如何选择与AVAssetReader一起使用的像素格式类型(kCVPixelBufferPixelFormatTypeKey)?

8
我们正在使用AVAssetReaderAVAssetWriter,并且类似于Video Encoding using AVAssetWriter - CRASHES中所述的方式读取从照片库/资源库获取的视频,然后将其写入不同比特率以减小其大小(以便进行网络上传)。
让我们成功的技巧是在AVAssetReaderTrackOutput中的outputSettings上指定了一个kCVPixelBufferPixelFormatTypeKey键和值,就像这样:
NSDictionary *outputSettings = [NSDictionary 
    dictionaryWithObject:[NSNumber numberWithInt:kCVPixelFormatType_32BGRA] 
                  forKey:(id)kCVPixelBufferPixelFormatTypeKey];     
readerTrackOutput = 
    [[AVAssetReaderTrackOutput alloc] initWithTrack:src_track 
                                     outputSettings:outputSettings];

基本上,我们使用kCVPixelBufferPixelFormatTypeKey关键字的kCVPixelFormatType_32BGRA值。但显然我们可以从许多可能的像素格式类型中进行选择。在iOS 6.0.1 iPhone设备上运行技术Q&A QA1501: Core Video - Available Pixel Formats中提到的代码,下面是支持的像素格式类型列表:
Core Video Supported Pixel Format Types:
Core Video Pixel Format Type: 32
Core Video Pixel Format Type: 24
Core Video Pixel Format Type: 16
Core Video Pixel Format Type (FourCC): L565
Core Video Pixel Format Type (FourCC): 2vuy
Core Video Pixel Format Type (FourCC): yuvs
Core Video Pixel Format Type (FourCC): yuvf
Core Video Pixel Format Type: 40
Core Video Pixel Format Type (FourCC): L008
Core Video Pixel Format Type (FourCC): 2C08
Core Video Pixel Format Type (FourCC): r408
Core Video Pixel Format Type (FourCC): v408
Core Video Pixel Format Type (FourCC): y408
Core Video Pixel Format Type (FourCC): y416
Core Video Pixel Format Type (FourCC): BGRA
Core Video Pixel Format Type (FourCC): b64a
Core Video Pixel Format Type (FourCC): b48r
Core Video Pixel Format Type (FourCC): b32a
Core Video Pixel Format Type (FourCC): b16g
Core Video Pixel Format Type (FourCC): R10k
Core Video Pixel Format Type (FourCC): v308
Core Video Pixel Format Type (FourCC): v216
Core Video Pixel Format Type (FourCC): v210
Core Video Pixel Format Type (FourCC): v410
Core Video Pixel Format Type (FourCC): r4fl
Core Video Pixel Format Type (FourCC): grb4
Core Video Pixel Format Type (FourCC): rgg4
Core Video Pixel Format Type (FourCC): bgg4
Core Video Pixel Format Type (FourCC): gbr4
Core Video Pixel Format Type (FourCC): 420v
Core Video Pixel Format Type (FourCC): 420f
Core Video Pixel Format Type (FourCC): 411v
Core Video Pixel Format Type (FourCC): 411f
Core Video Pixel Format Type (FourCC): 422v
Core Video Pixel Format Type (FourCC): 422f
Core Video Pixel Format Type (FourCC): 444v
Core Video Pixel Format Type (FourCC): 444f
Core Video Pixel Format Type (FourCC): y420
Core Video Pixel Format Type (FourCC): f420
Core Video Pixel Format Type (FourCC): a2vy
Core Video Pixel Format Type (FourCC): L00h
Core Video Pixel Format Type (FourCC): L00f
Core Video Pixel Format Type (FourCC): 2C0h
Core Video Pixel Format Type (FourCC): 2C0f
Core Video Pixel Format Type (FourCC): RGhA
Core Video Pixel Format Type (FourCC): RGfA

尽管kCVPixelFormatType_32BGRA对我们似乎有效,但我们很好奇是否有比上述列表中更好的选择。我们应该如何挑选出适合我们的正确像素格式类型呢?


如果有一种与硬件兼容的纹理格式用于解码原始视频帧,那么将其转换为该格式可能比转换为RGB更快。这可以交给GL处理,并使用片段着色器将其转换为屏幕颜色空间。 - MrMaxP
1个回答

2
你可以尝试不同的设置并比较性能。以不同的像素格式提供缓冲区给编码器可能导致编码性能的差异。硬件加速编码器通常使用“420v”。
另请参见:iOS上捕获视频时查询最佳像素格式?

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接