Re: [FFmpeg-devel] [PATCH v7 1/2] lavc, doc, configure: add libxavs2 video encoder wrapper
At 2018-09-10 02:01:32, "Mark Thompson" wrote: >On 06/09/18 14:58, hwren wrote: >> Signed-off-by: hwren >> --- >> Changelog | 1 + >> configure | 4 + >> doc/encoders.texi | 41 +++ >> doc/general.texi | 14 +++ >> libavcodec/Makefile| 1 + >> libavcodec/allcodecs.c | 1 + >> libavcodec/libxavs2.c | 303 >> + >> libavcodec/version.h | 4 +- >> 8 files changed, 367 insertions(+), 2 deletions(-) >> create mode 100644 libavcodec/libxavs2.c >> >> ... >> diff --git a/doc/encoders.texi b/doc/encoders.texi >> index 7b09575..2547acd 100644 >> --- a/doc/encoders.texi >> +++ b/doc/encoders.texi >> @@ -2726,6 +2726,47 @@ Reduces detail but attempts to preserve color at >> extremely low bitrates. >> >> @end table >> >> +@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 >> +@option{--enable-libxavs2}. >> + >> +@subsection Options >> + >> +@table @option >> +@item lcu_row_threads >> +Set the number of parallel threads for rows from 1 to 8 (default 5). >> + >> +@item initial_qp >> +Set the xavs2 quantization parameter from 1 to 63 (default 34). This is >> +used to set the initial qp for the first frame. >> + >> +@item max_qp >> +Set the max qp for rate control from 1 to 63 (default 55). >> + >> +@item min_qp >> +Set the min qp for rate control from 1 to 63 (default 20). >> + >> +@item speed_level >> +Set the Speed level from 0 to 9 (default 0). Higer is better but slower. > >Typo: higher. Fixed, thanks. ... >> diff --git a/libavcodec/libxavs2.c b/libavcodec/libxavs2.c >> new file mode 100644 >> index 000..3b0244d >> --- /dev/null >> +++ b/libavcodec/libxavs2.c >> @@ -0,0 +1,303 @@ ... >> + * >> + * 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 > >This header is never used. Cleaned, thanks. > >> + >> +#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" > >And some of these? At least avassert and imgutils aren't used, possibly some >others. Cleaned, thanks. ... >> + >> +/* Rate control */ >> +if (avctx->bit_rate > 0) { >> +xavs2_opt_set2("RateControl", "%d", 1); >> +xavs2_opt_set2("max_qp","%d", cae->max_qp); >> +xavs2_opt_set2("min_qp","%d", cae->min_qp); >> +xavs2_opt_set2("TargetBitRate", "%d", avctx->bit_rate); > >bit_rate is an int64_t, use "%"PRId64. Fixed, thanks. > >> +} >> + >> + >> +ff_mpeg12_find_best_frame_rate(avctx->framerate, , NULL, NULL, 0); >> + >> +xavs2_opt_set2("FrameRate", "%d", code); >> + >> +cae->encoder = cae->api->encoder_create(cae->param); >> + >> +if (!cae->encoder) { >> +av_log(avctx,AV_LOG_ERROR, "Can not create encoder. Null pointer >> returned\n"); >> +return AVERROR(EINVAL); >> +} >> + >> +return 0; >> +} >> + >> +static void xavs2_copy_frame_with_shift(xavs2_picture_t *pic, AVFrame >> *frame, const int shift_in) > >The AVFrame needs to be const, because that's what the encode function >received from the caller. Fixed, thanks. > >> +{ >> +int j, k; >> +for (k = 0; k < 3; k++) { >> +int i_stride = pic->img.i_stride[k]; >> +for (j = 0; j < pic->img.i_lines[k]; j++) { >> +uint16_t *p_plane = (uint16_t *)>img.img_planes[k][j * >> i_stride]; >> +int i; >> +uint8_t *p_buffer = frame->data[k] + frame->linesize[k] * j; >> +memset(p_plane, 0, i_stride); >> +for (i = 0; i < pic->img.i_width[k]; i++) { >> +p_plane[i] = p_buffer[i] << shift_in; >> +} >> +} >> +} >> +} >> + >> +static void xavs2_copy_frame(xavs2_picture_t *pic, AVFrame *frame) > >Also here. Fixed, thanks. > >> +{ >> +int j, k; >> +for (k = 0; k < 3; k++) { >> +for (j = 0; j < pic->img.i_lines[k]; j++) { >> +memcpy( pic->img.img_planes[k] + pic->img.i_stride[k] * j, >> +frame->data[k]+frame->linesize[k] * j, >> +pic->img.i_width[k] * pic->img.in_sample_size); >> +} >> +} >> +} >> + >> ... >> + >> +static const AVOption options[] = { >> +{ "lcu_row_threads" , "number of parallel threads for rows" , >> OFFSET(lcu_row_threads) , AV_OPT_TYPE_INT, {.i64 = 5 }, 0, INT_MAX, VE }, > >Did you explain
Re: [FFmpeg-devel] [PATCH v7 1/2] lavc, doc, configure: add libxavs2 video encoder wrapper
On 06/09/18 14:58, hwren wrote: > Signed-off-by: hwren > --- > Changelog | 1 + > configure | 4 + > doc/encoders.texi | 41 +++ > doc/general.texi | 14 +++ > libavcodec/Makefile| 1 + > libavcodec/allcodecs.c | 1 + > libavcodec/libxavs2.c | 303 > + > libavcodec/version.h | 4 +- > 8 files changed, 367 insertions(+), 2 deletions(-) > create mode 100644 libavcodec/libxavs2.c > > ... > diff --git a/doc/encoders.texi b/doc/encoders.texi > index 7b09575..2547acd 100644 > --- a/doc/encoders.texi > +++ b/doc/encoders.texi > @@ -2726,6 +2726,47 @@ Reduces detail but attempts to preserve color at > extremely low bitrates. > > @end table > > +@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 > +@option{--enable-libxavs2}. > + > +@subsection Options > + > +@table @option > +@item lcu_row_threads > +Set the number of parallel threads for rows from 1 to 8 (default 5). > + > +@item initial_qp > +Set the xavs2 quantization parameter from 1 to 63 (default 34). This is > +used to set the initial qp for the first frame. > + > +@item max_qp > +Set the max qp for rate control from 1 to 63 (default 55). > + > +@item min_qp > +Set the min qp for rate control from 1 to 63 (default 20). > + > +@item speed_level > +Set the Speed level from 0 to 9 (default 0). Higer is better but slower. Typo: higher. > + > +@item hierarchical_ref > +Set the hierarchical reference or not (default true). > + > +@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}: > + > +@example > +ffmpeg -i input -c:v libxavs2 -xavs2-params speed_level=5 output.avs2 > +@end example > +@end table > + > @c man end VIDEO ENCODERS > > @chapter Subtitles Encoders > ... > diff --git a/libavcodec/libxavs2.c b/libavcodec/libxavs2.c > new file mode 100644 > index 000..3b0244d > --- /dev/null > +++ b/libavcodec/libxavs2.c > @@ -0,0 +1,303 @@ > +/* > + * AVS2 encoding using the xavs2 library > + * > + * Copyright (C) 2018 Yiqun Xu, > + *Falei Luo, > + *Huiwen Ren, > + * > + * 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 This header is never used. > + > +#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" And some of these? At least avassert and imgutils aren't used, possibly some others. > + > ... > + > +static av_cold int xavs2_init(AVCodecContext *avctx) > +{ > +XAVS2EContext *cae= avctx->priv_data; > +int bit_depth, code; > + > +bit_depth = avctx->pix_fmt == AV_PIX_FMT_YUV420P ? 8 : 10; > + > +/* get API handler */ > +cae->api = xavs2_api_get(bit_depth); > + > +if (!cae->api) { > +av_log(avctx, AV_LOG_ERROR, "api get failed\n"); > +return AVERROR_EXTERNAL; > +} > + > +cae->param = cae->api->opt_alloc(); > + > +if (!cae->param) { > +av_log(avctx, AV_LOG_ERROR, "param alloc failed\n"); > +return AVERROR(ENOMEM); > +} > + > +xavs2_opt_set2("rec", "%d", 0); > +xavs2_opt_set2("log", "%d", 0); > + > +xavs2_opt_set2("width", "%d", avctx->width); > +xavs2_opt_set2("height","%d", avctx->height); > +xavs2_opt_set2("bframes", "%d", avctx->max_b_frames); > +xavs2_opt_set2("bitdepth", "%d", bit_depth); > +xavs2_opt_set2("preset","%d", cae->preset_level); > + > +/* not the same parameter as the IntraPeriod in xavs2 log */ > +xavs2_opt_set2("intraperiod", "%d", avctx->gop_size); > + > +xavs2_opt_set2("thread_frames", "%d", avctx->thread_count); > +xavs2_opt_set2("thread_rows", "%d",
[FFmpeg-devel] [PATCH v7 1/2] lavc, doc, configure: add libxavs2 video encoder wrapper
Signed-off-by: hwren --- Changelog | 1 + configure | 4 + doc/encoders.texi | 41 +++ doc/general.texi | 14 +++ libavcodec/Makefile| 1 + libavcodec/allcodecs.c | 1 + libavcodec/libxavs2.c | 303 + libavcodec/version.h | 4 +- 8 files changed, 367 insertions(+), 2 deletions(-) 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 : - 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 0d6ee0a..c8dc1a8 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-libxavs2enable 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] @@ -1666,6 +1667,7 @@ EXTERNAL_LIBRARY_GPL_LIST=" libx264 libx265 libxavs +libxavs2 libxvid " @@ -3131,6 +3133,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" @@ -6165,6 +6168,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 libx265 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..2547acd 100644 --- a/doc/encoders.texi +++ b/doc/encoders.texi @@ -2726,6 +2726,47 @@ Reduces detail but attempts to preserve color at extremely low bitrates. @end table +@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 +@option{--enable-libxavs2}. + +@subsection Options + +@table @option +@item lcu_row_threads +Set the number of parallel threads for rows from 1 to 8 (default 5). + +@item initial_qp +Set the xavs2 quantization parameter from 1 to 63 (default 34). This is +used to set the initial qp for the first frame. + +@item max_qp +Set the max qp for rate control from 1 to 63 (default 55). + +@item min_qp +Set the min qp for rate control from 1 to 63 (default 20). + +@item speed_level +Set the Speed level from 0 to 9 (default 0). Higer is better but slower. + +@item hierarchical_ref +Set the hierarchical reference or not (default true). + +@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}: + +@example +ffmpeg -i input -c:v libxavs2 -xavs2-params speed_level=5 output.avs2 +@end example +@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}. +@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. + +@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. +@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