1

I am developing a video editing kind of application in Swift3 language Where I am merging multiple videos.. setting custom background sound, WaterMark and Fade In & Fade Out effect to the final merged video using AVFoundation framework.

Now my problem is I need to add filter effects like Warm, cold, sepia/vintage to the video... Is this possible to add such effects in Swift iOS using inbuilt libraries? I have searched in Google but not able to find proper solution:

RGB range for cold and warm colors?

http://flexmonkey.blogspot.in/2016/04/loading-filtering-saving-videos-in-swift.html

How to create and add video filter like Instagram using AVFoundation framework - Swift programming

https://developer.apple.com/library/content/samplecode/RosyWriter/Introduction/Intro.html#//apple_ref/doc/uid/DTS40011110

Please advise me. Thank you!

Edited:

I tried using below code but it doesn't work.

let filter = CIFilter(name: "CISepiaTone")!
        let composition = AVVideoComposition(asset: firstAsset, applyingCIFiltersWithHandler: { request in


            let source = request.sourceImage.clampingToExtent()
            filter.setValue(source, forKey: kCIInputImageKey)

            // Vary filter parameters based on video timing
            let seconds = CMTimeGetSeconds(request.compositionTime)
            filter.setValue(seconds * 10.0, forKey: kCIInputRadiusKey)


            let output = filter.outputImage!.cropping(to: request.sourceImage.extent)

            // Provide the filter output to the composition
            request.finish(with: output, context: nil)
        })
Anand Gautam
  • 2,541
  • 3
  • 34
  • 70
  • 1
    What from your second link (FlexMonkey) has you saying it isn't *"...the proper solution"*? You're lacking *details* as in "what have you tried"? –  Mar 12 '18 at 14:34
  • Thanks for the code. Two things. (1) You need to explain *what* isn't working - the expected result in a bit more detail, etc. But more importantly is (2) *CISepiaTone* doesn't have something called "inputRadius"! It's not in the documentation nor in the filter's attributes (I actually checked). https://developer.apple.com/library/content/documentation/GraphicsImaging/Reference/CoreImageFilterReference/index.html#//apple_ref/doc/filter/ci/CISepiaTone –  Mar 12 '18 at 14:48
  • Sorry for late response @dfd, I tried using my second link (FlexMonkey) so I got to know that they are getting image frames from video file and then they are applying image filter and in UIImageView itself they are displaying all image frames, which looks like a playing Video. But as the final output source video's audio is missing. Is there any other way to achieve this with the source video sound? – Anand Gautam Mar 13 '18 at 12:56
  • Sorry, I can't help you with that. I work with *still* images, not video - and on that I'm surprised that a `UIImageView` yields good performance (I always use a `GLKView` and only convert my `CIImage` to a `UIImage` when saving/sharing). But yeah, since I use still images with no audio, I'm of little help. :-( –  Mar 13 '18 at 13:16
  • please look into this: https://stackoverflow.com/questions/51017511/how-to-add-watermark-on-final-video-after-merging-video-and-audio-asset-into-one – user2786 Jun 25 '18 at 06:53
  • Hi @dfd, Are you around? I have a doubt here with VideoComposition, can possible for you to suggest? – Anand Gautam Feb 18 '19 at 13:43
  • HI @AnandGautam, Have you found the answer? I need help, as I'm not able to create New Question... – Ahtazaz Apr 15 '19 at 12:06
  • @Mr.AhtazazYes, use AVPlayerItem and add filter like playerItem.videoComposition = yourComposition (playerItem is an instance of AVPlayerItem) – Anand Gautam Apr 16 '19 at 10:31
  • @AnandGautam found any solution? – Dixit Akabari Jun 02 '21 at 07:50

0 Answers0