Skip to content

Instantly share code, notes, and snippets.

@srinivasmohan
Created September 4, 2014 19:12
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save srinivasmohan/2fb604bda6d464a89517 to your computer and use it in GitHub Desktop.
Save srinivasmohan/2fb604bda6d464a89517 to your computer and use it in GitHub Desktop.
ffmpeg screenshots
#!/usr/bin/ruby
require "streamio-ffmpeg"
class Video
def initialize(f="", outf="./", at=[20, 50, 80])
@video=FFMPEG::Movie.new(f)
@at=at.map { |x| (@video.duration*x/100).to_i}
$stderr.puts "Video #{f} (#{@video.duration} secs) - Screenshots at #{@at.inspect}"
@outf=outf
end
def run
bname=File.basename(@video.path)
@at.length.times do |i|
cmd="ffmpeg -y -i #{@video.path} -ss #{@at[i]} -vframes 1 -vf fps=fps=1 -f image2 #{@outf}/x#{bname}-#{i}.jpg "
system(cmd ) #+ ' 2>/dev/null')
end
end
end
Screenshots=[20, 50, 80]
outf="./out"
Dir.mkdir(outf) unless File.directory?(outf)
v=Video.new(ARGV[0], outf, Screenshots)
v.run
@srinivasmohan
Copy link
Author

Lazy to edit... But helps to have -ss before -i - This tiny change makes ffmpeg seek directly to the offset and not have to decode video sequence till then... i.e.

cmd="ffmpeg -y -ss #{@at[i]} -i #{@video.path} -vframes 1 -f image2 #{@outf}/#{bname}-#{i}.jpg "

@srinivasmohan
Copy link
Author

^^^ Huge f****** speedup.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment