Permalink
Browse files

Added thumbnail creation

  • Loading branch information...
1 parent 131a0e2 commit 06176558353f8bed31269fb258cd8d16d853df2f @flatzo committed Mar 12, 2012
Showing with 47 additions and 0 deletions.
  1. +4 −0 lib/ffmpeg/movie.rb
  2. +25 −0 lib/ffmpeg/thumbnailer.rb
  3. +15 −0 lib/ffmpeg/thumbnailing_options.rb
  4. +3 −0 lib/streamio-ffmpeg.rb
View
4 lib/ffmpeg/movie.rb
@@ -88,6 +88,10 @@ def transcode(output_file, options = EncodingOptions.new, transcoder_options = {
Transcoder.new(self, output_file, options, transcoder_options).run &block
end
+ def thumbnail(output_file, options = ThumnbailingOptions.new)
+ Thumbnailer.new(self,output_file,options).run
+ end
+
protected
def aspect_from_dar
return nil unless dar
View
25 lib/ffmpeg/thumbnailer.rb
@@ -0,0 +1,25 @@
+require 'open3'
+require 'shellwords'
+
+module FFMPEG
+ class Thumbnailer
+ def initialize(movie,output_file,options = ThumbnailingOptions.new)
+ @movie = movie
+ @output_file = output_file
+ @options = options
+ end
+
+ def run
+ command = "#{FFMPEG.ffmpeg_binary} #{@options.preceding} -y -i #{Shellwords.escape(@movie.path)} #{@options.following} #{@output_file}"
+ FFMPEG.logger.info("Running thumbnailing...\n#{command}\n")
+ output = ""
+ last_output = nil
+ Open3.popen3(command) do |stdin, stdout, stderr|
+ stderr.each("\n") do |line|
+ puts line
+ end
+ end
+
+ end
+ end
+end
View
15 lib/ffmpeg/thumbnailing_options.rb
@@ -0,0 +1,15 @@
+module FFMPEG
+ class ThumnbailingOptions < Hash
+ attr_reader :preceding, :following
+ ##
+ # Position is in seconds
+ # output
+ def initialize(position=4,height=nil,width=nil)
+ @preceding = "-itsoffset -#{position}"
+ @following = "-vcodec mjpeg -vframes 1 -an -f rawvideo"
+ unless height.nil? and width.nil?
+ @following += "-s #{width}x#{height}"
+ end
+ end
+ end
+end
View
3 lib/streamio-ffmpeg.rb
@@ -6,7 +6,10 @@
require 'ffmpeg/version'
require 'ffmpeg/movie'
require 'ffmpeg/transcoder'
+require 'ffmpeg/thumbnailer'
require 'ffmpeg/encoding_options'
+require 'ffmpeg/thumbnailing_options'
+
module FFMPEG
# FFMPEG logs information about its progress when it's transcoding.

0 comments on commit 0617655

Please sign in to comment.