FFMPEG - 格式不可用? [英] FFMPEG - format not available?
问题描述
我将一些代码从FFMPEG 0.8转换为FFMPEG 1.2。调用方法avcodec_open2()时出现错误:指定的像素格式%s无效或不支持。我使用的格式是:AV_PIX_FMT_RGB24。
I'm converting some code from FFMPEG 0.8 to FFMPEG 1.2. I have an error during the call to the method avcodec_open2(): "Specified pixel format %s is invalid or not supported". The format I use is : AV_PIX_FMT_RGB24. It should be enabled by default, right?
以下是我的代码:
av_register_all();
codec = avcodec_find_encoder(AV_CODEC_ID_MPEG2VIDEO);
if(!codec)
{
throw SystemException("codec not found");
}
codecContext = avcodec_alloc_context3(codec);
codecContext->bit_rate = 200000;
codecContext->time_base.den = 1;
codecContext->time_base.num = 90000;
codecContext->gop_size = 8;
codecContext->pix_fmt = AV_PIX_FMT_RGB24;
_codecContext->width = 320
_codecContext->height = 240
if(avcodec_open2(_codecContext, _codec, NULL) < 0)
{
throw SystemException("Unable to open codec");
}
推荐答案
在最新版本的ffmpeg 不支持MPEG2
/ MPEG1 AV_PIX_FMT_RGB24
。
In latest version of ffmpeg MPEG2
/MPEG1 AV_PIX_FMT_RGB24
is not supported.
需要使用 AV_PIX_FMT_YUV420P
或 AV_PIX_FMT_YUV422P
。
如果您的输入PIX格式不是 AV_PIX_FMT_YUV420P
/ AV_PIX_FMT_YUV422P
,您将需要转换。您可以使用 Sws_Context
和 sws_scale
。
So I if your input PIX format is not AV_PIX_FMT_YUV420P
/AV_PIX_FMT_YUV422P
, you will need a conversion. You can make use of Sws_Context
and sws_scale
for the same.
这篇关于FFMPEG - 格式不可用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!