Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ffmpeg hevc (x265) encoding

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(&param, "x265-params", "qp=20", 0);
av_dict_set(&param, "preset", "ultrafast", 0);
av_dict_set(&param, "tune", "zero-latency", 0);
av_dict_set(&param, "qmin", "0", 0);
av_dict_set(&param, "qmax", "69", 0);
av_dict_set(&param, "qdiff", "4", 0);
codec = avcodec_find_encoder(codecContext->codec_id);
if (!codec) {
    //codec not found
    return;
}
int rt = avcodec_open2(codecContext, codec, &param); // <----- fails here
if (rt < 0) {
    // fails here!!
    return;
}

This code works for h264 encoder, anyone know why doesn't work with hevc?

like image 649
luca Avatar asked Jul 09 '26 00:07

luca


1 Answers

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(&param, "profile", "high", 0);

It seems that something was missing in the codec configuration.

like image 80
user3387182 Avatar answered Jul 11 '26 13:07

user3387182



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!