Class: RTranscoder::FFmpeg

Inherits:
RProgram::Program
  • Object
show all
Defined in:
lib/rtranscoder/ffmpeg/ffmpeg.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ FFmpeg

Creates a new FFmpeg object with the specified path of the ffmpeg program.



15
16
17
# File 'lib/rtranscoder/ffmpeg/ffmpeg.rb', line 15

def initialize(path)
  super(path)
end

Class Method Details

.encode(options = {}, &block) ⇒ Object

See FFmpeg#encode.



22
23
24
# File 'lib/rtranscoder/ffmpeg/ffmpeg.rb', line 22

def self.encode(options={},&block)
  self.find.encode(options,&block)
end

.thumbnail(options = {}) ⇒ Object

See FFmpeg#thumbnail.



29
30
31
# File 'lib/rtranscoder/ffmpeg/ffmpeg.rb', line 29

def self.thumbnail(options={})
  self.find.thumbnail(options)
end

Instance Method Details

#encode(options = {}, &block) ⇒ Object

Runs the ffmpeg program with the given options and the given block using FFmpegTask.



37
38
39
# File 'lib/rtranscoder/ffmpeg/ffmpeg.rb', line 37

def encode(options={},&block)
  run_task(FFmpegTask.new(options,&block))
end

#thumbnail(options = {}) ⇒ Object

Extracts a thumbnail using the given options.

options may contain the following keys:

:video

The input video file.

:start

The start timestamp of the thumbnail.

:length

The duration time of the thumbnail.

:frames

Number of video frames to record.

:fps

The FPS to use, defaults to 1.

:width

The width of the thumbnail.

:height

The height of the thumbnail.

:image

The output thumbnail image.



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/rtranscoder/ffmpeg/ffmpeg.rb', line 54

def thumbnail(options={})
  image = File.expand_path(options[:image])

  encode do |ffmpeg|
    ffmpeg.input = options[:video]
    ffmpeg.record_start_time = options[:start]
    ffmpeg.record_for = options[:length]
    ffmpeg.video_frames = options[:frames]
    ffmpeg.fps = (options[:fps] || 1)
    ffmpeg.video_frame_size = "#{options[:width]}x#{options[:height]}"
    ffmpeg.disable_audio = true
    ffmpeg.overwrite_output_files = true
    ffmpeg.output = image
  end

  image_search = image.split('%d').map { |part|
    Regexp.escape(part)
  }.join('*')

  return Dir[image_search]
end