Class: WebVideo::Transcoder
- Inherits:
-
Object
- Object
- WebVideo::Transcoder
- Defined in:
- lib/web_video/transcoder.rb
Instance Attribute Summary collapse
-
#adapter ⇒ Object
readonly
Returns the value of attribute adapter.
-
#source ⇒ Object
Returns the value of attribute source.
Instance Method Summary collapse
-
#convert(destination, options = {}, &block) ⇒ Object
Generate new video file.
-
#execute(command, options = {}) ⇒ Object
Execute command.
-
#initialize(filepath, options = {}, adapter = :ffmpeg) ⇒ Transcoder
constructor
Video Convertation.
-
#screenshot(destination, options = {}, &block) ⇒ Object
Create screenshots.
Constructor Details
#initialize(filepath, options = {}, adapter = :ffmpeg) ⇒ Transcoder
Video Convertation
transcoder = WebVideo::Transcoder.new(“demo.avi”) transcoder.source # WebVideo::Adapters::AbstractAdapter instance
Or
video = WebVideo::Adapters::FfmpegAdapter.new(‘demo.avi’) transcoder = WebVideo::Transcoder.new(video) transcoder.source # WebVideo::Adapters::FfmpegAdapter instance (video)
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/web_video/transcoder.rb', line 17 def initialize(filepath, = {}, adapter = :ffmpeg) @adapter = adapter if filepath.is_a?(WebVideo::Adapters::AbstractAdapter) @source = filepath else args = [filepath, ] @source = case @adapter when String, Symbol then load_adapter(@adapter.to_s).new(*args) when Class then @adapter.new(*args) else @adapter end end end |
Instance Attribute Details
#adapter ⇒ Object (readonly)
Returns the value of attribute adapter.
4 5 6 |
# File 'lib/web_video/transcoder.rb', line 4 def adapter @adapter end |
#source ⇒ Object
Returns the value of attribute source.
3 4 5 |
# File 'lib/web_video/transcoder.rb', line 3 def source @source end |
Instance Method Details
#convert(destination, options = {}, &block) ⇒ Object
Generate new video file
transcoder = WebVideo::Transcoder.new(“demo.avi”)
begin
transcoder.convert("demo.flv", :resolution => "480x360") do |command|
command << "-ar 22050"
command << "-ab 128k"
command << "-acodec libmp3lame"
command << "-vcodec flv"
command << "-r 25"
command << "-y"
end
rescue WebVideo::CommandLineError => e
WebVideo.logger.error("Unable to transcode video: #{e.class} - #{e.message}")
end
options:
:resolution - video resolution
81 82 83 84 85 |
# File 'lib/web_video/transcoder.rb', line 81 def convert(destination, = {}, &block) .symbolize_keys! process(destination, @source.convert_command, , &block) end |
#execute(command, options = {}) ⇒ Object
Execute command
89 90 91 |
# File 'lib/web_video/transcoder.rb', line 89 def execute(command, = {}) @source.run(command, ) end |
#screenshot(destination, options = {}, &block) ⇒ Object
Create screenshots
transcoder = WebVideo::Transcoder.new(“demo.avi”) transcoder.screenshot(“demo.jpg”, :resolution => “480x360”)
options:
:count - count images to generate
:format - image decoder
:at - sets that image should be taken from the point x seconds from the beginning
:resolution - image resolution
46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/web_video/transcoder.rb', line 46 def screenshot(destination, = {}, &block) = { :count => 1, :format => "image2", :at => "00:00:01" }.merge(.symbolize_keys) # Calculate middle video position if [:at].is_a?(Symbol) && [:center, :middle].include?([:at]) [:at] = @source.duration_in_seconds / 2 end process(destination, @source.screenshot_command, , &block) end |