How to remove existing CIFilter from video in ios?

43 Views Asked by At
func removeFilterFromVideo(videoURL: URL, completion: @escaping ((URL?, String?) -> Void)) {
    let asset = AVAsset(url: videoURL)
    
    // Create a mutable video composition
    guard let videoTrack = asset.tracks(withMediaType: .video).first else {
        completion(nil, "Failed to load video track")
        return
    }

This function is not working i am not getting any errors.
    
    let videoComposition = AVMutableVideoComposition(asset: asset) { request in
        // Provide the original image to the composition
        request.finish(with: request.sourceImage, context: nil)
    }
    
    videoComposition.renderSize = videoTrack.naturalSize
    
    // Export session
    guard let exportSession = AVAssetExportSession(asset: asset, presetName: AVAssetExportPresetHighestQuality) else {
        completion(nil, "Failed to create export session")
        return
    }
    
    // Create output file URL
    let documentDirectory = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask)[0]
    let outputURL = documentDirectory.appendingPathComponent("NoFilterVideo").appendingPathExtension("mp4")
    
    // Remove existing file
    deleteFile(outputURL)
    
    // Configure export session
    exportSession.outputURL = outputURL
    exportSession.outputFileType = .mp4
    exportSession.videoComposition = videoComposition
    
    // Perform export asynchronously
    exportSession.exportAsynchronously {
        switch exportSession.status {
        case .completed:
            completion(outputURL, nil)
        case .failed, .cancelled:
            completion(nil, exportSession.error?.localizedDescription)
        default:
            completion(nil, "Failed to export video")
        }
    }
}

This function is not working, i am not getting any error though. I want to remove all existing CIFilter before adding a new one currently it's adding filter on top. Working on video edit tool.

0

There are 0 best solutions below