Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

- Following the recommendations of mistydemeo, using -ss instead of -…

…tisoffset and use a safe way by default.

- Refactoring thumbnail to screenshot
  • Loading branch information...
commit 484c5aa9bd5cd5395249e1882e81f05c3ea39465 1 parent 3cb7881
@flatzo authored
View
3  README.md
@@ -125,9 +125,10 @@ movie.transcode("movie.mp4", options) # encodes video using libx264-medium.ffpre
### Thumbnails
By default, the thumbnail will have the same resolution as the movie
+If :safe options is set to false, will be almost instantaneous but may produce a grey screenshot
``` ruby
-options = {:position => 222, :height=>100 , :width=> 200}
+options = {:position => 222, :height=>100 , :width=> 200, :safe => true}
movie.thumbnail("/path/to/thumb.jpg",options)
```
View
4 lib/ffmpeg/movie.rb
@@ -88,8 +88,8 @@ 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 = {})
- Thumbnailer.new(self,output_file,options).run
+ def screenshot(output_file, options = {})
+ Screenshot.new(self,output_file,options).run
end
protected
View
8 lib/ffmpeg/thumbnailer.rb → lib/ffmpeg/screenshot.rb
@@ -2,13 +2,13 @@
require 'shellwords'
module FFMPEG
- class Thumbnailer
- def initialize(movie,output_file,options = ThumbnailingOptions.new)
+ class Screenshot
+ def initialize(movie,output_file,options = ScreenshotOptions.new)
- if options.is_a?(ThumbnailingOptions)
+ if options.is_a?(ScreenshotOptions)
@options = options
elsif options.is_a?(Hash)
- @options = ThumbnailingOptions.new(options)
+ @options = ScreenshotOptions.new(options)
end
@movie = movie
View
18 lib/ffmpeg/thumbnailing_options.rb → lib/ffmpeg/screenshot_options.rb
@@ -1,7 +1,8 @@
module FFMPEG
- class ThumbnailingOptions
+ class ScreenshotOptions
attr_reader :preceding, :following
DEFAULT_POSITION = 4
+
##
# Position is in seconds
# output
@@ -9,11 +10,20 @@ def initialize(options = {})
position = options.has_key?(:position) ? options[:position] : DEFAULT_POSITION
width = options.has_key?(:width) ? options[:width] : nil
height = options.has_key?(:height) ? options[:height] : nil
+ safe = options.has_key?(:safe) ? options[:safe] : true
- @preceding = "-itsoffset -#{position}"
- @following = "-vcodec mjpeg -vframes 1 -an -f rawvideo"
+ if safe then
+ @preceding = ""
+ @following = "-ss #{position} "
+ else
+ @preceding = "-ss #{position} "
+ @following = ""
+ end
+
+
+ @following += "-vcodec mjpeg -vframes 1 -an -f rawvideo "
unless height.nil? and width.nil?
- @following += " -s #{width}x#{height}"
+ @following += "-s #{width}x#{height}"
end
end
end
View
4 lib/streamio-ffmpeg.rb
@@ -6,9 +6,9 @@
require 'ffmpeg/version'
require 'ffmpeg/movie'
require 'ffmpeg/transcoder'
-require 'ffmpeg/thumbnailer'
+require 'ffmpeg/screenshot'
require 'ffmpeg/encoding_options'
-require 'ffmpeg/thumbnailing_options'
+require 'ffmpeg/screenshot_options'
module FFMPEG
Please sign in to comment.
Something went wrong with that request. Please try again.