SixLabors/ImageSharp

GIF to WebP conversion issue: animation speed

marklagendijk opened this issue · 3 comments

Prerequisites

  • I have written a descriptive issue title
  • I have verified that I am running the latest version of ImageSharp
  • I have verified if the problem exist in both DEBUG and RELEASE mode
  • I have searched open and closed issues to ensure it has not already been reported

ImageSharp version

3.1.1

Other ImageSharp packages and versions

ImageSharp.Web 3.1.0

Environment (Operating system, version and so on)

Windows 11

.NET Framework version

.NET 8

Description

When I saw that animated WebP encoding support landed, I started investigating it ASAP.
Our websites are full of animated GIF images, if we can automatically convert these to WebP using ImageSharp.Web (with acceptable quality) we can potentially save a lot of bandwidth.

On a first glance the quality seems fine, but there one problem. The animation speed of most images is way too high.

Steps to Reproduce

  1. Load the attached GIF image with the command format=webp

Images

Image (both original GIF and resulting WebP, I used a .zip file because GitHub does not allow uploading WebP):
aug_2022.zip

This would be a good one for community contribution. It’s just timespan conversion stuff.

I looked a bit in the codebase to see if would be something that I might be able to do, and I think I stumbled on the bug:

FrameDelay = (uint)metadata.Duration.Milliseconds,

This seems to be a conversion from a Timespan to an uint that should contain the duration in milliseconds. It uses .Milliseconds but should instead use .TotalMilliseconds.

For a Timespan of 5.5 seconds Milliseconds would be 500, but TotalMilliseconds would be 5500.

That'll be it then! My tests all contain sub-second frames so I never picked it up. Thanks for looking! 👍