Hi,
I'm trying to manipulate video sample that was already downloaded into my device.
I'm consistently getting an error using the code :
let ast = AVAsset.init(url: asset.urlAsset.url)
print(asset.urlAsset.url.absoluteString )
let presets = AVAssetExportSession.exportPresets(compatibleWith: ast)
print (presets)
AVAssetExportSession.determineCompatibility(ofExportPreset: AVAssetExportPresetHEVC1920x1080, with: ast, outputFileType: AVFileType.init("com.apple.m4v-video"), completionHandler: { (isCompatible) in
if !isCompatible {
print("Format not compatible.")
return
}})
let exporter = AVAssetExportSession(asset: ast, presetName: AVAssetExportPresetPassthrough)
print(exporter?.supportedFileTypes)
let filename = "filename.mp4"
print(AVAssetExportSession.exportPresets(compatibleWith: ast) )
let documentsDirectory = FileManager.default.urls(for: FileManager.SearchPathDirectory.documentDirectory, in: FileManager.SearchPathDomainMask.userDomainMask).last!
let outputURL = documentsDirectory.appendingPathComponent(filename)
print(outputURL)
exporter?.outputURL = outputURL
exporter?.outputFileType = AVFileType.mp4
exporter?.exportAsynchronously(completionHandler: {
print ("completed with error : ")
print(exporter?.status.rawValue)
print(exporter?.error)
switch exporter!.status {
case .failed:
print("Export failed: \(String(describing: exporter?.error?.localizedDescription))")
case .cancelled:
print("Export canceled.")
case .completed:
print("Successful!")
default:
break
}
})
I'm getting the following error :
2018-10-03 12:26:24.773233+0300 HLSCatalog[2028:582451] [WindowServer] display_timer_callback: unexpected state (now:1820f3fbc2b < expected:1820f458a19)
file:///private/var/mobile/Containers/Data/Application/270D782C-EB82-4050-AB5D-AF794E6B3470/Library/com.apple.UserManagedAssets.uuRgiT/Basic%2520Stream_8CDF279C6AFC98FE.movpkg/
["AVAssetExportPreset1920x1080", "AVAssetExportPresetLowQuality", "AVAssetExportPresetHEVCHighestQuality", "AVAssetExportPreset640x480", "AVAssetExportPreset3840x2160", "AVAssetExportPresetHEVC3840x2160", "AVAssetExportPresetHighestQuality", "AVAssetExportPresetMediumQuality", "AVAssetExportPreset1280x720", "AVAssetExportPreset960x540", "AVAssetExportPresetHEVC1920x1080"]
2018-10-03 12:26:25.293725+0300 HLSCatalog[2028:582498] [] [12:26:25.293] remoteXPCAsset_CopyTracksWithMediaType signalled err=-12174 (kFigAssetError_TrackNotFound) (No tracks with that mediaType) at /BuildRoot/Library/Caches/com.apple.xbs/Sources/EmbeddedCoreMedia/EmbeddedCoreMedia-2282.12/Prototypes/FigAsset/ClientServer/FigAsset_RemoteXPC.c:1643
2018-10-03 12:26:25.293811+0300 HLSCatalog[2028:582498] [] [12:26:25.294] remoteXPCAsset_CopyTracksWithMediaType signalled err=-12174 (kFigAssetError_TrackNotFound) (No tracks with that mediaType) at /BuildRoot/Library/Caches/com.apple.xbs/Sources/EmbeddedCoreMedia/EmbeddedCoreMedia-2282.12/Prototypes/FigAsset/ClientServer/FigAsset_RemoteXPC.c:1643
Optional([__C.AVFileType(_rawValue: com.apple.quicktime-movie), __C.AVFileType(_rawValue: com.apple.m4a-audio), __C.AVFileType(_rawValue: public.mpeg-4), __C.AVFileType(_rawValue: com.apple.m4v-video), __C.AVFileType(_rawValue: public.3gpp), __C.AVFileType(_rawValue: org.3gpp.adaptive-multi-rate-audio), __C.AVFileType(_rawValue: com.microsoft.waveform-audio), __C.AVFileType(_rawValue: public.aiff-audio), __C.AVFileType(_rawValue: public.aifc-audio), __C.AVFileType(_rawValue: com.apple.coreaudio-format)])
["AVAssetExportPreset1920x1080", "AVAssetExportPresetLowQuality", "AVAssetExportPresetHEVCHighestQuality", "AVAssetExportPreset640x480", "AVAssetExportPreset3840x2160", "AVAssetExportPresetHEVC3840x2160", "AVAssetExportPresetHighestQuality", "AVAssetExportPresetMediumQuality", "AVAssetExportPreset1280x720", "AVAssetExportPreset960x540", "AVAssetExportPresetHEVC1920x1080"]
Format not compatible.
file:///var/mobile/Containers/Data/Application/270D782C-EB82-4050-AB5D-AF794E6B3470/Documents/filename.mp4
completed with error :
Optional(4)
Optional(Error Domain=AVFoundationErrorDomain Code=-11822 "Cannot Open" UserInfo={NSLocalizedFailureReason=This media format is not supported., NSLocalizedDescription=Cannot Open, NSUnderlyingError=0x2804d1410 {Error Domain=NSOSStatusErrorDomain Code=-16976 "(null)"}})
Export failed: Optional("Cannot Open")
Any help will be appreciated !
Thanks.