BradLarson / GPUImage

An open source iOS framework for GPU-based image and video processing
http://www.sunsetlakesoftware.com/2012/02/12/introducing-gpuimage-framework
BSD 3-Clause "New" or "Revised" License
20.25k stars 4.61k forks source link

Input saved mov Video and get Output as Filtered mov file #2295

Open aiyub007 opened 8 years ago

aiyub007 commented 8 years ago

I am trying to get filtered .mov file and here As Input I am providing normal .mov File...

Here is my code...

player.pause()

    var paths: [AnyObject] = NSSearchPathForDirectoriesInDomains(.DocumentDirectory, .UserDomainMask, true)
    let  filePath = paths[0].stringByAppendingString("/image.mov")
    let asset: AVURLAsset = AVURLAsset(URL: NSURL(fileURLWithPath: filePath))
    let videoAssetTrack: AVAssetTrack = asset.tracksWithMediaType(AVMediaTypeVideo)[0]

    self.movieFile1 = GPUImageMovie(URL: NSURL(fileURLWithPath: filePath))
    self.movieFile1.runBenchmark = true

    let filteredFile: String = paths[0].stringByAppendingPathComponent("/MovieFiltered.m4v")
    unlink((filteredFile as NSString).UTF8String)
    let movieURL: NSURL = NSURL.fileURLWithPath(filteredFile)
    do {
        try NSFileManager.defaultManager().removeItemAtURL(movieURL)
        print("File removed")
    }catch{
        print("Not Removed \(error as NSError)")

    }
    print(videoAssetTrack.naturalSize.width)
    print(videoAssetTrack.naturalSize.height)

   self.movieWriter = GPUImageMovieWriter(movieURL: movieURL, size: CGSizeMake(videoAssetTrack.naturalSize.width, videoAssetTrack.naturalSize.height))
    self.movieFile1.addTarget(self.pixellateFilter)
    self.pixellateFilter.removeAllTargets()
    self.pixellateFilter.addTarget(self.movieWriter)
    self.movieWriter.shouldPassthroughAudio = true
    self.movieFile1.audioEncodingTarget = self.movieWriter
    self.movieFile1.enableSynchronizedEncodingUsingMovieWriter(self.movieWriter)
    self.movieWriter.startRecording()
    self.movieFile1.startProcessing()
    weak var weakSelf = self
    self.movieWriter.completionBlock = {() -> Void in
        dispatch_async(dispatch_get_main_queue(), {

      print("Recording done")
        weakSelf!.movieWriter.finishRecording()
    })

    }

App crashes at... dispatch_sync(videoProcessingQueue, block); .. InGPUImageOutput.m Please solve this for me.