8月 发表于 2019-9-23 10:58:23

avcodec_open2返回-22是啥问题?(ffmpeg 4.2.1)

AVCodec *pMJPEGCodec = NULL;
        AVCodecContext *pMJPEGCtx = avcodec_alloc_context3(pCodec);// 申请AVCodecContext空间。需要传递一个编码器,也可以不传,但不会包含编码器。
        if (NULL!=pMJPEGCtx)
        {
                pMJPEGCtx->bit_rate = pCodecCtx->bit_rate;
                pMJPEGCtx->width = pCodecCtx->width;
                pMJPEGCtx->height = pCodecCtx->height;
                pMJPEGCtx->pix_fmt = AV_PIX_FMT_YUVJ420P;// pix;
                pMJPEGCtx->codec_id = AV_CODEC_ID_MJPEG;
                pMJPEGCtx->codec_type = AVMEDIA_TYPE_VIDEO;
                pMJPEGCtx->time_base.num = pCodecCtx->time_base.num;
                pMJPEGCtx->time_base.den = pCodecCtx->time_base.den;
                pMJPEGCodec = avcodec_find_encoder(pMJPEGCtx->codec_id);
                if (NULL== pMJPEGCodec)
                {
                        AfxMessageBox(_T("找不到解码器!返回!"));
                        return false;
                }
                int open = avcodec_open2(pMJPEGCtx, pMJPEGCodec, NULL);
                if (open<0)//这里返回-22
                {
                        return false;
                }

8月 发表于 2019-9-23 11:00:25

程序用于H265转jpeg图片

Turisla 发表于 2019-9-29 13:51:57

你可以尝试用av_err2str方法将错误码转换成字符串看看是什么原因
页: [1]
查看完整版本: avcodec_open2返回-22是啥问题?(ffmpeg 4.2.1)