Created
August 8, 2019 03:03
-
-
Save shanecowherd/c5f3edae0b7d263d5f66c9cfb1da8630 to your computer and use it in GitHub Desktop.
This file lets you record using ffmpeg on a raspberry pi, in swift!
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//https://github.com/futurejones/Swift-Lite/ | |
////Install | |
// curl -s https://packagecloud.io/install/repositories/swift-arm/swift-lite/script.deb.sh | sudo bash | |
// sudo apt-get install swift-lite-rpi | |
////Compile | |
// swift-lite-build raspberry-pi-ffmpeg.swift | |
////Run | |
// ./raspberry-pi-ffmpeg.swapp | |
import Foundation | |
@discardableResult | |
func shell(_ args: String...) -> Process { | |
let task = Process() | |
task.executableURL = URL(string: "/usr/bin/env")! | |
task.arguments = args | |
try? task.run() | |
//task.waitUntilExit() | |
//return task.terminationStatus | |
return task | |
} | |
var ffmpeg: Process? | |
ffmpeg = shell("ffmpeg", | |
"-f", "v4l2", | |
"-i", "/dev/video0", | |
"-s", "1024x576", | |
"-c:v", "h264_omx", | |
"-b:v", "5000k", | |
"-pix_fmt", "yuv420p", | |
"-profile:v", "high", | |
"-c:a", "copy", | |
"-tune", "zerolatency", | |
"-vsync", "1", | |
"-g", "30", | |
"-y", "/home/pi/Desktop/output.mp4") | |
DispatchQueue.main.asyncAfter(deadline: .now() + 10.0) { | |
ffmpeg?.terminate() | |
shell("vlc","/home/pi/Desktop/output.mp4") | |
} | |
RunLoop.main.run() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment