C++ FFMPEG缩放错误无效维度
我在FFMPEG上做一个项目,现在我遇到了一个问题 我想做的是,将png图片转换成mpeg视频文件。我已经设法从图片中获取信息,但不知何故,我无法将图片转换为YUV格式。它返回“0x0->0x0是无效的缩放维度” 这是我的密码:C++ FFMPEG缩放错误无效维度,c++,ffmpeg,libavcodec,swscale,C++,Ffmpeg,Libavcodec,Swscale,我在FFMPEG上做一个项目,现在我遇到了一个问题 我想做的是,将png图片转换成mpeg视频文件。我已经设法从图片中获取信息,但不知何故,我无法将图片转换为YUV格式。它返回“0x0->0x0是无效的缩放维度” 这是我的密码: AVFrame *pFrame; AVFrame *pFrameYUV; pFrame = av_frame_alloc(); pFrameYUV = av_frame_alloc(); int numBytes;//Groesse des Bildes uint8_
AVFrame *pFrame;
AVFrame *pFrameYUV;
pFrame = av_frame_alloc();
pFrameYUV = av_frame_alloc();
int numBytes;//Groesse des Bildes
uint8_t *buffer= NULL;
numBytes=avpicture_get_size(AV_PIX_FMT_RGB24, pCodecCtx->width,pCodecCtx->height);
buffer=(uint8_t *)av_malloc(numBytes*sizeof(uint8_t));
/*avpicture_fill((AVPicture *)pFrameYUV, buffer, AV_PIX_FMT_YUV420P,
pCodecCtx->width, pCodecCtx->height);*/
av_image_fill_arrays(pFrameYUV->data,pFrameYUV->linesize,buffer,AV_PIX_FMT_YUV420P,pCodecCtx->width,pCodecCtx->height,32);
struct SwsContext *sws_ctx = NULL;
AVPacket packet;
// initialize SWS context for software scaling
sws_ctx=sws_getCachedContext(NULL,pFrame->width,pFrame->height,AV_PIX_FMT_RGB24,pFrameYUV->width,pFrameYUV->height,AV_PIX_FMT_YUV420P,0,0,0,0);
pFrameYUV->height= pFrame->height;
pFrameYUV->width= pFrame->width;
while (av_read_frame(pFormatCtx,&packet)>=0)
{
if(packet.stream_index == videoStream)
{
avcodec_decode_video2(pCodecCtx, pFrame, &frameFinished, &packet);
if(frameFinished)
{
sws_scale(sws_ctx, (uint8_t const * const *)pFrame->data,
pFrame->linesize, 0, pCodecCtx->height,
pFrameYUV->data, pFrameYUV->linesize);
printf("%d",pFrameYUV->height);
}
}
av_free_packet(&packet);
}
编辑:
转换后,我尝试将帧编码到一个数据包中,但数据包的大小是0。
代码
调用
sws\u getCachedContext
时,未设置这些值pFrameYUV->height,pFrame->height,pFrameYUV->width,pFrame->width,pFrame->width
pFrameYUV->height = pFrame->height = pCodecCtx->height;
pFrameYUV->width = pFrame->width = pCodecCtx->width;
sws_ctx=sws_getCachedContext(NULL,pFrame->width,pFrame->height,AV_PIX_FMT_RGB24,pFrameYUV->width,pFrameYUV->height,AV_PIX_FMT_YUV420P,0,0,0,0);
你是说尺寸不变吗?如果是,请将它们设置在sws\u getCachedContext之前
pFrameYUV->height = pFrame->height = pCodecCtx->height;
pFrameYUV->width = pFrame->width = pCodecCtx->width;
sws_ctx=sws_getCachedContext(NULL,pFrame->width,pFrame->height,AV_PIX_FMT_RGB24,pFrameYUV->width,pFrameYUV->height,AV_PIX_FMT_YUV420P,0,0,0,0);
调用
sws\u getCachedContext
时,未设置这些值pFrameYUV->height,pFrame->height,pFrameYUV->width,pFrame->width,pFrame->width
pFrameYUV->height = pFrame->height = pCodecCtx->height;
pFrameYUV->width = pFrame->width = pCodecCtx->width;
sws_ctx=sws_getCachedContext(NULL,pFrame->width,pFrame->height,AV_PIX_FMT_RGB24,pFrameYUV->width,pFrameYUV->height,AV_PIX_FMT_YUV420P,0,0,0,0);
你是说尺寸不变吗?如果是,请将它们设置在sws\u getCachedContext之前
pFrameYUV->height = pFrame->height = pCodecCtx->height;
pFrameYUV->width = pFrame->width = pCodecCtx->width;
sws_ctx=sws_getCachedContext(NULL,pFrame->width,pFrame->height,AV_PIX_FMT_RGB24,pFrameYUV->width,pFrameYUV->height,AV_PIX_FMT_YUV420P,0,0,0,0);
我想那些有av图像填充阵列的小装置?我是否也必须设置帧的pix fmt?是的,为了安全起见,您还应该设置
pix_fmt
。嘿,它可以工作。但缩放后pFrameYUV的数据字段仍然为空。我该怎么设置呢?sws\U刻度将为您填充。您应该使用frameFinished
检查返回值avcodec\u decode\u video2
,以确保帧的解码成功。解码成功,帧已完成,但pFrameYUV的数据字段仍然为空。我想那些设置了av\u image\u fill\u数组的wee?我是否也必须设置帧的pix fmt?是的,为了安全起见,您还应该设置pix_fmt
。嘿,它可以工作。但缩放后pFrameYUV的数据字段仍然为空。我该怎么设置呢?sws\U刻度将为您填充。您应该使用frameFinished
检查返回值avcodec\u decode\u video2
,以确保帧的解码成功。解码成功,帧已完成,但pFrameYUV的数据字段仍然为空