gpt4 book ai didi

cocoa - 从 libswscale 中获取 PIX_FMT_YUYV422

转载 作者:行者123 更新时间:2023-12-03 17:18:05 25 4
gpt4 key购买 nike

我正在尝试学习在 Cocoa 中使用不同的 ffmpeg 库,并且我正在尝试在 Core Video 的帮助下显示帧。看来我已经让 CV 回调开始工作,并且它获取了我尝试放入 CVImageBufferRef 中的帧,稍后我用 Core Image 绘制了这些帧。

问题是我试图让 PIX_FMT_YUYV422 与 libswscale 一起使用,但是一旦我将像素格式更改为 PIX_FMT_YUV420P 以外的任何格式,它就会因 EXC_BAD_ACCESS 崩溃。

只要我使用YUV420P,程序就可以运行,尽管它不能正常显示。我怀疑像素格式不受支持,所以我想尝试 PIX_FMT_YUYV422。

我之前已经运行过它并成功使用 PIX_FMT_RGB24 写入 PPM 文件。由于某种原因,它现在在我身上崩溃了,我不知道可能出了什么问题。

我有点不知所措,但这就是我更喜欢的学习方式。 :)

这是我分配 AVFrame 的方法:

inFrame = avcodec_alloc_frame();
outFrame = avcodec_alloc_frame();
int frameBytes = avpicture_get_size(PIX_FMT_YUYV422, cdcCtx->width, cdcCtx->height);


uint8_t *frameBuffer = malloc(frameBytes);
avpicture_fill((AVPicture *)outFrame, frameBuffer, PIX_FMT_YUYV422, cdcCtx->width, cdcCtx->height);

然后我尝试通过 swscale 运行它,如下所示:

static struct SwsContext *convertContext;


if (convertContext == NULL) {
int w = cdcCtx->width;
int h = cdcCtx->height;
convertContext = sws_getContext(w, h, cdcCtx->pix_fmt, outWidth, outHeight, PIX_FMT_YUYV422, SWS_BICUBIC, NULL, NULL, NULL);
if (convertContext == NULL) {
NSLog(@"Cannot initialize the conversion context!");
return NO;
}
}

sws_scale(convertContext, inFrame->data, inFrame->linesize, 0, outHeight, outFrame->data, outFrame->linesize);

最后我尝试将其写入像素缓冲区以与 Core Image 一起使用:

int ret = CVPixelBufferCreateWithBytes(0, outWidth, outHeight, kYUVSPixelFormat, outFrame->data[0], outFrame->linesize[0], 0, 0, 0, &currentFrame);

使用 420P 它可以运行,但它与像素缓冲区的 kYUVSPixelformat 不匹配,据我所知,它不接受 YUV420。

我真的很感激任何帮助,无论多么小,因为它可能会帮助我继续奋斗。 :)

最佳答案

这当然不是完整的代码示例,因为您从未将任何内容解码到输入帧中。如果您这样做,看起来是正确的。

实际上,您也不需要填充输出图片,甚至不需要为其分配 AVFrame。

关于cocoa - 从 libswscale 中获取 PIX_FMT_YUYV422,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1456691/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com