问题描述
我正在尝试将图像从YUV420P
转换为RGB24
,下面是我提取帧并对其进行解码的代码,
帧提取
while(av_read_frame(avc,avpacket) == 0){
if(avpacket->stream_index == videoStream){
int res = avcodec_send_packet(avctx,avpacket);
if(res == AVERROR(EAGAIN)){
continue;
}
else if(res<0){
std::cout<<"error reading packet\n";
break;
}
else{
AVFrame* avframeRGB = av_frame_alloc();
res = avcodec_receive_frame(avctx,avframeRGB);
if(res == AVERROR(EAGAIN)){
continue;
}
else if(res<0){
std::cout<<"Error reading frame";
break;
}
else{
++i;
convertimage(&avframeRGB,avctx->pix_fmt,AV_PIX_FMT_RGB24);
displayImage(avframeRGB);
}
}
}
}
void convertimage(AVFrame** frame,AVPixelFormat srcFmt,AVPixelFormat destFmt){
AVFrame* tframe = *frame;
struct SwsContext* swscaler = sws_getContext(tframe->width,tframe->height,srcFmt,tframe->width,destFmt,SWS_BILINEAR,NULL,NULL);
AVFrame* tmp = av_frame_alloc();
tmp->width = tframe->width;
tmp->height = tframe->height;
tmp->format = destFmt;
if(av_frame_get_buffer(tmp,32) !=0)
return;
int res = sws_scale(swscaler,(uint8_t const * const*)tframe->data,tframe->linesize,tmp->data,tmp->linesize);
*frame = tmp;
}
data : {0x555555988ec0 '\020' <repeats 200 times>...,0x555555a6f940 '\200' <repeats 200 times>...,0x555555aa9440 '\200' <repeats 200 times>...,0x0,0x0}
height : 720
width : 1280
data : {0x7fffdde19040 "",0x0}
height : 0
width : 0
我无法理解为什么我的数据为NULL并且高度和宽度为0?
ffmpeg版本-4.3.2
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)