avcodec YUV到RGB [英] avcodec YUV to RGB

查看:258
本文介绍了avcodec YUV到RGB的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图使用libswscale将YUV帧转换为RGB。



这是我的代码:

  AVFrame * RGBFrame; 
SwsContext * ConversionContext;

ConversionContext = sws_getCachedContext(NULL,FrameWidth,FrameHeight,AV_PIX_FMT_YUV420P,FrameWidth,FrameHeight,AV_PIX_FMT_RGB24,SWS_BILINEAR,0,0,0);
RGBFrame = av_frame_alloc();

avpicture_fill((AVPicture *)RGBFrame,& FillVect [0],AV_PIX_FMT_RGB24,FrameWidth,FrameHeight);

sws_scale(ConversionContext,VideoFrame-> data,VideoFrame-> linesize,0,VideoFrame-> height,RGBFrame-> data,RGBFrame-> linesize)

我的程序在sws_scale函数中执行SEGFAULT。



VideoFrame是一个保存我解码的帧的AVFrame结构。



我认为这是因为YUV帧来自avcodec_decode_video2,返回一个像这样的数组: p>

  VideoFrame-> data [0] // Y array,linesize = frame width 
VideoFrame-> data [1] ] // U array,linesize = frame width / 2
VideoFrame-> data [2] // V array,linesize = frame width / 2
所以,我不知道如何继续转换我的数组,其中Y,U,V数据分为RGB24,使用swscale。



请帮助me,thanks:)

解决方案

av_frame_alloc 只为框架分配内存对象本身,它不分配存储器来存储图像数据。您已完成:



FillVect.resize(avpicture_get_size(PIX_FMT_RGB24,FrameWidth,FrameHeight));

在调用 avpicture_fill 之前,您的代码中的某处有

?或者一些其他方法来确保FillVect分配足够的内存来保存整个解码图片?



你尝试在valgrind下运行它,看看SEGFAULT是什么? p>

I'm trying to convert an YUV frame to RGB using libswscale.

Here is my code :

AVFrame *RGBFrame;
SwsContext *ConversionContext;

ConversionContext = sws_getCachedContext(NULL, FrameWidth, FrameHeight, AV_PIX_FMT_YUV420P, FrameWidth, FrameHeight, AV_PIX_FMT_RGB24, SWS_BILINEAR, 0, 0, 0);
RGBFrame = av_frame_alloc();

avpicture_fill((AVPicture *)RGBFrame, &FillVect[0], AV_PIX_FMT_RGB24, FrameWidth, FrameHeight);

sws_scale(ConversionContext, VideoFrame->data, VideoFrame->linesize, 0, VideoFrame->height, RGBFrame->data, RGBFrame->linesize);

My program do SEGFAULT on the sws_scale function.

VideoFrame is an AVFrame struct who hold my decoded frame.

I think this is because the YUV frame come from avcodec_decode_video2, which return an array like this :

VideoFrame->data[0] // Y array, linesize = frame width
VideoFrame->data[1] // U array, linesize = frame width/2
VideoFrame->data[2] // V array, linesize = frame width/2

While YUV420P have theoretically only one plane (according to Wikipedia, YUV420P is a planar format, then Y, U, V data are grouped together). So, i don't know how to proceed to convert my array where Y, U, V data are separated into RGB24, using swscale.

Please help me, thanks :)

解决方案

av_frame_alloc only allocates memory for the frame object itself, it does not allocate memory to store the image data. Have you done:

FillVect.resize( avpicture_get_size( PIX_FMT_RGB24, FrameWidth, FrameHeight ) );

somewhere in your code before calling avpicture_fill? Or some other way to make sure FillVect allocates enough memory to keep the whole decoded picture?

Did you try to run it under valgrind to see what exactly trigges SEGFAULT?

这篇关于avcodec YUV到RGB的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆