[FFmpeg-devel] [PATCH v3 2/2] libavformat: add WebP demuxer

Andreas Rheinhardt andreas.rheinhardt at gmail.com
Wed Aug 26 12:16:09 EEST 2020


Josef Zlomek:
> Adds the demuxer of animated WebP files.
> It supports non-animated, animated, truncated, and concatenated files.
> Reading from a pipe (and other non-seekable inputs) is also supported.
> 
> The WebP demuxer splits the input stream into packets containing one frame.
> It also sets the timing information and marks the key frames properly.
> The loop count is ignored by default (same behaviour as animated PNG and GIF),
> it may be enabled by the option '-ignore_loop 0'.
> 
> Signed-off-by: Josef Zlomek <josef at pex.com>
> ---
>  Changelog                                   |   1 +
>  doc/demuxers.texi                           |  28 +
>  libavformat/Makefile                        |   1 +
>  libavformat/allformats.c                    |   1 +
>  libavformat/webpdec.c                       | 732 ++++++++++++++++++++
>  tests/ref/fate/exif-image-webp              |   8 +-
>  tests/ref/fate/webp-rgb-lena-lossless       |   2 +-
>  tests/ref/fate/webp-rgb-lena-lossless-rgb24 |   2 +-
>  tests/ref/fate/webp-rgb-lossless            |   2 +-
>  tests/ref/fate/webp-rgb-lossy-q80           |   2 +-
>  tests/ref/fate/webp-rgba-lossless           |   2 +-
>  tests/ref/fate/webp-rgba-lossy-q80          |   2 +-

Great that you also add so many tests for the new demuxer.

>  12 files changed, 773 insertions(+), 10 deletions(-)
>  create mode 100644 libavformat/webpdec.c
> 
> +    if (headers && headers->data) {
> +        uint8_t *side_data = av_memdup(headers->data, headers->size);
> +        if (!side_data)
> +            return AVERROR(ENOMEM);
> +
> +        ret = av_packet_add_side_data(pkt, AV_PKT_DATA_NEW_EXTRADATA,
> +                                      side_data, headers->size);

It is better to use av_packet_new_side_data() here: It takes care of the
case when the buffer could be allocated, but reallocating the side-data
array fails; and it also adds padding to the allocated buffer. Side data
of type AV_PKT_DATA_NEW_EXTRADATA should have it.

> +        if (ret < 0) {
> +            av_free(side_data);
> +            return ret;
> +        }
> +
> +        s->streams[0]->internal->need_context_update = 1;
> +        s->streams[0]->codecpar->width  = headers->canvas_width;
> +        s->streams[0]->codecpar->height = headers->canvas_height;
> +
> +        // copy the fields needed for the key frame detection
> +        wdc->canvas_width  = headers->canvas_width;
> +        wdc->canvas_height = headers->canvas_height;
> +    }
> +


More information about the ffmpeg-devel mailing list