[FFmpeg-devel] [PATCH v7 1/2] lavc, doc, configure: add libxavs2 video encoder wrapper

Huiwen Ren hwrenx at 126.com
Mon Sep 10 06:55:39 EEST 2018










At 2018-09-10 02:01:32, "Mark Thompson" <sw at jkqxz.net> wrote:
>On 06/09/18 14:58, hwren wrote:
>> Signed-off-by: hwren <hwrenx at 126.com>
>> ---
>>  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
>>  
>> + 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 lcu_row_threads
>> +Set the number of parallel threads for rows from 1 to 8 (default 5).
>> +
>> + at 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.
>> +
>> + at item max_qp
>> +Set the max qp for rate control from 1 to 63 (default 55).
>> +
>> + at item min_qp
>> +Set the min qp for rate control from 1 to 63 (default 20).
>> +
>> + at 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 0000000..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 <ctype.h>
>
>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, &code, 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 *)&pic->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 what the reason for the default of five was?  If you did I might have missed it.  (In particular, I'm wondering what happens if you run it on a processor with fewer than five real threads.)

Should be 0(auto) and fixed, thanks.

>
>> +    { "initial_qp"      ,   "Quantization parameter"  ,                 OFFSET(initial_qp)      , AV_OPT_TYPE_INT, {.i64 = 34 },  1,      63,  VE },
>> +    { "max_qp"          ,   "max qp for rate control" ,                 OFFSET(max_qp)          , AV_OPT_TYPE_INT, {.i64 = 55 },  0,      63,  VE },
>> +    { "min_qp"          ,   "min qp for rate control" ,                 OFFSET(min_qp)          , AV_OPT_TYPE_INT, {.i64 = 20 },  0,      63,  VE },
>> +    { "speed_level"     ,   "Speed level, higher is better but slower", OFFSET(preset_level)    , AV_OPT_TYPE_INT, {.i64 =  0 },  0,       9,  VE },
>> +    { "hierarchical_ref",   "hierarchical reference" ,                  OFFSET(hierarchical_reference)    , AV_OPT_TYPE_BOOL,    {.i64 =  1 }, 0, 1,  VE },
>> +    { "xavs2-params"    ,   "set the xavs2 configuration using a :-separated list of key=value parameters", OFFSET(xavs2_opts), AV_OPT_TYPE_STRING, { 0 }, 0, 0, VE },
>> +    { NULL },
>> +};
>> +
...

Also added log_level and qp, and moved min_qp/max_qp/initial_qp to the case with no bit_rate. Hope this version looks better :)

Cheers,
Huiwen Ren



More information about the ffmpeg-devel mailing list