问题
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).
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];
So basically we used the kCVPixelFormatType_32BGRA
value for the kCVPixelBufferPixelFormatTypeKey
key.
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
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?
回答1:
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".
See also, Query for optimal pixel format when capturing video on iOS?
来源:https://stackoverflow.com/questions/14191806/how-to-choose-the-a-pixel-format-type-kcvpixelbufferpixelformattypekey-for-use