[FFmpeg-devel] [PATCH v2] Add libx265 encoder
James Almer
jamrial at gmail.com
Tue Feb 11 22:29:42 CET 2014
On 11/02/14 5:41 PM, Derek Buitenhuis wrote:
> Signed-off-by: Derek Buitenhuis <derek.buitenhuis at gmail.com>
> ---
> I didn't change the configure check, since, unlike x264,
> x265's version is in no way related to its SONAME, which
> is what we want to check.
> ---
> Changelog | 1 +
> LICENSE | 1 +
> configure | 7 ++
> libavcodec/Makefile | 1 +
> libavcodec/allcodecs.c | 1 +
> libavcodec/libx265.c | 262 +++++++++++++++++++++++++++++++++++++++++++++++++
> libavcodec/version.h | 2 +-
> 7 files changed, 274 insertions(+), 1 deletion(-)
> create mode 100644 libavcodec/libx265.c
Missing general.texi changes for HEVC encoding.
>
> diff --git a/Changelog b/Changelog
> index 38c17bc..a8183b5 100644
> --- a/Changelog
> +++ b/Changelog
> @@ -26,6 +26,7 @@ version <next>
> MP3, AIFF, and OMA files), FLAC header, and the AVI "junk" block.
> - Mirillis FIC video decoder
> - Support DNx444
> +- libx265 encoder
nit: wrapper?
[...]
> +static av_cold int libx265_encode_init(AVCodecContext *avctx)
> +{
> + libx265Context *ctx = avctx->priv_data;
> + x265_nal *nal;
> + uint8_t *buf;
> + int nnal;
> + int ret;
> + int i;
> +
> + avctx->coded_frame = av_frame_alloc();
> + if (!avctx->coded_frame) {
> + av_log(avctx, AV_LOG_ERROR, "Could not allocate frame.\n");
> + return AVERROR(ENOMEM);
> + }
> +
> + ctx->params = x265_param_alloc();
> + if (!ctx->params) {
> + av_log(avctx, AV_LOG_ERROR, "Could not allocate x265 param structure.\n");
> + return AVERROR(ENOMEM);
> + }
> +
> + x265_param_default(ctx->params);
> + if (x265_param_default_preset(ctx->params, ctx->preset, ctx->tune) < 0)
> + av_log(avctx, AV_LOG_WARNING, "Invalid preset or tune.\n");
Shouldn't this return AVERROR(EINVAL) instead? We're currently doing that with libx264.
Doesn't seem like a good idea proceeding with what could potentially be a big encoding
after the user typoed the preset/tune he wanted.
[...]
> +#define OFFSET(x) offsetof(libx265Context, x)
> +#define VE AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM
> +static const AVOption options[] = {
> + { "preset", "set the x265 preset", OFFSET(preset), AV_OPT_TYPE_STRING, { 0 }, 0, 0, VE },
> + { "tune", "set the x265 tune parameter", OFFSET(tune), AV_OPT_TYPE_STRING, { 0 }, 0, 0, VE },
> + { "x265-params", "set the x265 configuration using a :-separated list of key=value parameters", OFFSET(x265_opts), AV_OPT_TYPE_STRING, { 0 }, 0, 0, VE },
> + { NULL },
> +};
nit: vertical alignment.
> +
> +static const AVClass class = {
> + .class_name = "libx265",
> + .item_name = av_default_item_name,
> + .option = options,
> + .version = LIBAVUTIL_VERSION_INT,
> +};
> +
> +AVCodec ff_libx265_encoder = {
> + .name = "libx265",
> + .long_name = NULL_IF_CONFIG_SMALL("libx265 H.265 / HEVC"),
> + .type = AVMEDIA_TYPE_VIDEO,
> + .id = AV_CODEC_ID_HEVC,
> + .init = libx265_encode_init,
> + .init_static_data = libx265_encode_init_csp,
> + .encode2 = libx265_encode_frame,
> + .close = libx265_encode_close,
> + .priv_data_size = sizeof(libx265Context),
> + .priv_class = &class,
> + .capabilities = CODEC_CAP_DELAY | CODEC_CAP_AUTO_THREADS,
> +};
> diff --git a/libavcodec/version.h b/libavcodec/version.h
> index 240113b..a698321 100644
> --- a/libavcodec/version.h
> +++ b/libavcodec/version.h
> @@ -29,7 +29,7 @@
> #include "libavutil/version.h"
>
> #define LIBAVCODEC_VERSION_MAJOR 55
> -#define LIBAVCODEC_VERSION_MINOR 50
> +#define LIBAVCODEC_VERSION_MINOR 51
> #define LIBAVCODEC_VERSION_MICRO 100
>
> #define LIBAVCODEC_VERSION_INT AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \
>
More information about the ffmpeg-devel
mailing list