获取 AvCaptureVideoDataOutput 的实际 NSString 可用VideoCVPixelFormatTypes
Posted
技术标签:
【中文标题】获取 AvCaptureVideoDataOutput 的实际 NSString 可用VideoCVPixelFormatTypes【英文标题】:Getting actual NSString of AvCaptureVideoDataOutput availableVideoCVPixelFormatTypes 【发布时间】:2013-01-26 14:33:38 【问题描述】:我正在尝试在 AVFoundation 输出中找到可接受的格式:
self.theOutput=[[AVCaptureVideoDataOutput alloc]init];
if ([self.theSession canAddOutput:self.theOutput])
[self.theSession addOutput:self.theOutput];
然后我在 and 之后插入一个断点:
po [self.theOutput availableVideoCVPixelFormatTypes]
我明白了:
(NSArray *) $5 = 0x2087ad00 <__NSArrayM 0x2087ad00>(
875704438,
875704422,
1111970369
)
如何获取这些格式类型的字符串值?
谢谢
【问题讨论】:
【参考方案1】:在运行 ios6 的 iPhone5 上,这里是可用的 AVCaptureVideoDataOuputVideoCVPixelFormatTypes:
kCVPixelFormatType_420YpCbCr8BiPlanarVideoRange
kCVPixelFormatType_420YpCbCr8BiPlanarFullRange
kCVPixelFormatType_32BGRA
信用到期的信用,我找到了一种方法来获得此处支持的价值。 https://gist.github.com/2327666
【讨论】:
你也可以在lldb中做p (FourCharCode)pixelFormatType
。【参考方案2】:
用于调试的分类版本
作为 NSNumber 上的一个类别
#import <CoreVideo/CoreVideo.h>
@implementation NSNumber (CVPixelFormatType)
- (NSString *)descriptivePixelFormat
return @
@(kCVPixelFormatType_1Monochrome): @"kCVPixelFormatType_1Monochrome",
@(kCVPixelFormatType_2Indexed): @"kCVPixelFormatType_2Indexed",
@(kCVPixelFormatType_4Indexed): @"kCVPixelFormatType_4Indexed",
@(kCVPixelFormatType_8Indexed): @"kCVPixelFormatType_8Indexed",
@(kCVPixelFormatType_1IndexedGray_WhiteIsZero): @"kCVPixelFormatType_1IndexedGray_WhiteIsZero",
@(kCVPixelFormatType_2IndexedGray_WhiteIsZero): @"kCVPixelFormatType_2IndexedGray_WhiteIsZero",
@(kCVPixelFormatType_4IndexedGray_WhiteIsZero): @"kCVPixelFormatType_4IndexedGray_WhiteIsZero",
@(kCVPixelFormatType_8IndexedGray_WhiteIsZero): @"kCVPixelFormatType_8IndexedGray_WhiteIsZero",
@(kCVPixelFormatType_16BE555): @"kCVPixelFormatType_16BE555",
@(kCVPixelFormatType_16LE555): @"kCVPixelFormatType_16LE555",
@(kCVPixelFormatType_16LE5551): @"kCVPixelFormatType_16LE5551",
@(kCVPixelFormatType_16BE565): @"kCVPixelFormatType_16BE565",
@(kCVPixelFormatType_16LE565): @"kCVPixelFormatType_16LE565",
@(kCVPixelFormatType_24RGB): @"kCVPixelFormatType_24RGB",
@(kCVPixelFormatType_24BGR): @"kCVPixelFormatType_24BGR",
@(kCVPixelFormatType_32ARGB): @"kCVPixelFormatType_32ARGB",
@(kCVPixelFormatType_32BGRA): @"kCVPixelFormatType_32BGRA",
@(kCVPixelFormatType_32ABGR): @"kCVPixelFormatType_32ABGR",
@(kCVPixelFormatType_32RGBA): @"kCVPixelFormatType_32RGBA",
@(kCVPixelFormatType_64ARGB): @"kCVPixelFormatType_64ARGB",
@(kCVPixelFormatType_48RGB): @"kCVPixelFormatType_48RGB",
@(kCVPixelFormatType_32AlphaGray): @"kCVPixelFormatType_32AlphaGray",
@(kCVPixelFormatType_16Gray): @"kCVPixelFormatType_16Gray",
@(kCVPixelFormatType_422YpCbCr8): @"kCVPixelFormatType_422YpCbCr8",
@(kCVPixelFormatType_4444YpCbCrA8): @"kCVPixelFormatType_4444YpCbCrA8",
@(kCVPixelFormatType_4444YpCbCrA8R): @"kCVPixelFormatType_4444YpCbCrA8R",
@(kCVPixelFormatType_444YpCbCr8): @"kCVPixelFormatType_444YpCbCr8",
@(kCVPixelFormatType_422YpCbCr16): @"kCVPixelFormatType_422YpCbCr16",
@(kCVPixelFormatType_422YpCbCr10): @"kCVPixelFormatType_422YpCbCr10",
@(kCVPixelFormatType_444YpCbCr10): @"kCVPixelFormatType_444YpCbCr10",
@(kCVPixelFormatType_420YpCbCr8Planar): @"kCVPixelFormatType_420YpCbCr8Planar",
@(kCVPixelFormatType_420YpCbCr8PlanarFullRange): @"kCVPixelFormatType_420YpCbCr8PlanarFullRange",
@(kCVPixelFormatType_422YpCbCr_4A_8BiPlanar): @"kCVPixelFormatType_422YpCbCr_4A_8BiPlanar",
@(kCVPixelFormatType_420YpCbCr8BiPlanarVideoRange): @"kCVPixelFormatType_420YpCbCr8BiPlanarVideoRange",
@(kCVPixelFormatType_420YpCbCr8BiPlanarFullRange): @"kCVPixelFormatType_420YpCbCr8BiPlanarFullRange",
@(kCVPixelFormatType_422YpCbCr8_yuvs): @"kCVPixelFormatType_422YpCbCr8_yuvs",
@(kCVPixelFormatType_422YpCbCr8FullRange): @"kCVPixelFormatType_422YpCbCr8FullRange"
[self];
@end
诊断输出示例
NSMutableArray *mutablePixelFormatTypes = [NSMutableArray array];
[captureOutput.availableVideoCVPixelFormatTypes enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop)
[mutablePixelFormatTypes addObject:[obj descriptivePixelFormat]];
];
NSString *pixelFormats = [mutablePixelFormatTypes componentsJoinedByString:@",\n"];
NSLog(@"Available pixel formats:\n%@\n", pixelFormats);
【讨论】:
【参考方案3】:当您调用 availableVideoCVPixelFormatTypes 时,您将获得所有像素格式类型标签的十进制表示。如果将它们转换为十六进制,则可以将其中一些与Apple's Documentation 上列出的标签匹配。其余的你必须将你得到的十六进制值转换为 ASCII 字符才能最终匹配标签。
例如:
(十进制) ------> (十六进制) ---> (ASCII)
875704438 -> 34323076 -> 420v
875704422 -> 34323066 -> 420f
1111970369 -> 42475241 -> BGRA
我发现这个网站“ASCII to Hex”很有用。
【讨论】:
以上是关于获取 AvCaptureVideoDataOutput 的实际 NSString 可用VideoCVPixelFormatTypes的主要内容,如果未能解决你的问题,请参考以下文章