0
我已经编译了一个FFMPEG库,以便在Android上使用libx264并使用NDK。FFMPEG x264编码器Android
我想对MPEG视频文件进行编码,但是在avcodec_open2中打开编码器编解码器时应用程序失败。
我从avcodec_open2接收到的FFMPEG日志如下,函数返回-22。
- 图片大小%ux%u无效。
- 忽略无效的宽度/高度重视
- 指定pix_fmt不支持
在Windows上的代码工作正常,不存在失败的它仅适用于Android。任何ides为什么这将失败在Android上?
if (!(codec = avcodec_find_encoder(AV_CODEC_ID_MPEG1VIDEO)))
{
return -1;
}
//Allocate context based on codec
if (!(context = avcodec_alloc_context3(codec)))
{
return -2;
}
//Setup Context
// put sample parameters
context->bit_rate = 4000000;
// resolution must be a multiple of two
context->width = 1280;
context->height = 720;
// frames per second
context->time_base = (AVRational){1,25};
context->inter_quant_bias = 96;
context->gop_size = 10;
context->max_b_frames = 1;
//IDs
context->pix_fmt = AV_PIX_FMT_YUV420P;
context->codec_id = AV_CODEC_ID_MPEG1VIDEO;
context->codec_type = AVMEDIA_TYPE_VIDEO;
if (AV_CODEC_ID_MPEG1VIDEO == AV_CODEC_ID_H264)
{
av_opt_set(context->priv_data, "preset", "slow", 0);
}
if ((result = avcodec_open2(context, codec, NULL)) < 0)
{
//Failed opening Codec!
}
您可能有兴趣了解libx264处理的H.264/AVC格式是否已获得专利,并且您需要支付版税以分发基于此产品的产品。至于你的编程问题,你是否尝试过其他像素格式,如AV_PIX_FMT_YUV422P或其他值? – personne3000 2014-09-24 10:56:01
我尝试过其他格式,如AV_PIX_FMT_YUV422P,但结果总是相同的。 – DundeeDave 2014-09-24 11:01:34
因此,完全相同的代码在Windows上工作,但在Android上失败?你是如何得到这两个ffmpeg版本的,你是否自己编译源代码? ffmpeg需要编译支持x264(可选)才能支持,所以编解码器的支持可能不同 – personne3000 2014-09-24 11:09:53