1

I'm making a video capture app with live filters. I was able to create live camera feed and display it in an image view and add filters. Now I want to record it as a video along with filter. At present I'm using this method for recording

 @IBAction func RecordBtnPressed(_ sender: Any)
{
   let videoFileOutput = AVCaptureMovieFileOutput()
    capturesession.addOutput(videoFileOutput)

    
    var path = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first!
    path.appendPathComponent("\(UUID().uuidString).mp4")

        videoFileOutput.startRecording(to: path, recordingDelegate: self)
    
 
    
}

But in above method the problem is when record button is pressed live feed preview in an image view using SampleBufferDelegate hangs still. But I was able to record and save the video in files app. I can't watch the live camera feed along with filter in preview layer. Is there is any alternative way to use setSampleBufferDelegate in AVCaptureMovieFileOutput

Here is my Sample Buffer Delegate method it fetches the images from buffer and apply user selected filter and add it to live feed preview layer. But when I press record button it hangs and video is captured but without filter on it

  func captureOutput(_ output: AVCaptureOutput, didOutput sampleBuffer: CMSampleBuffer, from connection: AVCaptureConnection) {
        
       let imagebuffer =  CMSampleBufferGetImageBuffer(sampleBuffer)
        CameraImage = CIImage(cvPixelBuffer: imagebuffer!)
        
        if Sepia
        {
        let filteredimage = sepiaFilter(image: CameraImage, intensity: 0.9)
        
       
         fixedImage =  UIImage(ciImage: filteredimage,scale: 1.0,orientation: .right).fixOrientation()
        }
        else if Mono
        {
            let filteredimage = monoFilter(image: CameraImage)
            
           
             fixedImage =  UIImage(ciImage: filteredimage,scale: 1.0,orientation: .right).fixOrientation()
        }
        else if ColorInvert
        {
            let filteredimage = colorinvert(image: CameraImage)
            
           
             fixedImage =  UIImage(ciImage: filteredimage,scale: 1.0,orientation: .right).fixOrientation()
        }
        else if PhotoEffectInstant
        {
            let filteredimage = photoeffectinstant(image: CameraImage)
            
           
             fixedImage =  UIImage(ciImage: filteredimage,scale: 1.0,orientation: .right).fixOrientation()
        }
        else if ComicEffect
        {
            let filteredimage = comicEffect(image: CameraImage)
            
           
             fixedImage =  UIImage(ciImage: filteredimage,scale: 1.0,orientation: .right).fixOrientation()
        }
        else if HexPixellate
        {
            let filteredimage = HexaPixellate(image: CameraImage)
            fixedImage = UIImage(ciImage: filteredimage,scale: 1.0,orientation: .right).fixOrientation()
        }
        else if Crystallize
        {
            let filteredimage = Crystsallize(image: CameraImage)
            fixedImage = UIImage(ciImage: filteredimage, scale: 1.0, orientation: .right).fixOrientation()
        }
        else
        {
            fixedImage =  UIImage(ciImage: CameraImage,scale: 1.0,orientation: .right).fixOrientation()
        }
        
        
        
        DispatchQueue.main.async {
        
            self.VideoPreviewImageView.image = self.fixedImage
           
        }
stark
  • 41
  • 3

0 Answers0