From 09333097ed4fd474916edf723d1ad07f72a9ab4d Mon Sep 17 00:00:00 2001 From: James Zern Date: Fri, 23 Mar 2018 22:48:17 -0700 Subject: [PATCH] gif2webp: force low duration frames to 100ms this is consistent with web browser behavior as well as various transcoding tools (ffmpeg, gif2apng, etc). also: update anim_diff to account for this new behaviour. BUG=webp:379 Change-Id: I70cc72a6b401ef32b73cd182a3f12d993d495bf4 --- examples/anim_util.c | 3 +++ examples/gif2webp.c | 8 ++++++++ 2 files changed, 11 insertions(+) diff --git a/examples/anim_util.c b/examples/anim_util.c index 6cd2c818..800ea763 100644 --- a/examples/anim_util.c +++ b/examples/anim_util.c @@ -593,6 +593,9 @@ static int ReadAnimatedGIF(const char filename[], AnimatedImage* const image, curr_frame = &image->frames[i]; curr_rgba = curr_frame->rgba; curr_frame->duration = GetFrameDurationGIF(gif, i); + // Force frames with a small or no duration to 100ms to be consistent + // with web browsers and other transcoding tools (like gif2webp itself). + if (curr_frame->duration <= 10) curr_frame->duration = 100; if (i == 0) { // Initialize as transparent. curr_frame->is_key_frame = 1; diff --git a/examples/gif2webp.c b/examples/gif2webp.c index 759eb8fb..b61f273e 100644 --- a/examples/gif2webp.c +++ b/examples/gif2webp.c @@ -361,6 +361,14 @@ int main(int argc, const char *argv[]) { GIFDisposeFrame(orig_dispose, &gif_rect, &prev_canvas, &curr_canvas); GIFCopyPixels(&curr_canvas, &prev_canvas); + // Force frames with a small or no duration to 100ms to be consistent + // with web browsers and other transcoding tools. This also avoids + // incorrect durations between frames when padding frames are + // discarded. + if (frame_duration <= 10) { + frame_duration = 100; + } + // Update timestamp (for next frame). frame_timestamp += frame_duration;