ios - AVAssetWriterInputPixelBufferAdaptor 返回空像素缓冲池

标签 ios core-foundation avassetwriter core-video

我确定我的缓冲区属性有问题,但我不清楚是什么 -- 没有很好地记录应该去那里的内容,所以我猜测基于 CVPixelBufferPoolCreate -- Core Foundation 对我来说几乎是一本合上的书。

    // "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

最佳答案

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

    1. AVAssetsWriter 的输出文件不存在。
    2. 在 AVAssetsWriter 上调用 startSessionAtTime: 后使用像素缓冲区。
    3. AVAssetWriterInput 和 AVAssetWriterInputPixelBufferAdaptor 设置正确。
    4.appendPixelBuffer的当前使用次数不一样。

关于ios - AVAssetWriterInputPixelBufferAdaptor 返回空像素缓冲池,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5810984/

相关文章:

ios - 每隔 X 秒 Swift 使用 SKAction 调用一个函数

c - OSX FSEventStreamEventFlags 无法正常工作

iphone - AVAssetWriter 多个 session 和状态属性

ios - 在输出到文件之前从 AVAssetWriter 中删除缓冲区

ios - UILabel 中的 HTML 格式 (iOS)

ios - 一种检查iOS应用程序是否存在于App Store中的方法?

ios - 在 UITableViewCell 的 UIButton 位置插入 UIView

CFDataCreateWithBytesNoCopy() 不能与 "const char var[xx]"一起使用,但可以与 malloc 一起使用吗?

objective-c - 静态分析和 "create rule"

ios - 将图像数组转换为 MP4 文件时遇到问题