I'm processing videos with the AVAssetReader
/AVAssetWriter
combo. Now I have the problem that processing can't continue in the background for long when the app is suspended.
The obvious solution here would be to cancel the current video export when the app is suspended. However, I much rather just pause the export and resume it as soon as the app is opened again. But I was unable to find a way to just pause the encoding.
Even when using a semaphore to block the processing loop when the app is suspended, AVFoundation will always throw the following error after 30 seconds in the background:
Could not export media: Error Domain=AVFoundationErrorDomain Code=-11847
"Operation Interrupted" UserInfo={NSLocalizedDescription=Operation Interrupted,
NSLocalizedRecoverySuggestion=Stop other operations and try again.}
It seems the writer basically timed out when no new frames arrived.
Is there a way to pause and resume processing in AVFoundation?