Skip to content
New issue

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

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Failed to generate frame: Cannot Decode #202

Closed
Oleg-Chashko opened this issue Sep 10, 2020 · 17 comments · Fixed by #221
Closed

Failed to generate frame: Cannot Decode #202

Oleg-Chashko opened this issue Sep 10, 2020 · 17 comments · Fixed by #221
Labels
bug Something isn't working help wanted Extra attention is needed

Comments

@Oleg-Chashko
Copy link

macOS v.11.0 Beta (20A5364e)
Gifski v.2.9.0 (39)

Screenshot:
Bildschirmfoto 2020-09-10 um 16 26 45

Video recording:
Bildschirmaufnahme 2020-09-10 um 16.18.34.zip

@sindresorhus
Copy link
Owner

Thanks for reporting. Are you able to reproduce it again if you convert with the exact same file and settings? What settings did you convert with (can you take a screenshot)? I was not able to reproduce this myself.

@kornelski
Copy link
Collaborator

kornelski commented Sep 13, 2020

I've got the same error on a screen recording from Big Sur. I fails on a specific frame, every time. I can trim the problematic frame out of the animation, and it won't fail then.

(I didn't report, since I was going to investigate myself, but needed to update Xcode, and that took so long that I forgot about the original issue :D)

@Oleg-Chashko
Copy link
Author

Oleg-Chashko commented Sep 13, 2020

@sindresorhus
This is a problem only on Big Sur.
Sometimes it freezes, i have to kill the process forcibly. But this rarely happens.
Test 1.zip
Test 2.zip

@kornelski
Copy link
Collaborator

kornelski commented Sep 24, 2020

This is the error: (AVFoundationErrorDomain Code=-11821)

https://stackoverflow.com/questions/26209099/error-domain-avfoundationerrordomain-code-11821-cannot-decode

Perhaps it's trying to say there's no frame at the given timestamp? In that case I suppose it'd be safe to skip the frame.

@sindresorhus
Copy link
Owner

Perhaps it's trying to say there's no frame at the given timestamp? In that case I suppose it'd be safe to skip the frame.

No, that's a different error, and we're already handling that:

error.code == .noImageAtTime

@sindresorhus
Copy link
Owner

sindresorhus commented Sep 24, 2020

The error code is the error AVErrorDecodeFailed.

Not very helpful. Should we just ignore that? Seems wrong to do so.


Handy tool: https://www.osstatus.com/search/results?platform=all&framework=all&search=-11821

@kornelski
Copy link
Collaborator

Apple's documentation is useless: https://developer.apple.com/documentation/avfoundation/averror/averrordecodefailed

but the StackOverflow answer mentions they've solved it by correcting their timestamps, so I suspect this may be another case of AV getting confused by a mismatched timestamp.

@sindresorhus
Copy link
Owner

Some observations. I'll look more into this when the final macOS 11 release is out.

It seems to only fail at the following timestamps (Test 1):

Decode failed at time: 0.13666666666666666
Decode failed at time: 0.17166666666666666
Decode failed at time: 0.20666666666666667
Decode failed at time: 0.24
Decode failed at time: 0.275
Decode failed at time: 0.3433333333333333
Decode failed at time: 0.37833333333333335
Decode failed at time: 0.41333333333333333

The error does not happen if I remove

Gifski/Gifski/Gifski.swift

Lines 174 to 175 in 2760425

generator.requestedTimeToleranceBefore = .zero
generator.requestedTimeToleranceAfter = .zero

It also doesn't happen with:

generator.requestedTimeToleranceBefore = CMTime(seconds: 0.3, preferredTimescale: .video)
generator.requestedTimeToleranceAfter = CMTime(seconds: 0.3, preferredTimescale: .video)

However, it does fail with 0.2 seconds. Also, we cannot have this much of a tolerance as then it wouldn't be very accurate.

If there's no other solution, we could consider ignoring any decode errors for the first 0.5 seconds. I would really like to find a better solution though.

@sindresorhus
Copy link
Owner

so I suspect this may be another case of AV getting confused by a mismatched timestamp.

What do you mean by mismatched timestamps? AVAssetImageGenerator is supposed to be able to handle any timestamp that is within the range of the video, even if it doesn't match up with the actual frames.

@kornelski
Copy link
Collaborator

Oh, I forgot the framework promises to support any timestamp. I thought it could fail if you asked for a timestamp that doesn't correspond to a frame (but maybe that still happens despite the API promise).

@sindresorhus sindresorhus added the bug Something isn't working label Oct 8, 2020
@sindresorhus sindresorhus added the help wanted Extra attention is needed label Nov 25, 2020
@aheze
Copy link

aheze commented Dec 11, 2020

Similar problem here.

Screen Shot 2020-12-11 at 9 28 52 AM

Here is the mov file:

always.mov.zip

I am on Big Sur 11.0.1 on Apple silicon.

@sindresorhus
Copy link
Owner

sindresorhus commented Dec 20, 2020

@aheze Can you try upgrading to macOS 11.1 and then try rerecording and converting? I read in the release not that it fixes an issue with screen recordings.

@aheze
Copy link

aheze commented Dec 25, 2020

@sindresorhus just updated and tried the same video file, but got the same crash

@sindresorhus
Copy link
Owner

@aheze

then try rerecording

Because this is most likely a bug in the screen recorder that creates invalid videos.

@aheze
Copy link

aheze commented Dec 25, 2020

Ah. That's probably the problem, I was using xcrun to screen record the simulator...
Edit: xcrun might be broken. I tried rerecording and it only recorded a 0 second video of the home screen.

@sindresorhus
Copy link
Owner

This is the release note item I was talking about:

simctl video recordings no longer cut off the end of the video when no screen updates are happening. The recording timeline now holds the last frame and extends until you terminate the recording with Control-C (SIGINT). (67952344) (FB8565355) - https://developer.apple.com/documentation/Xcode-Release-Notes/xcode-12_3-release-notes

@aheze
Copy link

aheze commented Dec 25, 2020

@sindresorhus Hmm. My Xcode is still on 12.2, I'll try updating.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
bug Something isn't working help wanted Extra attention is needed
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants