jjzjj

ios - AVAssetWriterInputPixelBufferAdaptor 返回空像素缓冲池

coder 2023-09-21 原文

我确定我的缓冲区属性有问题,但我不清楚是什么 -- 没有很好地记录应该去那里的内容,所以我猜测基于 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 - AVAssetWriterInputPixelBufferAdaptor 返回空像素缓冲池的更多相关文章

随机推荐