Skip to content

Instantly share code, notes, and snippets.

@kmdarshan
Created June 19, 2024 17:08
Show Gist options
  • Save kmdarshan/6d4f552f4e0266700414a37d232b0e7b to your computer and use it in GitHub Desktop.
Save kmdarshan/6d4f552f4e0266700414a37d232b0e7b to your computer and use it in GitHub Desktop.
func exportVideoWithWatermark(inputURL: URL, outputURL: URL, watermark: UIImage) {
guard let composition = addWatermark(to: inputURL, watermark: watermark) else {
print("Failed to add watermark")
return
}
guard let exportSession = AVAssetExportSession(asset: composition, presetName: AVAssetExportPresetHighestQuality) else {
print("Failed to create export session")
return
}
exportSession.outputURL = outputURL
exportSession.outputFileType = .mp4
exportSession.shouldOptimizeForNetworkUse = true
exportSession.exportAsynchronously {
switch exportSession.status {
case .completed:
print("Export completed")
case .failed:
print("Failed to export video: \(String(describing: exportSession.error))")
case .cancelled:
print("Export cancelled")
default:
break
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment