[PATCH] WebP native muxer bugfix: frames should have alpha blending off
All the frames that the native muxer gets are fully reconstructed frames, and they should not be alpha-blended with the previous frames. As per the WebP container spec https://developers.google.com/speed/webp/docs/riff_container#animation, ANMF chunk should specify blending method = do not blend (and disposal method = do not dispose). However, the native muxer was wrongly setting blending method = use alpha blending. This bug can be reproduced by converting a source with transparency (e.g. animated GIF with transparency) to an animated WebP, and viewing it with vwebp. --- libavformat/webpenc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libavformat/webpenc.c b/libavformat/webpenc.c index 69270c6..1455cc7 100644 --- a/libavformat/webpenc.c +++ b/libavformat/webpenc.c @@ -137,7 +137,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, 2); // Do not dispose and do not blend. } avio_write(s->pb, w->last_pkt.data + skip, w->last_pkt.size - skip); av_free_packet(&w->last_pkt); -- 2.2.0.rc0.207.ga3a616c
On Wed, May 27, 2015 at 03:10:05PM -0700, Urvang Joshi wrote:
All the frames that the native muxer gets are fully reconstructed frames,
wrong
and they should not be alpha-blended with the previous frames.
As per the WebP container spec https://developers.google.com/speed/webp/docs/riff_container#animation, ANMF chunk should specify blending method = do not blend (and disposal method = do not dispose).
However, the native muxer was wrongly setting blending method = use alpha blending. This bug can be reproduced by converting a source with transparency (e.g. animated GIF with transparency) to an animated WebP, and viewing it with vwebp. --- libavformat/webpenc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
this breaks the encoder completely the testcase is the same as previously but probably any testcase that enables encoding multi frame animations will do try -cr_threshold 10000 -cr_size 16 for example [...] -- Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB I have never wished to cater to the crowd; for what I know they do not approve, and what they approve I do not know. -- Epicurus
On Wed, May 27, 2015 at 5:33 PM Michael Niedermayer <michaelni@gmx.at> wrote:
On Wed, May 27, 2015 at 03:10:05PM -0700, Urvang Joshi wrote:
All the frames that the native muxer gets are fully reconstructed frames,
wrong
and they should not be alpha-blended with the previous frames.
As per the WebP container spec https://developers.google.com/speed/webp/docs/riff_container#animation, ANMF chunk should specify blending method = do not blend (and disposal method = do not dispose).
However, the native muxer was wrongly setting blending method = use alpha blending. This bug can be reproduced by converting a source with transparency (e.g. animated GIF with transparency) to an animated WebP, and viewing it with vwebp. --- libavformat/webpenc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
this breaks the encoder completely the testcase is the same as previously but probably any testcase that enables encoding multi frame animations will do try -cr_threshold 10000 -cr_size 16 for example
Ah, the problem seems to be for sources which don't have alpha, and then alpha is introduced by 'cr_threshold' and 'cr_size' for example. [There are other cases too, but this is one example]. I believe the logic for cr_threshold / cr_size is incorrect then, unfortunately. Here's why: 1. The original frame that the encoder gets (before possibly being modified based on cr_threshold and cr_size) is fully-reconstructed, and should NOT be alpha-blended with the previous frame. [Yes, this is true. You can repro this bug by converting this GIF to WebP before this patch: http://dhelemann.de/images/Flug1.gif] For example, if this frame had a transparent pixel, it should be shown as transparent pixel and should NOT see-through the corresponding pixel from the previous frame. This would be achieved by setting blending method = "do not blend". 2. On the other hand, based on the cr_threshold and cr_size, some pixels which are 'similar' to the corresponding pixels in the previous frame are modified to be transparent. So, this logic expects that the frame is alpha-blended with the previous frame (to see-through pixels from the previous frame). Clearly, the two requirements are contrasting and cannot be met. One solution I can think of: (1) By default, set blending method = "do not blend" (2) Some pixels can be modified to become transparent ONLY IF the original frame doesn't have any transparent pixels. And if some pixels are made transparent, we set blending method = "blend". Thoughts?
[...] -- Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
I have never wished to cater to the crowd; for what I know they do not approve, and what they approve I do not know. -- Epicurus _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
On Thu, May 28, 2015 at 05:52:35PM +0000, Urvang Joshi wrote:
On Wed, May 27, 2015 at 5:33 PM Michael Niedermayer <michaelni@gmx.at> wrote:
On Wed, May 27, 2015 at 03:10:05PM -0700, Urvang Joshi wrote:
All the frames that the native muxer gets are fully reconstructed frames,
wrong
and they should not be alpha-blended with the previous frames.
As per the WebP container spec https://developers.google.com/speed/webp/docs/riff_container#animation, ANMF chunk should specify blending method = do not blend (and disposal method = do not dispose).
However, the native muxer was wrongly setting blending method = use alpha blending. This bug can be reproduced by converting a source with transparency (e.g. animated GIF with transparency) to an animated WebP, and viewing it with vwebp. --- libavformat/webpenc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
this breaks the encoder completely the testcase is the same as previously but probably any testcase that enables encoding multi frame animations will do try -cr_threshold 10000 -cr_size 16 for example
Ah, the problem seems to be for sources which don't have alpha, and then alpha is introduced by 'cr_threshold' and 'cr_size' for example. [There are other cases too, but this is one example].
I believe the logic for cr_threshold / cr_size is incorrect then, unfortunately. Here's why: 1. The original frame that the encoder gets (before possibly being modified based on cr_threshold and cr_size) is fully-reconstructed, and should NOT be alpha-blended with the previous frame. [Yes, this is true. You can repro this bug by converting this GIF to WebP before this patch: http://dhelemann.de/images/Flug1.gif]
For example, if this frame had a transparent pixel, it should be shown as transparent pixel and should NOT see-through the corresponding pixel from the previous frame. This would be achieved by setting blending method = "do not blend".
2. On the other hand, based on the cr_threshold and cr_size, some pixels which are 'similar' to the corresponding pixels in the previous frame are modified to be transparent. So, this logic expects that the frame is alpha-blended with the previous frame (to see-through pixels from the previous frame).
Clearly, the two requirements are contrasting and cannot be met.
One solution I can think of: (1) By default, set blending method = "do not blend" (2) Some pixels can be modified to become transparent ONLY IF the original frame doesn't have any transparent pixels. And if some pixels are made transparent, we set blending method = "blend".
sounds possible unless iam too tired and misunderstand
Thoughts?
webp allows updating the last frame by using alpha, but it does not allow a normal RGBA difference update like a P frame with 0,0 MVs would be IIUC. supporting something similar to P frames would be better than trying to emulate GIF I never tried to reencode a gif to webp and dont plan it in the future either, i think the whole webp design is too much based on gif not considering that it could be used for material that is not from a gif file [...] -- Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB DNS cache poisoning attacks, popular search engine, Google internet authority dont be evil, please
On Thu, May 28, 2015 at 8:30 PM Michael Niedermayer <michaelni@gmx.at> wrote:
On Thu, May 28, 2015 at 05:52:35PM +0000, Urvang Joshi wrote:
On Wed, May 27, 2015 at 5:33 PM Michael Niedermayer <michaelni@gmx.at> wrote:
On Wed, May 27, 2015 at 03:10:05PM -0700, Urvang Joshi wrote:
All the frames that the native muxer gets are fully reconstructed frames,
wrong
and they should not be alpha-blended with the previous frames.
As per the WebP container spec
https://developers.google.com/speed/webp/docs/riff_container#animation,
ANMF chunk should specify blending method = do not blend (and disposal method = do not dispose).
However, the native muxer was wrongly setting blending method = use alpha blending. This bug can be reproduced by converting a source with transparency (e.g. animated GIF with transparency) to an animated WebP, and viewing it with vwebp. --- libavformat/webpenc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
this breaks the encoder completely the testcase is the same as previously but probably any testcase that enables encoding multi frame animations will do try -cr_threshold 10000 -cr_size 16 for example
Ah, the problem seems to be for sources which don't have alpha, and then alpha is introduced by 'cr_threshold' and 'cr_size' for example. [There are other cases too, but this is one example].
I believe the logic for cr_threshold / cr_size is incorrect then, unfortunately. Here's why: 1. The original frame that the encoder gets (before possibly being modified based on cr_threshold and cr_size) is fully-reconstructed, and should NOT be alpha-blended with the previous frame. [Yes, this is true. You can repro this bug by converting this GIF to WebP before this patch: http://dhelemann.de/images/Flug1.gif]
For example, if this frame had a transparent pixel, it should be shown as transparent pixel and should NOT see-through the corresponding pixel from the previous frame. This would be achieved by setting blending method = "do not blend".
2. On the other hand, based on the cr_threshold and cr_size, some pixels which are 'similar' to the corresponding pixels in the previous frame are modified to be transparent. So, this logic expects that the frame is alpha-blended with the previous frame (to see-through pixels from the previous frame).
Clearly, the two requirements are contrasting and cannot be met.
One solution I can think of: (1) By default, set blending method = "do not blend" (2) Some pixels can be modified to become transparent ONLY IF the original frame doesn't have any transparent pixels. And if some pixels are made transparent, we set blending method = "blend".
sounds possible unless iam too tired and misunderstand
Alright, I'm implementing this behavior then. One question: - Whether the original frame had transparent pixels or not is determined in the encoder; but - The 'blending method' flag is written in the muxer. Given this, how do I pass along this info (selected "blend method" for each frame) from encoder to muxer?
Thoughts?
webp allows updating the last frame by using alpha, but it does not allow a normal RGBA difference update like a P frame with 0,0 MVs would be IIUC. supporting something similar to P frames would be better than trying to emulate GIF I never tried to reencode a gif to webp and dont plan it in the future either, i think the whole webp design is too much based on gif not considering that it could be used for material that is not from a gif file
[...] -- Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
DNS cache poisoning attacks, popular search engine, Google internet authority dont be evil, please _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
On Thu, Jun 25, 2015 at 08:07:06PM +0000, Urvang Joshi wrote:
On Thu, May 28, 2015 at 8:30 PM Michael Niedermayer <michaelni@gmx.at> wrote:
On Thu, May 28, 2015 at 05:52:35PM +0000, Urvang Joshi wrote:
On Wed, May 27, 2015 at 5:33 PM Michael Niedermayer <michaelni@gmx.at> wrote:
On Wed, May 27, 2015 at 03:10:05PM -0700, Urvang Joshi wrote:
All the frames that the native muxer gets are fully reconstructed frames,
wrong
and they should not be alpha-blended with the previous frames.
As per the WebP container spec
https://developers.google.com/speed/webp/docs/riff_container#animation,
ANMF chunk should specify blending method = do not blend (and disposal method = do not dispose).
However, the native muxer was wrongly setting blending method = use alpha blending. This bug can be reproduced by converting a source with transparency (e.g. animated GIF with transparency) to an animated WebP, and viewing it with vwebp. --- libavformat/webpenc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
this breaks the encoder completely the testcase is the same as previously but probably any testcase that enables encoding multi frame animations will do try -cr_threshold 10000 -cr_size 16 for example
Ah, the problem seems to be for sources which don't have alpha, and then alpha is introduced by 'cr_threshold' and 'cr_size' for example. [There are other cases too, but this is one example].
I believe the logic for cr_threshold / cr_size is incorrect then, unfortunately. Here's why: 1. The original frame that the encoder gets (before possibly being modified based on cr_threshold and cr_size) is fully-reconstructed, and should NOT be alpha-blended with the previous frame. [Yes, this is true. You can repro this bug by converting this GIF to WebP before this patch: http://dhelemann.de/images/Flug1.gif]
For example, if this frame had a transparent pixel, it should be shown as transparent pixel and should NOT see-through the corresponding pixel from the previous frame. This would be achieved by setting blending method = "do not blend".
2. On the other hand, based on the cr_threshold and cr_size, some pixels which are 'similar' to the corresponding pixels in the previous frame are modified to be transparent. So, this logic expects that the frame is alpha-blended with the previous frame (to see-through pixels from the previous frame).
Clearly, the two requirements are contrasting and cannot be met.
One solution I can think of: (1) By default, set blending method = "do not blend" (2) Some pixels can be modified to become transparent ONLY IF the original frame doesn't have any transparent pixels. And if some pixels are made transparent, we set blending method = "blend".
sounds possible unless iam too tired and misunderstand
Alright, I'm implementing this behavior then.
One question: - Whether the original frame had transparent pixels or not is determined in the encoder; but - The 'blending method' flag is written in the muxer.
Given this, how do I pass along this info (selected "blend method" for each frame) from encoder to muxer?
I would try to seperate demuxer and decoder in such a way that the output from the encoder is self contained and can be fed to the decoder and decode correctly. That is i would make the chunks that are needed for decoding part of data that belongs to the decoder/encoder layer, if that is possible [...] -- Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB The real ebay dictionary, page 1 "Used only once" - "Some unspecified defect prevented a second use" "In good condition" - "Can be repaird by experienced expert" "As is" - "You wouldnt want it even if you were payed for it, if you knew ..."
Hi Michael, How about sending the blend method info using side_data in the AVFrame? Here's the patch using that method. If this looks fine, I can separate it out into avformat/* changes and avcodec/* changes. Thanks, Urvang On Thu, Jun 25, 2015 at 6:08 PM Michael Niedermayer <michaelni@gmx.at> wrote:
On Thu, May 28, 2015 at 8:30 PM Michael Niedermayer <michaelni@gmx.at> wrote:
On Thu, May 28, 2015 at 05:52:35PM +0000, Urvang Joshi wrote:
On Wed, May 27, 2015 at 5:33 PM Michael Niedermayer < michaelni@gmx.at> wrote:
On Wed, May 27, 2015 at 03:10:05PM -0700, Urvang Joshi wrote:
All the frames that the native muxer gets are fully reconstructed frames,
wrong
and they should not be alpha-blended with the previous frames.
As per the WebP container spec
https://developers.google.com/speed/webp/docs/riff_container#animation ,
ANMF chunk should specify blending method = do not blend (and disposal method = do not dispose).
However, the native muxer was wrongly setting blending method = use alpha blending. This bug can be reproduced by converting a source with
(e.g. animated GIF with transparency) to an animated WebP, and viewing it with vwebp. --- libavformat/webpenc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
this breaks the encoder completely the testcase is the same as previously but probably any testcase
enables encoding multi frame animations will do try -cr_threshold 10000 -cr_size 16 for example
Ah, the problem seems to be for sources which don't have alpha, and
alpha is introduced by 'cr_threshold' and 'cr_size' for example. [There are other cases too, but this is one example].
I believe the logic for cr_threshold / cr_size is incorrect then, unfortunately. Here's why: 1. The original frame that the encoder gets (before possibly being modified based on cr_threshold and cr_size) is fully-reconstructed, and should NOT be alpha-blended with the previous frame. [Yes, this is true. You can repro this bug by converting this GIF to WebP before this patch: http://dhelemann.de/images/Flug1.gif]
For example, if this frame had a transparent pixel, it should be shown as transparent pixel and should NOT see-through the corresponding pixel from the previous frame. This would be achieved by setting blending method = "do not blend".
2. On the other hand, based on the cr_threshold and cr_size, some
which are 'similar' to the corresponding pixels in the previous
On Thu, Jun 25, 2015 at 08:07:06PM +0000, Urvang Joshi wrote: transparency that then pixels frame are
modified to be transparent. So, this logic expects that the frame is alpha-blended with the previous frame (to see-through pixels from the previous frame).
Clearly, the two requirements are contrasting and cannot be met.
One solution I can think of: (1) By default, set blending method = "do not blend" (2) Some pixels can be modified to become transparent ONLY IF the original frame doesn't have any transparent pixels. And if some pixels are made transparent, we set blending method = "blend".
sounds possible unless iam too tired and misunderstand
Alright, I'm implementing this behavior then.
One question: - Whether the original frame had transparent pixels or not is determined in the encoder; but - The 'blending method' flag is written in the muxer.
Given this, how do I pass along this info (selected "blend method" for each frame) from encoder to muxer?
I would try to seperate demuxer and decoder in such a way that the output from the encoder is self contained and can be fed to the decoder and decode correctly. That is i would make the chunks that are needed for decoding part of data that belongs to the decoder/encoder layer, if that is possible
[...] -- Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
The real ebay dictionary, page 1 "Used only once" - "Some unspecified defect prevented a second use" "In good condition" - "Can be repaird by experienced expert" "As is" - "You wouldnt want it even if you were payed for it, if you knew ..." _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
On Tue, Jul 14, 2015 at 12:20:43AM +0000, Urvang Joshi wrote:
Hi Michael, How about sending the blend method info using side_data in the AVFrame?
the encoders input are AVFrames, the encoder does not output AVFrames so you cannot send anything with an AVFrame from the encoder to the muxer. The data struct between encoder and muxer is a AVPacket the ANMF chunk which carries the blend information could be put like any other chunk in AVPacket.data together with the rest of the frame. I think thats cleaner than putting strings in side data but such side data would also work
Here's the patch using that method. If this looks fine, I can separate it out into avformat/* changes and avcodec/* changes.
[...]
Two cases here:
(1) With the default encoder options, all the frames that the native muxer gets are fully reconstructed frames, and they should NOT be alpha-blended with the previous frames.
As per the WebP container spec https://developers.google.com/speed/webp/docs/riff_container#animation, ANMF chunk should specify blending method = do not blend (and disposal method = do not dispose).
However, the native muxer was wrongly setting blending method = use alpha blending for this case. This bug can be reproduced by converting a source with transparency (e.g. animated GIF with transparency) to an animated WebP, and viewing it with vwebp.
(2) In presence of options like 'cr_threshold' and 'cr_size', the frames may be modified to introduce some transparent pixels and they SHOULD be alpha-blended with the previous frames. However, such introduction of transparent pixels should only be allowed when the original frame didn't already contain some transparent pixels.
this seems not to work: ./ffmpeg -i matrixbench_mpeg2.mpg -cr_threshold 10000 -cr_size 16 -t 1 -loop 2 -vcodec libwebp -flags +bitexact ref.webp apply patch ./ffmpeg -i matrixbench_mpeg2.mpg -cr_threshold 10000 -cr_size 16 -t 1 -loop 2 -vcodec libwebp -flags +bitexact new.webp ./ffmpeg -i matrixbench_mpeg2.mpg -t 1 -loop 2 -vcodec libwebp -flags +bitexact new-nocr.webp ls -alF *.webp -rw-r----- 1 michael michael 191978 Jul 14 03:29 new-nocr.webp -rw-r----- 1 michael michael 191978 Jul 14 03:15 new.webp -rw-r----- 1 michael michael 139126 Jul 14 03:12 ref.webp theres no transparency in matrixbench_mpeg2.mpg, yet the cr_* options no longer work [...] -- Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB You can kill me, but you cannot change the truth.
participants (3)
-
Michael Niedermayer -
Michael Niedermayer -
Urvang Joshi