本文介绍了如何选择与AVAssetReader一起使用的像素格式类型(kCVPixelBufferPixelFormatTypeKey)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们正在以视频编码中所述的样式使用AVAssetReaderAVAssetWriter使用AVAssetWriter-CRASHES 基本上是从相册/资产库中读取视频,然后以不同的比特率写入以减小其大小(最终用于网络上传).

We are using AVAssetReader and AVAssetWriter somewhat in the style as noted in Video Encoding using AVAssetWriter - CRASHES basically to read a video what we got from the photo gallery / asset library then writing it at a different bit rate to reduce its size (for eventual network upload).

让它起作用的诀窍是在AVAssetReaderTrackOutputoutputSettings中指定kCVPixelBufferPixelFormatTypeKey键和值,如下所示:

The trick to getting this to work for us was to specify a kCVPixelBufferPixelFormatTypeKey key and value in the outputSettings on AVAssetReaderTrackOutput, something like this:

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

因此,基本上,我们将kCVPixelFormatType_32BGRA值用于kCVPixelBufferPixelFormatTypeKey键.

So basically we used the kCVPixelFormatType_32BGRA value for the kCVPixelBufferPixelFormatTypeKey key.

但是显然,我们可以选择许多可能的像素格式类型.运行 Q&A QA1501:核心视频-可用的代码像素格式在iOS 6.0.1 iPhone设备上,此处显示的是支持的像素格式类型:

But apparently there are many possible pixel format types that we could choose from. Running the code noted in Technical Q&A QA1501: Core Video - Available Pixel Formats on an iOS 6.0.1 iPhone device, here's the list of support pixel format types that it shows:

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对我们有用(至少在表面上),但我们对是否有比上述列表更好的选择感到好奇.我们应该如何选择合适的像素格式类型?

Even though kCVPixelFormatType_32BGRA worked (at least seemingly) for us, we are curious as to whether there is a better choice than that from the above list. How should we go about picking out the right pixel format type to us?

推荐答案

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

You might experiment with different settings and compare perfomance. Providing the buffers to the encoder in different pixel formats may result in differences in encoding perfomance. Hardware accelerated encoders are often using "420v".

另请参见查询在iOS上捕获视频时最佳像素格式?

这篇关于如何选择与AVAssetReader一起使用的像素格式类型(kCVPixelBufferPixelFormatTypeKey)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-19 01:56