如何从ios中的视频中删除现有的CIFilter?

问题描述 投票:0回答:1
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")
        }
    }
}

此功能不起作用,但我没有收到任何错误。我想在添加新的 CIFilter 之前删除所有现有的 CIFilter,目前它正在顶部添加过滤器。正在开发视频编辑工具。

ios swift video cifilter
1个回答
0
投票

不,许多 CI 过滤器确实具有破坏性。他们以丢失信息的方式改变原始图像。锐化就是这样一种转变。它会以无法撤销的方式改变源图像,至少不能完美地改变。您可以应用模糊滤镜来尝试反转锐化,但结果会降低。

(模糊是另一种破坏性滤镜。您可以应用锐化来尝试消除模糊,但会严重损失细节。事实上,大多数“卷积滤镜”都是破坏性的,因为它们混合了相邻像素的值。)

如果您想让滤镜真正可逆,您应该保存原始视频,并将滤镜应用到该原始视频。如果用户决定删除滤镜,请返回原始图像并将所有剩余的滤镜应用于原始图像。

© www.soinside.com 2019 - 2024. All rights reserved.