[FFmpeg-trac] #7941(undetermined:closed): Transparency broken when encoding animated webp
FFmpeg
trac at avcodec.org
Tue Feb 15 22:03:04 EET 2022
#7941: Transparency broken when encoding animated webp
-------------------------------------+-------------------------------------
Reporter: Nirel d | Owner: (none)
Type: defect | Status: closed
Priority: normal | Component:
| undetermined
Version: git-master | Resolution: invalid
Keywords: webp alpha | Blocked By:
Blocking: | Reproduced by developer: 0
Analyzed by developer: 0 |
-------------------------------------+-------------------------------------
Comment (by Mario Zechner):
I've encountered the bug as well. It is indeed an FFmpeg issue (latest
git-master) and can be reproduced by encoding a webm file with transparent
background to an animated webp file file via e.g.
{{{
❯ ./ffmpeg -c:v libvpx-vp9 -i in.webm -c:v libwebp -loop 0 out.webp
ffmpeg version N-105642-g538be75a69 Copyright (c) 2000-2022 the FFmpeg
developers
built with Apple clang version 13.0.0 (clang-1300.0.29.30)
configuration: --pkg-config-flags=--static --disable-ffplay --disable-
ffprobe --disable-doc --disable-htmlpages --disable-manpages --disable-
podpages --disable-txtpages --disable-libxcb --disable-lzma --disable-sdl2
--enable-libvpx --enable-libwebp
libavutil 57. 21.100 / 57. 21.100
libavcodec 59. 21.100 / 59. 21.100
libavformat 59. 17.101 / 59. 17.101
libavdevice 59. 5.100 / 59. 5.100
libavfilter 8. 27.100 / 8. 27.100
libswscale 6. 5.100 / 6. 5.100
libswresample 4. 4.100 / 4. 4.100
[libvpx-vp9 @ 0x7f8e19412980] v1.11.0
Last message repeated 1 times
Input #0, matroska,webm, from 'out.webm':
Metadata:
ENCODER : Lavf59.17.101
Duration: 00:00:00.84, start: 0.000000, bitrate: 2777 kb/s
Stream #0:0: Video: vp9 (Profile 0), yuva420p(tv, progressive), 511x699,
SAR 1:1 DAR 511:699, 25 fps, 25 tbr, 1k tbn
Metadata:
alpha_mode : 1
ENCODER : Lavc59.21.100 libvpx-vp9
DURATION : 00:00:00.840000000
File 'out.webp' already exists. Overwrite? [y/N] y
[libvpx-vp9 @ 0x7f8e197043c0] v1.11.0
Stream mapping:
Stream #0:0 -> #0:0 (vp9 (libvpx-vp9) -> webp (libwebp))
Press [q] to stop, [?] for help
[libvpx-vp9 @ 0x7f8e197043c0] v1.11.0
Output #0, webp, to 'out.webp':
Metadata:
encoder : Lavf59.17.101
Stream #0:0: Video: webp, yuva420p(tv, progressive), 511x699 [SAR 1:1
DAR 511:699], q=2-31, 200 kb/s, 25 fps, 1k tbn
Metadata:
alpha_mode : 1
DURATION : 00:00:00.840000000
encoder : Lavc59.21.100 libwebp
frame= 21 fps=0.0 q=-0.0 Lsize= 775kB time=00:00:00.80
bitrate=7927.0kbits/s speed=0.848x
video:775kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB
muxing overhead: unknown
}}}
You can find the input webm file here: https://marioslab.io/dump/in.webm
The bug is located in line 137 in webpenc.c. This sets the disposal method
of the ANMF chunk to 0, which means the previous canvas contents are
retained. For transparent frames, that is incorrect. The simplest fix is
to set the disposal method to 1, like this:
{{{
git patch --- a/libavformat/webpenc.c
+++ b/libavformat/webpenc.c
@@ -134,7 +134,7 @@ static int flush(AVFormatContext *s, int trailer,
int64_t pts)
avio_wl24(s->pb, pts - w->last_pkt->pts);
} else
avio_wl24(s->pb, w->last_pkt->duration);
- avio_w8(s->pb, 0);
+ avio_w8(s->pb, 0x1);
}
avio_write(s->pb, w->last_pkt->data + skip, w->last_pkt->size -
skip);
av_packet_unref(w->last_pkt);
}}}
This fixes the issue, but may lead to bigger webp files in case of non-
transparent input frames.
--
Ticket URL: <https://trac.ffmpeg.org/ticket/7941#comment:19>
FFmpeg <https://ffmpeg.org>
FFmpeg issue tracker
More information about the FFmpeg-trac
mailing list