Is there a way to export a video with resolution 480 x 960 ? I know there are libraries for this but I'd rather do it without installing more pods on my project if possible.
I am converting a captured video in .MOV to .MP4. I used the method suggested on this thread.
The available options from AVAssetExport are these:
AVAssetExportPresetLowQuality
AVAssetExportPresetMediumQuality
AVAssetExportPresetHighestQuality
AVAssetExportPresetHEVCHighestQuality
AVAssetExportPreset640x480
AVAssetExportPreset960x540
AVAssetExportPreset1280x720
AVAssetExportPreset1920x1080
AVAssetExportPreset3840x2160
Is this the correct approach if the exported video is MP4? The documentation for AVAssetExportSession says this is for quicktime movies so I am a bit confused about this.
func exportVideo(inputurl: URL,
presetName: String = AVAssetExportPresetHighestQuality,
outputFileType: AVFileType = .mp4,
fileExtension: String = "mp4",
then completion: @escaping (URL?) -> Void)
{
let asset = AVAsset(url: inputurl)
let filename = filePath.deletingPathExtension().appendingPathExtension(fileExtension).lastPathComponent
outputURL = FileManager.default.temporaryDirectory.appendingPathComponent(filename)
if let session = AVAssetExportSession(asset: asset, presetName: presetName) {
session.outputURL = outputURL
session.outputFileType = outputFileType
session.shouldOptimizeForNetworkUse = true
session.exportAsynchronously {
switch session.status {
case .completed:
completion(self.outputURL)
case .cancelled:
debugPrint("Video export cancelled.")
completion(nil)
case .failed:
let errorMessage = session.error?.localizedDescription ?? "n/a"
debugPrint("Video export failed with error: \(errorMessage)")
completion(nil)
default:
break
}
}
} else {
completion(nil)
}
}