AVAssetReader fails to initialise?

550 Views Asked by At

I am trying to export iCloud assets through AVAssetReader and AVAssetWriter but AVAssetReader fails to initialise using that asset. All other videos are working fine. Only iCloud shared album videos are causing trouble. The error AVAssetReader gives me is under:

Error Domain=AVFoundationErrorDomain Code=-11800 "The operation could not be completed" UserInfo={NSLocalizedFailureReason=An unknown error occurred (-17507), NSLocalizedDescription=The operation could not be completed, NSUnderlyingError=0x2812d8ae0 {Error Domain=NSOSStatusErrorDomain Code=-17507 "(null)"}}

Is there any why to fix it or is there any other alternative ?

1

There are 1 best solutions below

2
Cihan Tek On

When requesting the asset using PHImageManager, setting the deliveryMode property of the PHVideoRequestOptions instance to mediumQualityFormat or fastFormat might be the cause of the problem you're experiencing. Try using auto or high quality, because according to the docs, those are the only modes supported when exporting.

let videoRequestOptions = PHVideoRequestOptions()
videoRequestOptions.deliveryMode = .highQualityFormat
videoRequestOptions.isNetworkAccessAllowed = true

PHImageManager.default().requestAVAsset(forVideo: asset, options: videoRequestOptions) { (asset, audioMix, info) in
            // Use the returned asset 
        }