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

对牛乱弹琴 对牛乱弹琴 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
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是最新版本
...全文
评论 16
收藏 已收藏
分享
返回顶部
对牛乱弹琴
Linux/Unix社区 18,828 成员 11,488 内容