Añade marca de agua al video grabado y guarda

Así que estoy tratando de agregar una marca de agua a un video grabado previamente usando el siguiente código, pero cuando veo el video, no hay marca de agua. ¿Alguien puede ayudar? Intenté seguir la publicación en: iPhone Watermark en el video grabado.

public func addWatermarkToVideo(url: NSURL, completion:(url: NSURL?) -> Void) { let videoAsset = AVURLAsset(URL: url) let mixComposition = AVMutableComposition() let compositionVideoTrack = mixComposition.addMutableTrackWithMediaType(AVMediaTypeVideo, prefernetworkingTrackID: kCMPersistentTrackID_Invalid) let clipVideoTrack: AVAssetTrack = videoAsset.tracksWithMediaType(AVMediaTypeVideo)[0] do { try compositionVideoTrack.insertTimeRange(CMTimeRangeMake(kCMTimeZero, videoAsset.duration), ofTrack: clipVideoTrack, atTime: kCMTimeZero) } catch { print(error) } compositionVideoTrack.prefernetworkingTransform = videoAsset.tracksWithMediaType(AVMediaTypeVideo)[0].prefernetworkingTransform //Add watermark guard let myImage = UIImage(named: "Logo") else { completion(url: nil) return } let aLayer = CALayer() aLayer.contents = myImage.CGImage aLayer.frame = CGRectMake(5, 25, 100, 57) aLayer.opacity = 0.65 let videoSize = videoAsset.tracksWithMediaType(AVMediaTypeVideo)[0].naturalSize let parentLayer = CALayer() let videoLayer = CALayer() parentLayer.frame = CGRectMake(0, 0, videoSize.width, videoSize.height) videoLayer.frame = CGRectMake(0, 0, videoSize.width, videoSize.height) parentLayer.addSublayer(videoLayer) parentLayer.addSublayer(aLayer) let videoComp = AVMutableVideoComposition() videoComp.renderSize = videoSize videoComp.frameDuration = CMTimeMake(1,30) videoComp.animationTool = AVVideoCompositionCoreAnimationTool(postProcessingAsVideoLayer: videoLayer, inLayer: parentLayer) let instruction = AVMutableVideoCompositionInstruction() instruction.timeRange = CMTimeRangeMake(kCMTimeZero, mixComposition.duration) let videoTrack = mixComposition.tracksWithMediaType(AVMediaTypeVideo)[0] let layerInstruction = AVMutableVideoCompositionLayerInstruction(assetTrack: videoTrack) instruction.layerInstructions = [layerInstruction] videoComp.instructions = [instruction] let paths = NSSearchPathForDirectoriesInDomains(NSSearchPathDirectory.DocumentDirectory, NSSearchPathDomainMask.UserDomainMask, true) let documentsDirectory: AnyObject = paths[0] let dataPath = documentsDirectory.stringByAppendingPathComponent("VideoCache") if (!NSFileManager.defaultManager().fileExistsAtPath(dataPath)) { do { try NSFileManager.defaultManager().createDirectoryAtPath(dataPath, withIntermediateDirectories: false, attributes: nil) } catch { print("Couldn't create path") } } let tempURL = NSURL(fileURLWithPath: dataPath) let completeMovieUrl = tempURL.URLByAppendingPathComponent("tether-\(NSDate()).mov") if let exporter = AVAssetExportSession(asset: mixComposition, presetName: AVAssetExportPresetHighestQuality) { exporter.outputURL = completeMovieUrl exporter.outputFileType = AVFileTypeMPEG4 exporter.exportAsynchronouslyWithCompletionHandler({ () -> Void in switch exporter.status { case .Failed: print("failed \(exporter.error)") completion(url: nil) break case .Cancelled: print("cancelled \(exporter.error)") completion(url: nil) break default: print("complete") completion(url: exporter.outputURL) } }) } } 

Olvidó agregar su videoComposition a AVAssetExportSession :

 exporter.outputFileType = AVFileTypeMPEG4 // You had this exporter.videoComposition = videoComp // but had forgotten this exporter.exportAsynchronouslyWithCompletionHandler({ // ...