Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

BUG: HEIC encoder does not respect frame duration timing when encoding HEIC sequences; defaults to 0.1sec #3120

Closed
TysonParks opened this issue Nov 2, 2020 · 13 comments
Labels
apple bug apple's bug cause our framework author's pain heif ImageIO Anything related to Apple ImageIO codec stale

Comments

@TysonParks
Copy link

New Issue Checklist

Issue Info

Info Value
Platform Name ios
Platform Version 13+
SDWebImage Version 5.9.4
Integration Method Swift Package
Xcode Version Xcode 12.1
Repro rate all the time (100%)
Repro with our demo prj not sure
Demo project link https://github.com/TysonParks/SDWebImageTestingApp

Issue Description and Steps

The HEIC encoder appears to only encode HEIC sequences at 10fps (or with a 0.1sec frame duration).

I mainly just write Swift so it's a little challenging to fully understand all the Obj-C code in this framework but...
maybe this has to do with a (0.1sec) frameDuration limiter like at the bottom of the SDImageIOAnimatedCoder frameDurationAtIndex() method implementation? Perhaps the heic encoder is somehow always receiving a frameDuration value below the frameDuration's (0.011sec) threshold and bumping everything up to 0.1sec?

I wrote a simple testing app that shows how SDWebImage transcoding from GIFs and APNGs with different frame rates successfully maintains frame rates when converting to GIF or APNG, but always converts to HEIC sequences at 10fps.

Many thanks in advance!

https://github.com/TysonParks/SDWebImageTestingApp

@dreampiggy
Copy link
Contributor

dreampiggy commented Nov 3, 2020

The SDWebImageHEICCoder use Apple's built-in Image/IO framework. And for APNG/GIF they share the similar codebase...Maybe this is some bug because of Image/IO, I'll have a check.

@dreampiggy
Copy link
Contributor

dreampiggy commented Nov 3, 2020

Found the reason: not SDWebImage's issue, but Apple's limit in SDK.

For GIF/APHG, if we provide kCGImagePropertyGIFDelayTime: 10ms, it will actually encode current frame as 10ms.
For HEICS, if we provide kCGImagePropertyHEICSDelayTime: 10ms, it will actually encode current frame as 100s.

Even I try to use the kCGImagePropertyHEICSUnclampedDelayTime instead of kSDCGImagePropertyHEICSDelayTime, the result is the same :(

See: https://developer.apple.com/documentation/imageio/kcgimagepropertygifunclampeddelaytime

@dreampiggy dreampiggy added apple bug apple's bug cause our framework author's pain heif ImageIO Anything related to Apple ImageIO codec labels Nov 3, 2020
@dreampiggy
Copy link
Contributor

Try to de-compile the ImageIO.framework

@TysonParks
Copy link
Author

Thanks for digging into this so quickly!
Okay, I see it's on Apple's end. :(
Yes, I thought that the SD implementations for HEICCoder seemed to be the exact same as the GIF/APNG coders, corresponding to their matching keys, but I thought I might just be missing something when digging through the framework.

@TysonParks
Copy link
Author

Try to de-compile the ImageIO.framework

Is this possible?

@dreampiggy
Copy link
Contributor

dreampiggy commented Nov 4, 2020

Does not found a good way to workaround this. I've fired radar to Apple :(

FB8881566

image

@dreampiggy
Copy link
Contributor

dreampiggy commented Nov 4, 2020

If anyone want to check about this bug, use this demo:

image

Reproduce Demo: ImageIOHEICSEncodeDecodeBug.zip

@dreampiggy
Copy link
Contributor

dreampiggy commented Nov 4, 2020

@TysonParks For now, I suggest you to use the open-source libheif codec solution for HEICS animated image encoding.

We provide a external coder plugin as well: https://github.com/SDWebImage/SDWebImageHEIFCoder

@TysonParks
Copy link
Author

@dreampiggy Thanks for digging further into this! I will test the SDWebImageHEIFCoder today.

@stale
Copy link

stale bot commented Jul 21, 2021

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. If this is still an issue, please make sure it is up to date and if so, add a comment that this is still an issue to keep it open. Thank you for your contributions.

@stale stale bot added the stale label Jul 21, 2021
@libe
Copy link

libe commented Oct 25, 2021

Does not found a good way to workaround this. I've fired radar to Apple :(

FB8881566

image

Hello,

did you get back any feedback on this issue from Apple? I was able to reproduce it as of today...

Thanks!

@stale stale bot removed stale labels Oct 25, 2021
@dreampiggy
Copy link
Contributor

Does not found a good way to workaround this. I've fired radar to Apple :(
FB8881566
image

Hello,

did you get back any feedback on this issue from Apple? I was able to reproduce it as of today...

Thanks!

None :)

image

Maybe you can use the open-source world SDWebImageHEIFCoder if you really need the frame duration for HEIC animated images.

Bug Demo:
ImageIOHEICSEncodeDecodeBug.zip

@stale
Copy link

stale bot commented Apr 17, 2022

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. If this is still an issue, please make sure it is up to date and if so, add a comment that this is still an issue to keep it open. Thank you for your contributions.

@stale stale bot added the stale label Apr 17, 2022
@stale stale bot closed this as completed Apr 27, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
apple bug apple's bug cause our framework author's pain heif ImageIO Anything related to Apple ImageIO codec stale
Projects
None yet
Development

No branches or pull requests

3 participants