Last active
October 5, 2020 18:19
-
-
Save keithrbennett/cafc46973012f6f8de1a7da9f95b3866 to your computer and use it in GitHub Desktop.
Script that uses ffmpeg to create multiple JPG images from a video file.
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
#!/usr/bin/env ruby | |
if ARGV.empty? | |
raise 'Syntax is: split-video-to-photos video_file_spec' | |
end | |
def run_command(command) | |
puts command | |
IO.popen(command).each { |line| puts line } | |
end | |
def output_mask(filespec) | |
extension = File.extname(filespec) | |
filespec[0...(-(extension.length))] + '-%3d.jpg' | |
end | |
def build_command | |
filespec = ARGV[0] | |
images_per_second = '-r 4' | |
highest_quality_output = '-qmin 1 -qscale:v 1' | |
command = "ffmpeg -i #{filespec} #{images_per_second} #{highest_quality_output} #{output_mask(filespec)}" | |
end | |
run_command(build_command()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment