我正在尝试在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吗?
最佳答案
如果您设定
codecContext->sample_aspect_ratio.num = 4;
codecContext->sample_aspect_ratio.den = 3;
HEVC编码器可以工作,但是输出上没有视频。