Skip to content

Instantly share code, notes, and snippets.

@jon-cotton
Created June 2, 2016 17:43
Show Gist options
  • Save jon-cotton/8fa938326f784c95c2e8f0fd67565857 to your computer and use it in GitHub Desktop.
Save jon-cotton/8fa938326f784c95c2e8f0fd67565857 to your computer and use it in GitHub Desktop.
#!/usr/bin/swift
import Foundation
enum Device: String {
case phone
case tablet
var videoSize: Int {
switch self {
case phone: return 440
case tablet: return 1200
}
}
var overlaySize: Int {
switch self {
case phone: return 400
case tablet: return 600
}
}
}
// MARK:- Run
let env = NSProcessInfo.processInfo().environment as [String : String]
let args = Process.arguments
var devices: [Device] = []
if args.contains("phone") {
devices.append(.phone)
}
if args.contains("tablet") {
devices.append(.tablet)
}
guard devices.count > 0 else {
print("Please supply at least one device - Usage: video-helper.swift [phone, tablet]")
exit(1)
}
// setup/build
for device in devices {
print("\n**** Outputting video for \(device.rawValue) ****\n")
let cmd = "ffmpeg -nostdin -i in.mp4 -filter:v \"crop=\(device.videoSize):in_h:(in_w/2)-\(device.videoSize/2):0\" -c:a copy cropped.mp4 && ffmpeg -i cropped.mp4 -i diffuse.png -filter_complex \"[1:v]scale=\(device.overlaySize):\(device.overlaySize) [ovrl], [0:v][ovrl]overlay=(W-w)/2:(H-h)/4\" -codec:a copy \(device.rawValue).mp4"
print(cmd)
system(cmd)
system("rm -f cropped.mp4")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment