m0_61770108 2024-08-01 17:39 采纳率: 12.3%
浏览 110
已结题

FFmpeg中avcodec_open2打开编码器失败

FFmpeg中avcodec_open2打开编码器失败
FFmpeg中avcodec_open2打开编码器失败
源码


//配置h265解码器
    OutputVideoCodec = avcodec_find_encoder(AV_CODEC_ID_HEVC);
    if(!OutputVideoCodec){
        qDebug()<<"初始化h265解码器失败";
        return;
    }
    //保存编码器相关信息
    OutputVideoCodecContext = avcodec_alloc_context3(OutputVideoCodec);
    if(!OutputVideoCodecContext){
        qDebug()<<"保存编码器相关信息失败";
        return;
    }

    //配置编码器上下文
    OutputVideoCodecContext->bit_rate = 2000000; // 比特率
    OutputVideoCodecContext->width = InputVideoCodecContext->width; // 宽度
    OutputVideoCodecContext->height = InputVideoCodecContext->height; // 高度
    OutputVideoCodecContext->gop_size = 12; // GOP大小
    OutputVideoCodecContext->pix_fmt = AV_PIX_FMT_YUV420P; // 输出像素格式
    OutputVideoCodecContext->time_base = InputVideoCodecContext->time_base; // 时间基
    OutputVideoCodecContext->framerate = InputVideoCodecContext->framerate; // 帧率

    //打开解码器
    ret = avcodec_open2(OutputVideoCodecContext,OutputVideoCodec,NULL);
    if(ret < 0){
        char *erroeMsg = new char[32];
        av_strerror(ret,erroeMsg,1024);
        qDebug()<<"打开输出解码器失败"<<ret<<erroeMsg;
        return;
    }

报错信息

img

  • 写回答

1条回答 默认 最新

  • ontheway-xx 2024-08-01 17:48
    关注

    time_base 有值吗

    评论

报告相同问题?

问题事件

  • 已结题 (查看结题原因) 8月2日
  • 创建了问题 8月1日