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

Michael Niedermayer michael at niedermayer.cc
Mon Sep 3 02:24:44 EEST 2018


On Sun, Sep 02, 2018 at 12:58:38PM +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  | 320 +++++++++++++++++++++++++++++++++++++++++++++++++
>  libavcodec/version.h   |   2 +-
>  8 files changed, 382 insertions(+), 1 deletion(-)
>  create mode 100644 libavcodec/libxavs2.c
[...]
> +static av_cold int xavs2_init(AVCodecContext *avctx)
> +{
> +    XAVS2EContext *cae= avctx->priv_data;
> +    int bit_depth;
> +
> +    char str_bd[16] = {0}, str_iqp[16] = {0}, str_w[16] = {0}, str_h[16] = {0};
> +    char str_preset[16] = {0}, str_hr[16] = {0}, str_bf[16] = {0};
> +    char str_iv[16] = {0}, str_TBR[16] = {0}, str_fr[16] = {0};
> +
> +    bit_depth = avctx->pix_fmt == AV_PIX_FMT_YUV420P ? 8 : 10;
> +
> +    /* get API handler */
> +    cae->api = xavs2_api_get(bit_depth);
> +
> +    cae->param = cae->api->opt_alloc();
> +
> +    if (!cae->param) {
> +        av_log(avctx, AV_LOG_ERROR, "param alloc failed\n");
> +        return AVERROR(EINVAL);
> +    }
> +
> +    cae->api->opt_set2(cae->param,"rec","0");
> +    cae->api->opt_set2(cae->param,"log","0");
> +
> +    av_strlcatf(str_w, sizeof(str_w), "%d", avctx->width);
> +    av_strlcatf(str_h, sizeof(str_h), "%d", avctx->height);
> +    av_strlcatf(str_bd, sizeof(str_bd), "%d", bit_depth);
> +    av_strlcatf(str_iqp, sizeof(str_iqp), "%d", cae->i_initial_qp);
> +
> +    cae->api->opt_set2(cae->param,"width",str_w);
> +    cae->api->opt_set2(cae->param,"height",str_h);
> +    cae->api->opt_set2(cae->param, "initial_qp", str_iqp);
> +    cae->api->opt_set2(cae->param, "bitdepth", str_bd);
> +
> +    /* preset level */
> +    av_strlcatf(str_preset, sizeof(str_preset), "%d", cae->preset_level);
> +
> +    cae->api->opt_set2(cae->param,"preset", str_preset);
> +    /* bframes */
> +    av_log( avctx, AV_LOG_DEBUG,
> +            "HierarchicalReference %d, Number B Frames %d\n",
> +            cae->b_hierarchical_reference, cae->num_b_frames);
> +
> +    av_strlcatf(str_hr, sizeof(str_hr), "%d", cae->b_hierarchical_reference);
> +    //av_strlcatf(str_bf, sizeof(str_bf), "%d", cae->num_b_frames);
> +    av_strlcatf(str_bf, sizeof(str_bf), "%d", avctx->max_b_frames);
> +
> +    cae->api->opt_set2(cae->param, "hierarchical_ref",  str_hr);
> +    cae->api->opt_set2(cae->param, "bframes",  str_bf);
> +
> +    if (cae->xavs2_opts) {
> +        AVDictionary *dict    = NULL;
> +        AVDictionaryEntry *en = NULL;
> +
> +        if (!av_dict_parse_string(&dict, cae->xavs2_opts, "=", ":", 0)) {
> +            while ((en = av_dict_get(dict, "", en, AV_DICT_IGNORE_SUFFIX))) {
> +

> +                int i_value = isdigit(en->value[0]) ? atoi(en->value) : 0;

this lacks validity checks, strtol() or similar may be a better choice
[...]

> +    if ((cae->packet.len) && (cae->packet.state != XAVS2_STATE_FLUSH_END)){
> +        av_new_packet(pkt, cae->packet.len);
> +
> +        if (!pkt) {

this is not checking for av_new_packet failure


> +            av_log(avctx, AV_LOG_ERROR, "packet alloc failed\n");
> +            return AVERROR(EINVAL);
> +        }
> +
[...]
-- 
Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

Let us carefully observe those good qualities wherein our enemies excel us
and endeavor to excel them, by avoiding what is faulty, and imitating what
is excellent in them. -- Plutarch
-------------- 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/20180903/9f86adca/attachment.sig>


More information about the ffmpeg-devel mailing list