Created
September 4, 2014 19:12
-
-
Save srinivasmohan/2fb604bda6d464a89517 to your computer and use it in GitHub Desktop.
ffmpeg screenshots
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/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 |
^^^ Huge f****** speedup.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.