ChinaFFmpeg

 找回密码
 立即注册

QQ登录

只需一步,快速开始

查看: 10699|回复: 2

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

[复制链接]
发表于 2019-9-23 10:58:23 | 显示全部楼层 |阅读模式
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;
                }

回复

使用道具 举报

 楼主| 发表于 2019-9-23 11:00:25 | 显示全部楼层
程序用于H265转jpeg图片
回复 支持 反对

使用道具 举报

发表于 2019-9-29 13:51:57 | 显示全部楼层
你可以尝试用av_err2str方法将错误码转换成字符串看看是什么原因
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手机版|Archiver|ChinaFFmpeg

GMT+8, 2024-4-20 19:45 , Processed in 0.067617 second(s), 14 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表