如何解决ffmpeg:sws_scale无法将图像从YUV转换为RGB
我正在尝试将图像从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 举报,一经查实,本站将立刻删除。