小编jr.*_*.cs的帖子

如何将YUVJ420P中的FFMPEG AVFrame转换为AVFoundation cVPixelBufferRef?

我有一个FFMPEG AVFrameYUVJ420P,我想将其转换为一个CVPixelBufferRefCVPixelBufferCreateWithBytes.我想这样做的原因是使用AVFoundation来显示/编码帧.

我选择kCVPixelFormatType_420YpCbCr8BiPlanarVideoRange并尝试转换它,因为AVFrame有三个平面的数据 Y480 Cb240 Cr240.根据我所研究的内容,这与所选的相匹配kCVPixelFormatType.通过双平面我需要将其转换为包含Y480CbCr480Interleaved 的缓冲区.

我尝试用2个平面创建一个缓冲区:

  • frame->data[0] 在第一架飞机上,
  • frame->data[1]frame->data[2]在第二个平面上交错.

但是,我收到的返回错误-6661 (invalid a)来自CVPixelBufferCreateWithBytes:

"Invalid function parameter. For example, out of range or the wrong type."
Run Code Online (Sandbox Code Playgroud)

我根本没有关于图像处理的专业知识,所以任何指向文档的指针都可以让我从正确的方法开始解决这个问题.我的C技能也不是最重要的,所以也许我在这里犯了一个基本错误.

    uint8_t **buffer = malloc(2*sizeof(int *));
    buffer[0] = frame->data[0];
    buffer[1] = malloc(frame->linesize[0]*sizeof(int));
    for(int i = 0; i<frame->linesize[0]; i++){
        if(i%2){
            buffer[1][i]=frame->data[1][i/2];
        }else{
            buffer[1][i]=frame->data[2][i/2];
        }
    }

    int ret = CVPixelBufferCreateWithBytes(NULL, frame->width, frame->height, kCVPixelFormatType_420YpCbCr8BiPlanarVideoRange, …
Run Code Online (Sandbox Code Playgroud)

ffmpeg yuv avfoundation ios

7
推荐指数
1
解决办法
4414
查看次数

标签 统计

avfoundation ×1

ffmpeg ×1

ios ×1

yuv ×1