Pregunta

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?

¿Fue útil?

Solución

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.

Otros consejos

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.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top