diff mbox series

[FFmpeg-devel,v3,3/4] avformat/webpenc: better detection of anim chunks

Message ID 20210912202010.1542872-4-yakoyoku@gmail.com
State New
Headers show
Series [FFmpeg-devel,v3,1/4] avcodec/webp: compatibilize with avformat/webpdec
Related show

Checks

Context Check Description
andriy/make_x86 success Make finished
andriy/make_fate_x86 fail Make fate failed
andriy/make_ppc success Make finished
andriy/make_fate_ppc fail Make fate failed

Commit Message

Martin Reboredo Sept. 12, 2021, 8:20 p.m. UTC
Receiving RIFF chunks as `av_packet`s from `webpdec.c` in `webpenc.c` it wasn't doing proper animated frame detection/enumeration.
Check for `ANIM`/`ANMF` chunks to see if the package is an animated WebP packet and for the `ANMF`/`ALPH`/`VP8 `/`VP8L` chunks if it's an actual frame.

Signed-off-by: Martin Reboredo <yakoyoku@gmail.com>
---
 libavformat/webpenc.c | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)
diff mbox series

Patch

diff --git a/libavformat/webpenc.c b/libavformat/webpenc.c
index 9599fe7b85..50bee91910 100644
--- a/libavformat/webpenc.c
+++ b/libavformat/webpenc.c
@@ -55,13 +55,18 @@  static int is_animated_webp_packet(AVPacket *pkt)
 {
     int skip = 0;
     unsigned flags = 0;
+    int fourcc = AV_RL32(pkt->data);
 
     if (pkt->size < 4)
         return AVERROR_INVALIDDATA;
-    if (AV_RL32(pkt->data) == AV_RL32("RIFF"))
+    if (fourcc == AV_RL32("RIFF"))
         skip = 12;
+    else if (fourcc == AV_RL32("ANIM"))
+        return 1;
+    else if (fourcc == AV_RL32("ANMF"))
+        return 1;
     // Safe to do this as a valid WebP bitstream is >=30 bytes.
-    if (pkt->size < skip + 4)
+    if (pkt->size < skip + 4 && pkt->size != 12)
         return AVERROR_INVALIDDATA;
     if (AV_RL32(pkt->data + skip) == AV_RL32("VP8X")) {
         flags |= pkt->data[skip + 4 + 4];
@@ -143,6 +148,7 @@  static int flush(AVFormatContext *s, int trailer, int64_t pts)
 static int webp_write_packet(AVFormatContext *s, AVPacket *pkt)
 {
     WebpContext *w = s->priv_data;
+    int fourcc = AV_RL32(pkt->data);
     int ret;
 
     if (!pkt->size)
@@ -161,7 +167,9 @@  static int webp_write_packet(AVFormatContext *s, AVPacket *pkt)
             return ret;
         av_packet_ref(&w->last_pkt, pkt);
     }
-    ++w->frame_count;
+    if (fourcc == AV_RL32("ANMF") || fourcc == AV_RL32("ALPH") ||
+        fourcc == AV_RL32("VP8 ") || fourcc == AV_RL32("VP8L"))
+        ++w->frame_count;
 
     return 0;
 }