If you set
codecContext->sample_aspect_ratio.num = 4;
codecContext->sample_aspect_ratio.den = 3;
HEVC encoder will work, but there is no video on the output.
Frage
i'm trying to use h265 encoder in ffmpeg library but give me this error:
Cannot open libx265 encoder.
this is my code:
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;
}
This code works for h264 encoder, anyone know why doesn't work with hevc?
Lösung
If you set
codecContext->sample_aspect_ratio.num = 4;
codecContext->sample_aspect_ratio.den = 3;
HEVC encoder will work, but there is no video on the output.
Andere Tipps
Hi, did you reach to open libx265
encoder ?
I've had the same trouble and tried using AV_CODEC_ID_H265
instead.
I've had the same trouble before with libx264
but i resolved it, by setting :
av_dict_set(¶m, "profile", "high", 0);
It seems that something was missing in the codec configuration.