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

时间:2013-01-07 07:41:35

标签: ios avassetwriter core-video avassetreader

我们正在使用AVAssetReaderAVAssetWriter的风格,如Video Encoding using AVAssetWriter - CRASHES中所述,基本上是为了阅读视频,我们从照片库/资产库中获得了什么,然后将其写在不同的比特率以减小其大小(用于最终的网络上传)。

让我们为此工作的诀窍是在kCVPixelBufferPixelFormatTypeKey outputSettings上指定AVAssetReaderTrackOutput键和值,如下所示:

NSDictionary *outputSettings = [NSDictionary 
    dictionaryWithObject:[NSNumber numberWithInt:kCVPixelFormatType_32BGRA] 
                  forKey:(id)kCVPixelBufferPixelFormatTypeKey];     
readerTrackOutput = 
    [[AVAssetReaderTrackOutput alloc] initWithTrack:src_track 
                                     outputSettings:outputSettings];

基本上我们使用了kCVPixelFormatType_32BGRA键的kCVPixelBufferPixelFormatTypeKey值。

但显然我们可以选择许多可能的像素格式类型。在iOS 6.0.1 iPhone设备上运行Technical 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对我们起作用(至少看似),但我们很好奇是否有比上面列表更好的选择。我们该如何选择正确的像素格式类型给我们?

1 个答案:

答案 0 :(得分:1)

您可以尝试不同的设置并比较性能。以不同像素格式向编码器提供缓冲器可能导致编码性能的差异。硬件加速编码器通常使用“420v”。

另见Query for optimal pixel format when capturing video on iOS?