Skip to content

Instantly share code, notes, and snippets.

@keithrbennett
Last active October 5, 2020 18:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save keithrbennett/cafc46973012f6f8de1a7da9f95b3866 to your computer and use it in GitHub Desktop.
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.
#!/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