我正在尝试在ffmpeg库中使用h265编码器,但是给我这个错误:
Cannot open libx265 encoder.
这是我的代码:
formatContext = avformat_alloc_context();
videoStream = avformat_new_stream(formatContext,0);
if(!videoStream ) {
//error
return;
}
av_init_packet(&packet);
codecContext=videoStream->codec;
codecContext->codec_type = AVMEDIA_TYPE_VIDEO;
codecContext->width = width;
codecContext->height = height;
codecContext->time_base.den = fps;
codecContext->time_base.num = 1;
codecContext->pix_fmt = AV_PIX_FMT_YUV420P;
codecContext->codec_id = AV_CODEC_ID_HEVC;
AVDictionary *param = 0;
av_dict_set(¶m, "x265-params", "qp=20", 0);
av_dict_set(¶m, "preset", "ultrafast", 0);
av_dict_set(¶m, "tune", "zero-latency", 0);
av_dict_set(¶m, "qmin", "0", 0);
av_dict_set(¶m, "qmax", "69", 0);
av_dict_set(¶m, "qdiff", "4", 0);
codec = avcodec_find_encoder(codecContext->codec_id);
if (!codec) {
//codec not found
return;
}
int rt = avcodec_open2(codecContext, codec, ¶m); // <----- fails here
if (rt < 0) {
// fails here!!
return;
}
此代码适用于h264编码器,任何人都知道为什么不能使用hevc?
答案 0 :(得分:1)
嗨,你有没有打开libx265
编码器?
我遇到了同样的麻烦,并尝试使用AV_CODEC_ID_H265
代替。
我在使用libx264
之前遇到了同样的麻烦,但我通过设置:
av_dict_set(¶m, "profile", "high", 0);
似乎编解码器配置中缺少某些内容。
答案 1 :(得分:1)
如果您设置
codecContext->sample_aspect_ratio.num = 4;
codecContext->sample_aspect_ratio.den = 3;
HEVC编码器可以工作,但输出上没有视频。