ffmpeg缩放误差活性维度
FFMPEG scaling error-invalid dimension
我正在从事FFMPEG的一个项目,现在我陷入了问题。
我要做的是将PNG PIC转换为MPEG视频文件。我已经设法从图片中获取Informatin,但是我无法以Yuv格式转换图片。它返回" 0x0-> 0x0是无效的缩放尺寸"。
这是我的代码:
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。代码
AVPacket pkt;
av_init_packet(&pkt);
pkt.stream_index= st->index;
pkt.data= buffer;
pkt.size=numBytes;
int got_pkt;
test=avcodec_encode_video2(st->codec,&pkt,pFrameYUV,&got_pkt);
printf("%d",got_pkt);
这些值pFrameYUV->height, pFrame->height, pFrameYUV->width, pFrame->width
在调用sws_getCachedContext
时未设置。
您的意思是尺寸不变吗?如果是这样,请在sws_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);
相关文章:
- 为什么在浮点中从大到小会引入更多的误差
- 基于相邻元素 c++ 的分段误差范围的循环
- QImage::p ixel 和 QImage::setPixel 坐标超出范围误差
- 将误差线添加到 VTK 二维散点图
- 动态矩阵特征分解过程中的误差
- 转换为非标量误差是什么意思?我该如何解决?
- 特征误差:INVALID_MATRIX_PRODUCT乘向量和矩阵
- 使用不同参数匹配器的同一方法ON_CALL AND EXPECT_CALL会产生饱和和活动误差
- boost odeint 中的受控误差步进器是否支持复杂的数据类型?
- 此外,在计算大斐波那契数时存在精度误差
- C++17中不定参数函数的误差
- 多态性中独立类的基本误差.C++
- 犰狳函数的不同最小二乘误差
- 在 qt 中的绘图中拖动误差线
- variadic函数和折叠表达:试图在Visual Studio 2017中编译时致命误差
- 在Cython中使用移动方法时的汇编误差
- variadic模板代码中的GCC VS MSVC编译误差
- CMAKE和CUDA的权限误差
- OPENCV C 中的分割故障误差
- ffmpeg缩放误差活性维度