Skip to content

Instantly share code, notes, and snippets.

@ulaganathan-PalaniVelayutham
Created March 9, 2023 11:17
Show Gist options
  • Save ulaganathan-PalaniVelayutham/02865e383c56daba0830556c3de41b04 to your computer and use it in GitHub Desktop.
Save ulaganathan-PalaniVelayutham/02865e383c56daba0830556c3de41b04 to your computer and use it in GitHub Desktop.
func addWaterMark(toVideofrom url: URL, onComplete: @escaping (URL?, UIImage?) -> Void) {
let queue = DispatchQueue.global(qos: .background)
queue.async { [self] in
1// let asset = AVURLAsset(url: url)
2//let composition = AVMutableComposition()
3// guard
let compositionVideoTrack = composition.addMutableTrack(
withMediaType: .video, preferredTrackID: kCMPersistentTrackID_Invalid),
let assetVideoTrack = asset.tracks(withMediaType: .video).first
else {
print("Something is wrong with the asset.")
onComplete(nil, nil)
return
}
4// do {
let timeRange = CMTimeRange(start: .zero, duration: asset.duration)
try compositionVideoTrack.insertTimeRange(timeRange, of: assetVideoTrack, at: .zero)
5// if let assetAudioTrack = asset.tracks(withMediaType: .audio).first,
let compositionAudioTrack = composition.addMutableTrack(
withMediaType: .audio,
preferredTrackID: kCMPersistentTrackID_Invalid) {
try compositionAudioTrack.insertTimeRange(
timeRange,
of: assetAudioTrack,
at: .zero)
}
} catch {
print(error)
onComplete(nil, nil)
return
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment