[FFmpeg-devel] [PATCH v2 1/2] lavc, doc, configure: add libxavs2 video encoder wrapper
Michael Niedermayer
michael at niedermayer.cc
Sat Sep 1 23:53:09 EEST 2018
On Fri, Aug 31, 2018 at 06:30:56PM +0800, hwren wrote:
> Signed-off-by: hwren <hwrenx at 126.com>
> ---
> Changelog | 1 +
> configure | 4 +
> doc/encoders.texi | 40 ++++++
> doc/general.texi | 14 +++
> libavcodec/Makefile | 1 +
> libavcodec/allcodecs.c | 1 +
> libavcodec/libxavs2.c | 330 +++++++++++++++++++++++++++++++++++++++++++++++++
> libavcodec/version.h | 2 +-
> 8 files changed, 392 insertions(+), 1 deletion(-)
> create mode 100644 libavcodec/libxavs2.c
>
> diff --git a/Changelog b/Changelog
> index 0975fee..8377956 100644
> --- a/Changelog
> +++ b/Changelog
> @@ -21,6 +21,7 @@ version <next>:
> - Brooktree ProSumer video decoder
> - MatchWare Screen Capture Codec decoder
> - WinCam Motion Video decoder
> +- AVS2 video encoder via libxavs2
>
>
> version 4.0:
> diff --git a/configure b/configure
> index 8bbcd53..c439d2a 100755
> --- a/configure
> +++ b/configure
> @@ -280,6 +280,7 @@ External library support:
> --enable-libx264 enable H.264 encoding via x264 [no]
> --enable-libx265 enable HEVC encoding via x265 [no]
> --enable-libxavs enable AVS encoding via xavs [no]
> + --enable-libxavs2 enable AVS2 encoding via xavs2 [no]
> --enable-libxcb enable X11 grabbing using XCB [autodetect]
> --enable-libxcb-shm enable X11 grabbing shm communication [autodetect]
> --enable-libxcb-xfixes enable X11 grabbing mouse rendering [autodetect]
> @@ -1667,6 +1668,7 @@ EXTERNAL_LIBRARY_GPL_LIST="
> libx264
> libx265
> libxavs
> + libxavs2
> libxvid
> "
>
> @@ -3132,6 +3134,7 @@ libx264rgb_encoder_deps="libx264 x264_csp_bgr"
> libx264rgb_encoder_select="libx264_encoder"
> libx265_encoder_deps="libx265"
> libxavs_encoder_deps="libxavs"
> +libxavs2_encoder_deps="libxavs2"
> libxvid_encoder_deps="libxvid"
> libzvbi_teletext_decoder_deps="libzvbi"
> vapoursynth_demuxer_deps="vapoursynth"
> @@ -6164,6 +6167,7 @@ enabled libx264 && { check_pkg_config libx264 x264 "stdint.h x264.h" x
> enabled libx265 && require_pkg_config libx265 x265 x265.h x265_api_get &&
> require_cpp_condition x265.h "X265_BUILD >= 68"
> enabled libxavs && require libxavs "stdint.h xavs.h" xavs_encoder_encode "-lxavs $pthreads_extralibs $libm_extralibs"
> +enabled libxavs2 && require_pkg_config libxavs2 "xavs2 >= 1.2.77" "stdint.h xavs2.h" xavs2_api_get
> enabled libxvid && require libxvid xvid.h xvid_global -lxvidcore
> enabled libzimg && require_pkg_config libzimg "zimg >= 2.7.0" zimg.h zimg_get_api_version
> enabled libzmq && require_pkg_config libzmq libzmq zmq.h zmq_ctx_new
> diff --git a/doc/encoders.texi b/doc/encoders.texi
> index 7b09575..b5f9c5e 100644
> --- a/doc/encoders.texi
> +++ b/doc/encoders.texi
> @@ -2726,6 +2726,46 @@ Reduces detail but attempts to preserve color at extremely low bitrates.
>
> @end table
>
> + at section libxavs2
> +
> +xavs2 AVS2-P2/IEEE1857.4 encoder wrapper.
> +
> +This encoder requires the presence of the libxavs2 headers and library
> +during configuration. You need to explicitly configure the build with
> + at option{--enable-libxavs2}.
> +
> + at subsection Options
> +
> + at table @option
> + at item i_lcurow_threads
> +Set the number of parallel threads for rows from 1 to 8 (default 5).
> +
> + at item i_initial_qp
> +Set the xavs2 quantization parameter from 1 to 63 (default 34).
> +
> + at item preset_level
> +Set the Speed level from 0 to 9 (default 0).
> +
> + at item intra_period
> +Set the Intra period from 3 to 100 (default 4).
> +
> + at item hierarchical_ref
> +Set the hierarchical reference from 0 to 1 (default 1).
> +
> + at item num_bframes
> +Set the number of B frames from 0 to 15 (default 7).
> +
> + at item xavs2-params
> +Set xavs2 options using a list of @var{key}=@var{value} couples separated
> +by ":".
> +
> +For example to specify libxavs2 encoding options with @option{-xavs2-params}:
> +
> + at example
> +ffmpeg -i input -c:v libxavs2 -xavs2-params -preset_level=5 output.avs2
> + at end example
> + at end table
> +
> @c man end VIDEO ENCODERS
>
> @chapter Subtitles Encoders
> diff --git a/doc/general.texi b/doc/general.texi
> index 06f7a78..05f7bcd9 100644
> --- a/doc/general.texi
> +++ b/doc/general.texi
> @@ -17,6 +17,20 @@ for more formats. None of them are used by default, their use has to be
> explicitly requested by passing the appropriate flags to
> @command{./configure}.
>
> + at section libxavs2
> +
> +FFmpeg can make use of the xavs2 library for AVS2-P2/IEEE1857.4 video encoding.
> +
> +Go to @url{https://github.com/pkuvcl/xavs2} and follow the instructions for
> +installing the library. Then pass @code{--enable-libxavs2} to configure to
> +enable it.
> +
> + at float NOTE
> +libxavs2 is under the GNU Public License Version 2 or later
> +(see @url{http://www.gnu.org/licenses/old-licenses/gpl-2.0.html} for
> +details), you must upgrade FFmpeg's license to GPL in order to use it.
> + at end float
> +
> @section libdavs2
>
> FFmpeg can make use of the davs2 library for AVS2-P2/IEEE1857.4 video decoding.
> diff --git a/libavcodec/Makefile b/libavcodec/Makefile
> index f8673f0..bf17bf7 100644
> --- a/libavcodec/Makefile
> +++ b/libavcodec/Makefile
> @@ -992,6 +992,7 @@ OBJS-$(CONFIG_LIBX262_ENCODER) += libx264.o
> OBJS-$(CONFIG_LIBX264_ENCODER) += libx264.o
> OBJS-$(CONFIG_LIBX265_ENCODER) += libx265.o
> OBJS-$(CONFIG_LIBXAVS_ENCODER) += libxavs.o
> +OBJS-$(CONFIG_LIBXAVS2_ENCODER) += libxavs2.o
> OBJS-$(CONFIG_LIBXVID_ENCODER) += libxvid.o
> OBJS-$(CONFIG_LIBZVBI_TELETEXT_DECODER) += libzvbi-teletextdec.o ass.o
>
> diff --git a/libavcodec/allcodecs.c b/libavcodec/allcodecs.c
> index a461131..493ff8f 100644
> --- a/libavcodec/allcodecs.c
> +++ b/libavcodec/allcodecs.c
> @@ -711,6 +711,7 @@ extern AVCodec ff_libx264_encoder;
> extern AVCodec ff_libx264rgb_encoder;
> extern AVCodec ff_libx265_encoder;
> extern AVCodec ff_libxavs_encoder;
> +extern AVCodec ff_libxavs2_encoder;
> extern AVCodec ff_libxvid_encoder;
> extern AVCodec ff_libzvbi_teletext_decoder;
>
> diff --git a/libavcodec/libxavs2.c b/libavcodec/libxavs2.c
> new file mode 100644
> index 0000000..c9e4863
> --- /dev/null
> +++ b/libavcodec/libxavs2.c
> @@ -0,0 +1,330 @@
> +/*
> + * AVS2 encoding using the xavs2 library
> + *
> + * Copyright (C) 2018 Yiqun Xu, <yiqun.xu at vipl.ict.ac.cn>
> + * Falei Luo, <falei.luo at gmail.com>
> + * Huiwen Ren, <hwrenx at gmail.com>
> + *
> + * This file is part of FFmpeg.
> + *
> + * FFmpeg is free software; you can redistribute it and/or
> + * modify it under the terms of the GNU Lesser General Public
> + * License as published by the Free Software Foundation; either
> + * version 2.1 of the License, or (at your option) any later version.
> + *
> + * FFmpeg is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
> + * Lesser General Public License for more details.
> + *
> + * You should have received a copy of the GNU Lesser General Public
> + * License along with FFmpeg; if not, write to the Free Software
> + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
> + */
> +
> +#include <ctype.h>
> +
> +#include "xavs2.h"
> +#include "avcodec.h"
> +#include "mpeg12.h"
> +#include "internal.h"
> +#include "libavutil/internal.h"
> +#include "libavutil/mem.h"
> +#include "libavutil/opt.h"
> +#include "libavutil/imgutils.h"
> +#include "libavutil/avassert.h"
> +#include "libavutil/avstring.h"
> +#include "libavutil/common.h"
> +#include "libavutil/avutil.h"
> +
> +#define DELAY_FRAMES 8
> +
> +typedef struct XAVS2EContext {
> + AVClass *class;
> +
> + void* handle;
> +
> + int i_lcurow_threads;
> + int i_initial_qp;
> + int preset_level;
> + int intra_period;
> +
> + void *encoder;
> + char *xavs2_opts;
> +
> + int b_hierarchical_reference;
> + int num_b_frames;
> +
> + xavs2_outpacket_t packet;
> + xavs2_param_t *param;
> +
> + const xavs2_api_t *api;
> +
> +} XAVS2EContext;
> +
> +static av_cold int xavs2_init(AVCodecContext *avctx)
> +{
> + XAVS2EContext *cae= avctx->priv_data;
> +
> + char str_bd[16], str_iqp[16], str_w[16], str_h[16];
> + char str_preset[16], str_hr[16], str_bf[16];
> + char str_iv[16], str_TBR[16], str_fr[16];
> +
> + if (avctx->pix_fmt == AV_PIX_FMT_YUV420P) {
> + /* get API handler */
> + cae->api = xavs2_api_get(8);
> + cae->param = cae->api->opt_alloc();
> +
> + if (!cae->param) {
> + av_log(avctx, AV_LOG_ERROR, "param alloc failed\n");
> + return AVERROR(EINVAL);
> + }
> +
> + sprintf(str_bd, "%d", 8);
> + sprintf(str_iqp, "%d", 32);
theres no need for sprintf() here, its just a constant string
and if it was not a constant then sprintf() would be unsafe as it
lacks a end of array check
[...]
--
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
Those who would give up essential Liberty, to purchase a little
temporary Safety, deserve neither Liberty nor Safety -- Benjamin Franklin
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 181 bytes
Desc: not available
URL: <http://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20180901/809da04d/attachment.sig>
More information about the ffmpeg-devel
mailing list