首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >AVAssetWriterInputPixelBufferAdaptor返回空像素缓冲池

AVAssetWriterInputPixelBufferAdaptor返回空像素缓冲池
EN

Stack Overflow用户
提问于 2011-04-28 05:43:51
回答 6查看 7.9K关注 0票数 9

我确信我的buffer属性出了问题,但我不清楚是什么问题--没有很好的文档记录,所以我猜是基于CVPixelBufferPoolCreate --而Core Foundation对我来说几乎是一本封闭的书。

代码语言:javascript
复制
    // "width" and "height" are const ints
    CFNumberRef cfWidth = CFNumberCreate(kCFAllocatorDefault, kCFNumberIntType, &width);
    CFNumberRef cfHeight = CFNumberCreate(kCFAllocatorDefault, kCFNumberIntType, &height);

    CFStringRef keys[] = {
        kCVPixelBufferWidthKey,
        kCVPixelBufferHeightKey,
        kCVPixelBufferCGImageCompatibilityKey
    };
    CFTypeRef values[] = {
        cfWidth,
        cfHeight,
        kCFBooleanTrue
    };
    int numValues = sizeof(keys) / sizeof(keys[0]);

    CFDictionaryRef bufferAttributes = CFDictionaryCreate(kCFAllocatorDefault, 
                                                          (const void **)&keys, 
                                                          (const void **)&values,
                                                          numValues,
                                                          &kCFTypeDictionaryKeyCallBacks,
                                                          &kCFTypeDictionaryValueCallBacks
                                                          );

    AVAssetWriterInputPixelBufferAdaptor *adaptor = [[AVAssetWriterInputPixelBufferAdaptor 
                                                      assetWriterInputPixelBufferAdaptorWithAssetWriterInput:writerInput
                                                      sourcePixelBufferAttributes:(NSDictionary*)bufferAttributes] retain];
    CVPixelBufferPoolRef bufferPool = adaptor.pixelBufferPool;
    NSParameterAssert(bufferPool != NULL); // fails
EN

回答 6

Stack Overflow用户

回答已采纳

发布于 2013-11-21 08:37:54

当pixelBufferPool返回null时,请检查以下内容:

  1. AVAssetsWriter的输出文件不存在。2.在AVAssetsWriter上调用startSessionAtTime:之后使用像素缓冲区。3. AVAssetWriterInput和AVAssetWriterInputPixelBufferAdaptor设置正确。4.现在使用appendPixelBuffer的时间并不相同。
票数 18
EN

Stack Overflow用户

发布于 2011-05-27 17:56:50

我也遇到了同样的问题,我想这可能是因为你没有正确配置你的AVAssetWriterInput。我的游泳池开始工作后,我做了这件事。特别是,除非我以AVVideoCompressionPropertiesKey格式提供数据,否则该池不会为我提供像素缓冲区。首先,创建并完全配置AVAssetWriter (在/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS4.3.sdk/System/Library/Frameworks/AVFoundation.framework/Headers/AVVideoSettings.h中查找outputSettingscompressionSettings的键和值):

代码语言:javascript
复制
NSError * err = 0;
AVAssetWriter * outputWriter = [AVAssetWriter
    assetWriterWithURL: [NSURL fileURLWithPath:outputPath]
              fileType: AVFileTypeAppleM4V
                 error: & err];

NSMutableDictionary * outputSettings
    = [[NSMutableDictionary alloc] init];
[outputSettings setObject: AVVideoCodecH264
                   forKey: AVVideoCodecKey];
[outputSettings setObject: [NSNumber numberWithInt: width_]
                   forKey: AVVideoWidthKey];
[outputSettings setObject: [NSNumber numberWithInt: height_]
                   forKey: AVVideoHeightKey];

NSMutableDictionary * compressionProperties
    = [[NSMutableDictionary alloc] init];
[compressionProperties setObject: [NSNumber numberWithInt: 1000000]
                          forKey: AVVideoAverageBitRateKey];
[compressionProperties setObject: [NSNumber numberWithInt: 16]
                          forKey: AVVideoMaxKeyFrameIntervalKey];
[compressionProperties setObject: AVVideoProfileLevelH264Main31
                          forKey: AVVideoProfileLevelKey];

[outputSettings setObject: compressionProperties
                   forKey: AVVideoCompressionPropertiesKey];

AVAssetWriterInput * writerInput = [AVAssetWriterInput
    assetWriterInputWithMediaType: AVMediaTypeVideo
                   outputSettings: outputSettings];

[compressionProperties release];
[outputSettings release];

创建像素缓冲区适配器:

代码语言:javascript
复制
NSMutableDictionary * pixBufSettings = [[NSMutableDictionary alloc] init];
[pixBufSettings setObject: [NSNumber numberWithInt: kCVPixelFormatType_32BGRA]
                   forKey: (NSString *) kCVPixelBufferPixelFormatTypeKey];
[pixBufSettings setObject: [NSNumber numberWithInt: width_]
                   forKey: (NSString *) kCVPixelBufferWidthKey];
[pixBufSettings setObject: [NSNumber numberWithInt: height_]
                   forKey: (NSString *) kCVPixelBufferHeightKey];

AVAssetWriterInputPixelBufferAdaptor * outputPBA =
    [AVAssetWriterInputPixelBufferAdaptor
    assetWriterInputPixelBufferAdaptorWithAssetWriterInput: outputInput
                               sourcePixelBufferAttributes: nil];

然后使用以下命令从其池中检索像素缓冲区:

代码语言:javascript
复制
CVReturn res = CVPixelBufferPoolCreatePixelBuffer (NULL
    , [outputPBA pixelBufferPool]
    , & outputFrame);
票数 3
EN

Stack Overflow用户

发布于 2011-06-21 03:59:47

根据文档:

“在关联的AVAssetWriter对象上首次调用startSessionAtTime:之前,此属性为NULL。”

因此,如果您太早尝试访问池,它将为NULL。我自己才刚刚学到这些东西,所以我现在不能详细说明。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/5810984

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档