ffmpeg open问题
做H264视频解码部分,用到FFmpeg的H264解码,如果只有一个视频通道初始化的时候是没有问题的,
但是在多通道同时初始化的时候,就是出现avcodec_open2返回失败的可能
打印信息: insufficient thread locking around avcodec_open/close()
想问一下ffmpeg不支持多线程吗?
在多线程同时打开的时候,有什么避免出现那种情况?
有没有做过H264解码的指点一下啊
avcodec_register_all();
//av_dict_set(&opts, "b", "2.5M", 0);
//av_register_all();
/* find the h264 video decoder */
pDec->codec = avcodec_find_decoder(CODEC_ID_H264);
if (!pDec->codec)
{
fprintf(stderr, "avcodec_find_decoder fail\n");
goto ERROR_DEC_CREATE;
}
pDec->c = avcodec_alloc_context3(pDec->codec);
if (!pDec->c)
{
fprintf(stderr, "avcodec_alloc_context3 fail\n");
goto ERROR_DEC_CREATE;
}
if(pDec->codec->capabilities&CODEC_CAP_TRUNCATED)
pDec->c->flags|= CODEC_FLAG_TRUNCATED; /* we do not send complete frames */
/* For some codecs, such as msmpeg4 and mpeg4, width and height
MUST be initialized there because this information is not
available in the bitstream. */
/* open it */
//av_lockmgr_register(lockmgr);
//多线程情况下,avcodec_open2有时候返回失败
if ((s32Ret = avcodec_open2(pDec->c, pDec->codec, NULL)) < 0)
{
fprintf(stderr, "Could not open codec:%d\n", s32Ret);
goto ERROR_DEC_CREATE;
}
pDec->picture = avcodec_alloc_frame();
if (!pDec->picture)
{
fprintf(stderr, "Could not allocate video frame\n");
goto ERROR_DEC_CREATE;
}
return pDec;