Skip to content

Instantly share code, notes, and snippets.

@crowjdh
Created March 4, 2017 11:52
Show Gist options
  • Select an option

  • Save crowjdh/fc8a048bc42706b79756d383dd6d1700 to your computer and use it in GitHub Desktop.

Select an option

Save crowjdh/fc8a048bc42706b79756d383dd6d1700 to your computer and use it in GitHub Desktop.

Revisions

  1. Chris Jeong created this gist Mar 4, 2017.
    24 changes: 24 additions & 0 deletions ffmpegFilterExample.swift
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,24 @@
    func filterVideo(inputFilePath: String, outputFilePath: String,
    filterPath: String, callback: @escaping (Bool) -> Void) -> (Process, DispatchWorkItem)? {
    guard let launchPath = Bundle.main.path(forResource: "ffmpeg", ofType: "") else {
    return nil
    }
    let process = Process()
    let task = DispatchWorkItem {
    process.launchPath = launchPath
    process.arguments = [
    "-y",
    "-i", inputFilePath,
    "-filter_script:v", filterPath,
    outputFilePath
    ]
    process.standardInput = FileHandle.nullDevice
    process.launch()
    process.terminationHandler = { process in
    callback(process.terminationStatus == 0)
    }
    }
    DispatchQueue.global(qos: .userInitiated).async(execute: task)

    return (process, task)
    }