alexiscreuzot / SwiftyGif

High performance GIF engine
MIT License
1.99k stars 210 forks source link

Fix playback speed on non-60hz displays #180

Closed donmai-me closed 1 year ago

donmai-me commented 1 year ago

Fixes #170 and brings back tvOS support. This is a band aid solution to the problem as the playback speed gets slow when my iPad pro is on low power mode.

alexiscreuzot commented 1 year ago

Interesting, I'm thinking there's probably a way to detect this state change. Anyway good work, I'm merging your PR

donmai-me commented 1 year ago

Best I can think of is using the display link's targetTimestamp and timestamp to get the current display framerate. Like

let actualFramesPerSecond = 1 / (displaylink.targetTimestamp - displaylink.timestamp)

For macOS:

// WARNING: This is divide-by-zero if the display is not available
let actualFramesPerSecond = 1 / CVDisplayLinkGetActualOutputVideoRefreshPeriod(displaylink)

SwiftyGifManager already uses the appropriate display link on macOS and iOS for its timer. Maybe it can also be used to get the current framerate.

rjvir commented 1 year ago

It seems like this change regressed GIF playback on my app.

For some reason, all GIFs play super slow on 120hz iPhones (e.g. 14 pro max).

I had to downgrade to 5.4.3 to fix it.

igor2890 commented 1 year ago

It seems like this change regressed GIF playback on my app.

For some reason, all GIFs play super slow on 120hz iPhones (e.g. 14 pro max).

I had to downgrade to 5.4.3 to fix it.

I confirm, faced the same problem

alexiscreuzot commented 1 year ago

Reverted this commit, but seem to cause other issues

donmai-me commented 1 year ago

Hi! Like I said above this is a bandaid fix. The correct solution would be something like I proposed above; to use the appropriate display link to get the current framerate rather than hardcoding framerates.