我們使用AVAssetReader
和AVAssetWriter
的方式有點像Video Encoding using AVAssetWriter - CRASHES中提到的風格,基本上是從照片庫/資源庫中讀取視頻,然後以不同的比特率寫入視頻以減小其大小(最終網絡上傳)。如何選擇用於AVAssetReader的像素格式類型(kCVPixelBufferPixelFormatTypeKey)?
的竅門能讓這對我們的工作是對AVAssetReaderTrackOutput
指定的outputSettings
一個kCVPixelBufferPixelFormatTypeKey
鍵和值,像這樣:
NSDictionary *outputSettings = [NSDictionary
dictionaryWithObject:[NSNumber numberWithInt:kCVPixelFormatType_32BGRA]
forKey:(id)kCVPixelBufferPixelFormatTypeKey];
readerTrackOutput =
[[AVAssetReaderTrackOutput alloc] initWithTrack:src_track
outputSettings:outputSettings];
所以基本上我們用kCVPixelFormatType_32BGRA
價值爲kCVPixelBufferPixelFormatTypeKey
關鍵。
但顯然有很多可能的像素格式類型,我們可以從中選擇。運行在Technical Q&A QA1501: Core Video - Available Pixel Formats在iOS 6.0.1 iPhone設備上標註的代碼,下面是它顯示支持像素格式類型的列表:
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