1
0
mirror of https://github.com/FFmpeg/FFmpeg.git synced 2024-12-23 12:43:46 +02:00

libx265: Use the Multi-library Interface

Use the Multi-library interface to load at runtime x265 libraries
supporting alternative bit depths (e.g. 8bit and 16bit).

The linked library will try to load the library supporting the
pixel format if it is not supported by itself.

Fallback requesting the native library (passing 0 to x265_api_get) if
a library supporting the requested bit depth is not available.

Signed-off-by: Gopu Govindaswamy <gopu@multicorewareinc.com>
Signed-off-by: Derek Buitenhuis <derek.buitenhuis@gmail.com>
Signed-off-by: Luca Barbato <lu_zero@gentoo.org>
This commit is contained in:
Gopu Govindaswamy 2015-05-11 16:25:59 +01:00 committed by Luca Barbato
parent 85ca012ba6
commit 3b5e5e6a29
2 changed files with 19 additions and 14 deletions

4
configure vendored
View File

@ -4268,8 +4268,8 @@ enabled libx264 && require_pkg_config x264 "stdint.h x264.h" x264_enco
{ check_cpp_condition x264.h "X264_BUILD >= 118" || { check_cpp_condition x264.h "X264_BUILD >= 118" ||
die "ERROR: libx264 version must be >= 0.118."; } die "ERROR: libx264 version must be >= 0.118."; }
enabled libx265 && require_pkg_config x265 x265.h x265_encoder_encode && enabled libx265 && require_pkg_config x265 x265.h x265_encoder_encode &&
{ check_cpp_condition x265.h "X265_BUILD >= 17" || { check_cpp_condition x265.h "X265_BUILD >= 57" ||
die "ERROR: libx265 version must be >= 17."; } die "ERROR: libx265 version must be >= 57."; }
enabled libxavs && require libxavs xavs.h xavs_encoder_encode -lxavs enabled libxavs && require libxavs xavs.h xavs_encoder_encode -lxavs
enabled libxvid && require libxvid xvid.h xvid_global -lxvidcore enabled libxvid && require libxvid xvid.h xvid_global -lxvidcore
enabled mmal && { check_lib interface/mmal/mmal.h mmal_port_connect -lmmal_core -lmmal_util -lmmal_vc_client -lbcm_host || enabled mmal && { check_lib interface/mmal/mmal.h mmal_port_connect -lmmal_core -lmmal_util -lmmal_vc_client -lbcm_host ||

View File

@ -39,6 +39,7 @@ typedef struct libx265Context {
x265_encoder *encoder; x265_encoder *encoder;
x265_param *params; x265_param *params;
const x265_api *api;
float crf; float crf;
char *preset; char *preset;
@ -67,10 +68,10 @@ static av_cold int libx265_encode_close(AVCodecContext *avctx)
av_frame_free(&avctx->coded_frame); av_frame_free(&avctx->coded_frame);
x265_param_free(ctx->params); ctx->api->param_free(ctx->params);
if (ctx->encoder) if (ctx->encoder)
x265_encoder_close(ctx->encoder); ctx->api->encoder_close(ctx->encoder);
return 0; return 0;
} }
@ -79,6 +80,10 @@ static av_cold int libx265_encode_init(AVCodecContext *avctx)
{ {
libx265Context *ctx = avctx->priv_data; libx265Context *ctx = avctx->priv_data;
ctx->api = x265_api_get(av_pix_fmt_desc_get(avctx->pix_fmt)->comp[0].depth_minus1 + 1);
if (!ctx->api)
ctx->api = x265_api_get(0);
if (avctx->strict_std_compliance > FF_COMPLIANCE_EXPERIMENTAL && if (avctx->strict_std_compliance > FF_COMPLIANCE_EXPERIMENTAL &&
!av_pix_fmt_desc_get(avctx->pix_fmt)->log2_chroma_w) { !av_pix_fmt_desc_get(avctx->pix_fmt)->log2_chroma_w) {
av_log(avctx, AV_LOG_ERROR, av_log(avctx, AV_LOG_ERROR,
@ -93,13 +98,13 @@ static av_cold int libx265_encode_init(AVCodecContext *avctx)
return AVERROR(ENOMEM); return AVERROR(ENOMEM);
} }
ctx->params = x265_param_alloc(); ctx->params = ctx->api->param_alloc();
if (!ctx->params) { if (!ctx->params) {
av_log(avctx, AV_LOG_ERROR, "Could not allocate x265 param structure.\n"); av_log(avctx, AV_LOG_ERROR, "Could not allocate x265 param structure.\n");
return AVERROR(ENOMEM); return AVERROR(ENOMEM);
} }
if (x265_param_default_preset(ctx->params, ctx->preset, ctx->tune) < 0) { if (ctx->api->param_default_preset(ctx->params, ctx->preset, ctx->tune) < 0) {
int i; int i;
av_log(avctx, AV_LOG_ERROR, "Error setting preset/tune %s/%s.\n", ctx->preset, ctx->tune); av_log(avctx, AV_LOG_ERROR, "Error setting preset/tune %s/%s.\n", ctx->preset, ctx->tune);
@ -148,7 +153,7 @@ static av_cold int libx265_encode_init(AVCodecContext *avctx)
avctx->sample_aspect_ratio.num, avctx->sample_aspect_ratio.num,
avctx->sample_aspect_ratio.den, 65535); avctx->sample_aspect_ratio.den, 65535);
snprintf(sar, sizeof(sar), "%d:%d", sar_num, sar_den); snprintf(sar, sizeof(sar), "%d:%d", sar_num, sar_den);
if (x265_param_parse(ctx->params, "sar", sar) == X265_PARAM_BAD_VALUE) { if (ctx->api->param_parse(ctx->params, "sar", sar) == X265_PARAM_BAD_VALUE) {
av_log(avctx, AV_LOG_ERROR, "Invalid SAR: %d:%d.\n", sar_num, sar_den); av_log(avctx, AV_LOG_ERROR, "Invalid SAR: %d:%d.\n", sar_num, sar_den);
return AVERROR_INVALIDDATA; return AVERROR_INVALIDDATA;
} }
@ -173,7 +178,7 @@ static av_cold int libx265_encode_init(AVCodecContext *avctx)
char crf[6]; char crf[6];
snprintf(crf, sizeof(crf), "%2.2f", ctx->crf); snprintf(crf, sizeof(crf), "%2.2f", ctx->crf);
if (x265_param_parse(ctx->params, "crf", crf) == X265_PARAM_BAD_VALUE) { if (ctx->api->param_parse(ctx->params, "crf", crf) == X265_PARAM_BAD_VALUE) {
av_log(avctx, AV_LOG_ERROR, "Invalid crf: %2.2f.\n", ctx->crf); av_log(avctx, AV_LOG_ERROR, "Invalid crf: %2.2f.\n", ctx->crf);
return AVERROR(EINVAL); return AVERROR(EINVAL);
} }
@ -191,7 +196,7 @@ static av_cold int libx265_encode_init(AVCodecContext *avctx)
if (!av_dict_parse_string(&dict, ctx->x265_opts, "=", ":", 0)) { if (!av_dict_parse_string(&dict, ctx->x265_opts, "=", ":", 0)) {
while ((en = av_dict_get(dict, "", en, AV_DICT_IGNORE_SUFFIX))) { while ((en = av_dict_get(dict, "", en, AV_DICT_IGNORE_SUFFIX))) {
int parse_ret = x265_param_parse(ctx->params, en->key, en->value); int parse_ret = ctx->api->param_parse(ctx->params, en->key, en->value);
switch (parse_ret) { switch (parse_ret) {
case X265_PARAM_BAD_NAME: case X265_PARAM_BAD_NAME:
@ -210,7 +215,7 @@ static av_cold int libx265_encode_init(AVCodecContext *avctx)
} }
} }
ctx->encoder = x265_encoder_open(ctx->params); ctx->encoder = ctx->api->encoder_open(ctx->params);
if (!ctx->encoder) { if (!ctx->encoder) {
av_log(avctx, AV_LOG_ERROR, "Cannot open libx265 encoder.\n"); av_log(avctx, AV_LOG_ERROR, "Cannot open libx265 encoder.\n");
libx265_encode_close(avctx); libx265_encode_close(avctx);
@ -221,7 +226,7 @@ static av_cold int libx265_encode_init(AVCodecContext *avctx)
x265_nal *nal; x265_nal *nal;
int nnal; int nnal;
avctx->extradata_size = x265_encoder_headers(ctx->encoder, &nal, &nnal); avctx->extradata_size = ctx->api->encoder_headers(ctx->encoder, &nal, &nnal);
if (avctx->extradata_size <= 0) { if (avctx->extradata_size <= 0) {
av_log(avctx, AV_LOG_ERROR, "Cannot encode headers.\n"); av_log(avctx, AV_LOG_ERROR, "Cannot encode headers.\n");
libx265_encode_close(avctx); libx265_encode_close(avctx);
@ -255,7 +260,7 @@ static int libx265_encode_frame(AVCodecContext *avctx, AVPacket *pkt,
int ret; int ret;
int i; int i;
x265_picture_init(ctx->params, &x265pic); ctx->api->picture_init(ctx->params, &x265pic);
if (pic) { if (pic) {
for (i = 0; i < 3; i++) { for (i = 0; i < 3; i++) {
@ -272,8 +277,8 @@ static int libx265_encode_frame(AVCodecContext *avctx, AVPacket *pkt,
X265_TYPE_AUTO; X265_TYPE_AUTO;
} }
ret = x265_encoder_encode(ctx->encoder, &nal, &nnal, ret = ctx->api->encoder_encode(ctx->encoder, &nal, &nnal,
pic ? &x265pic : NULL, &x265pic_out); pic ? &x265pic : NULL, &x265pic_out);
if (ret < 0) if (ret < 0)
return AVERROR_UNKNOWN; return AVERROR_UNKNOWN;