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;
}
报错信息