【问题标题】:Adobe Native Extension iOS h.264 file encoderAdobe Native Extension iOS h.264 文件编码器
【发布时间】:2012-10-20 16:53:41
【问题描述】:

我正在尝试为 iOS 制作一个 adobe 本机扩展 h.264 文件编码器。我有编码器部分工作。它在 xcode 测试项目中运行良好。问题是当我尝试从 ane 文件运行它时它不起作用。

我的代码将从 bitmapData 转换为 CGImage 的帧添加:

    //convert first argument in a bitmapData
    FREObject objectBitmapData = argv[0];
    FREBitmapData  bitmapData;

    FREAcquireBitmapData( objectBitmapData, &bitmapData );

    CGImageRef theImage = getCGImageRefFromBitmapData(bitmapData);

    [videoRecorder addFrame:theImage];

在这种情况下,CGImageRef 有数据,但是当我尝试打开视频时,它只显示黑屏。

当我从 xcode 项目中对其进行测试时,它还会保存一个黑屏视频,但如果我从 UIImage 文件创建 CGImage,然后修改此 CGImage 并将其传递给 addFrame,它可以正常工作。

我的猜测是 CGImageRef theImage 没有正确创建。

我用来创建 CGImageRef 的代码是这样的:https://stackoverflow.com/a/8528969/800836

为什么使用 CGImageCreate 创建 CGImage 时不能正常工作?

谢谢!

【问题讨论】:

    标签: ios video air h.264 encoder


    【解决方案1】:

    如果有人遇到同样的问题,我的解决方案是创建一个每行 0 字节的 CGImageRef:

    CGBitmapInfo bitmapInfo     = kCGImageAlphaNoneSkipFirst | kCGBitmapByteOrder32Little;
    CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
    CGContextRef context = CGBitmapContextCreate(NULL, 1024, 768, 8, /*bytes per row*/0,    colorSpace, bitmapInfo);
    // create image from context
    CGImageRef tmpImage = CGBitmapContextCreateImage(context);
    CGContextRelease(context);
    CGColorSpaceRelease(colorSpace);
    

    然后将像素数据复制到这个tmpImage中,然后根据这个图像新建一个:

    CGImageRef getCGImageRefFromRawData(FREBitmapData bitmapData) {
        CGImageRef abgrImageRef = tmpImage;
        CFDataRef abgrData = CGDataProviderCopyData(CGImageGetDataProvider(abgrImageRef));
        UInt8 *pixelData = (UInt8 *) CFDataGetBytePtr(abgrData);
        int length = CFDataGetLength(abgrData);
    
        uint32_t* input = bitmapData.bits32;
        int index2 = 0;
        for (int index = 0; index < length; index+= 4) {
                pixelData[index] = (input[index2]>>0) & 0xFF;
                pixelData[index+1] = (input[index2]>>8) & 0xFF;
                pixelData[index+2] = (input[index2]>>16) & 0xFF;
                pixelData[index+3] = (input[index2]>>24) & 0xFF;
                index2++;
        }
    
    
        // grab the bgra image info
        size_t width = CGImageGetWidth(abgrImageRef);
        size_t height = CGImageGetHeight(abgrImageRef);
        size_t bitsPerComponent = CGImageGetBitsPerComponent(abgrImageRef);
        size_t bitsPerPixel = CGImageGetBitsPerPixel(abgrImageRef);
        size_t bytesPerRow = CGImageGetBytesPerRow(abgrImageRef);
        CGColorSpaceRef colorspace = CGImageGetColorSpace(abgrImageRef);
        CGBitmapInfo bitmapInfo = CGImageGetBitmapInfo(abgrImageRef);
    
        // create the argb image
        CFDataRef argbData = CFDataCreate(NULL, pixelData, length);
        CGDataProviderRef provider = CGDataProviderCreateWithCFData(argbData);
        CGImageRef argbImageRef = CGImageCreate(width, height, bitsPerComponent, bitsPerPixel, bytesPerRow, colorspace, bitmapInfo, provider, NULL, true, kCGRenderingIntentDefault);
    
        // release what we can
        CFRelease(abgrData);
        CFRelease(argbData);
        CGDataProviderRelease(provider);
    return argbImageRef;
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-02-16
      • 2014-09-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多