Android通过JNI调用ffmpeg实现解码,avcodec_open2返回错误代码-22

对牛乱弹琴 2014-05-13 11:08:54
JNIEXPORT int JNICALL Java_com_example_testlive_MainActivity_Init( JNIEnv* env, jobject thiz)
{
//avcodec_init();
avcodec_register_all();
// Register all formats and codecs
av_register_all();
LOGI("register");
// Find the decoder for the video stream
pCodec=avcodec_find_decoder(CODEC_ID_H264);
if(pCodec == NULL)
{
LOGI("avcodec_find_decoder failed");
return -1; // Codec not found
}
else
{
pCodecCtx=avcodec_alloc_context3(pCodec);
if (pCodecCtx == NULL)
{
LOGI("avcodec_alloc_context3 failed");
}

pCodecCtx->time_base.num = 1; //
pCodecCtx->time_base.den = 25;
pCodecCtx->bit_rate = 0; //
pCodecCtx->frame_number = 1; //
pCodecCtx->codec_type = CODEC_ID_H264;
pCodecCtx->width = 704; //
pCodecCtx->height = 576;
}
// Open codec
LOGI("avcodec_find_decoder susscess");
//av_dict_set(&optionsDict, "b", "2.5M", 0);
//pCodec->capabilities=CODEC_CAP_DELAY;
if(pCodec->capabilities&CODEC_CAP_TRUNCATED)
pCodecCtx->flags|= CODEC_FLAG_TRUNCATED;
int ret = 0;
if((ret = avcodec_open2(pCodecCtx, pCodec, NULL))<0)
{
LOGI("avcodec_open2 failed");
return ret; // Could not open codec ******************程序执行到这里返回-22************
}
// Allocate video frame
pFrame=avcodec_alloc_frame();

// Allocate an AVFrame structure
pFrameRGBA=avcodec_alloc_frame();
if(pFrameRGBA==NULL)
{
LOGI("avcodec_alloc_frame failed");
return -1;
}
//get the scaling context
sws_ctx = sws_getContext
(
pCodecCtx->width,
pCodecCtx->height,
pCodecCtx->pix_fmt,
pCodecCtx->width,
pCodecCtx->height,
AV_PIX_FMT_RGBA,
SWS_BILINEAR,
NULL,
NULL,
NULL
);

// Assign appropriate parts of bitmap to image planes in pFrameRGBA
// Note that pFrameRGBA is an AVFrame, but AVFrame is a superset
// of AVPicture
//avpicture_fill((AVPicture *)pFrameRGBA, buffer, AV_PIX_FMT_RGBA,
// pCodecCtx->width, pCodecCtx->height);

return 0;
}


请问这是为什么啊,ffmpeg是最新版本
...全文
3952 16 打赏 收藏 转发到动态 举报
写回复
用AI写文章
16 条回复
切换为时间正序
请发表友善的回复…
发表回复
vliubingv 2016-06-19
  • 打赏
  • 举报
回复
楼主 给我一个支持全部编码的版本呗 349857978@qq.com 谢谢了
zhiyao931007 2016-04-07
  • 打赏
  • 举报
回复
遇到同样问题。不过我是在linux下可以通过,JNI移植到安卓时,可以打开视频编码器,打开音频编码器的时候就返回-22。同求解
NWDB38 2016-03-09
  • 打赏
  • 举报
回复
解决了吗 xiaoyanmint@126.com 麻烦啊 万分感谢
梦中守望 2015-09-07
  • 打赏
  • 举报
回复
我的也是啊。。。打不开,求助
弛简 2015-08-20
  • 打赏
  • 举报
回复
求发送,862284475@qq.com
弛简 2015-08-19
  • 打赏
  • 举报
回复
我发现,编译的ffmpeg有好几种都打不开的
弛简 2015-08-19
  • 打赏
  • 举报
回复
楼主这个问题解决了么?
LovingLife231 2015-07-08
  • 打赏
  • 举报
回复
楼主,提前谢过,wangxueqing231@163.com
hellofly01 2015-02-25
  • 打赏
  • 举报
回复
编译了半天也 没成功,楼主可以发一份给我吗?万分感 谢!!804364449@qq.com
对牛乱弹琴 2014-11-20
  • 打赏
  • 举报
回复
引用 6 楼 coffee_shop 的回复:
楼主,能否发一份最新编译好的库给我吗?我编译很久都不行。。1539991400@qq.com 谢谢!
发给你了
hdev0225 2014-11-10
  • 打赏
  • 举报
回复
楼主,能否发一份最新编译好的库给我吗?我编译很久都不行。。1539991400@qq.com 谢谢!
chaooooooo 2014-09-12
  • 打赏
  • 举报
回复
是你的库里面不包含哪几种解码形式 重新编下库
对牛乱弹琴 2014-08-12
  • 打赏
  • 举报
回复
引用 3 楼 xia1234567890123 的回复:
我也遇到了这个问题,楼主解决了吗?是什么原因照成的?
CODEC_ID_H264---->AV_CODEC_ID_H264,版本问题
Xia_Evan 2014-08-04
  • 打赏
  • 举报
回复
我也遇到了这个问题,楼主解决了吗?是什么原因照成的?
对牛乱弹琴 2014-05-13
  • 打赏
  • 举报
回复
我发现把CODEC_ID_H264换成CODEC_ID_MPEG4就成功了,为什么呢?我需要的是CODEC_ID_H264啊,
avcodec_find_decoder(CODEC_ID_MPEG4);//CODEC_ID_H264
对牛乱弹琴 2014-05-13
  • 打赏
  • 举报
回复
没人看吗?还是我发错版块了?版主在不

18,777

社区成员

发帖
与我相关
我的任务
社区描述
Linux/Unix社区 专题技术讨论区
社区管理员
  • 专题技术讨论区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧