Class: FFmpegWeb::Transcoder
- Inherits:
-
Object
- Object
- FFmpegWeb::Transcoder
- Defined in:
- lib/ffmpeg_web.rb
Instance Attribute Summary collapse
-
#input ⇒ Object
Returns the value of attribute input.
-
#output ⇒ Object
Returns the value of attribute output.
-
#video_info ⇒ Object
Returns the value of attribute video_info.
Instance Method Summary collapse
-
#duration ⇒ Object
returns the duration of the video in seconds.
-
#initialize(input, output) ⇒ Transcoder
constructor
A new instance of Transcoder.
-
#transcode(output_size = nil) ⇒ Object
transcodes the file and returns an io pipe object.
Constructor Details
#initialize(input, output) ⇒ Transcoder
Returns a new instance of Transcoder.
7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/ffmpeg_web.rb', line 7 def initialize(input, output) @input = input @output = output raise "Input file does not exist" if !File.exists?(input) raise "Output directory does not exist" if !File.exists?(File.dirname(output)) @video_info = ffmpeg_info raise "File is not a valid movie file" if !is_valid? end |
Instance Attribute Details
#input ⇒ Object
Returns the value of attribute input.
5 6 7 |
# File 'lib/ffmpeg_web.rb', line 5 def input @input end |
#output ⇒ Object
Returns the value of attribute output.
5 6 7 |
# File 'lib/ffmpeg_web.rb', line 5 def output @output end |
#video_info ⇒ Object
Returns the value of attribute video_info.
5 6 7 |
# File 'lib/ffmpeg_web.rb', line 5 def video_info @video_info end |
Instance Method Details
#duration ⇒ Object
returns the duration of the video in seconds
20 21 22 23 |
# File 'lib/ffmpeg_web.rb', line 20 def duration duration = /Duration: (\d{2}):(\d{2}):(\d{2}).(\d{2})/.match(@video_info) duration_in_milliseconds = ($~[1].to_i * 60 * 60) + ($~[2].to_i * 60) + $~[3].to_i + ($~[4].to_i / 1000) end |
#transcode(output_size = nil) ⇒ Object
transcodes the file and returns an io pipe object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/ffmpeg_web.rb', line 26 def transcode(output_size=nil) progress_read, progress_write = IO::pipe pid = Process.fork do progress_read.close if output_size.nil? crf_encode(progress_write) else two_pass_encode(output_size, progress_write) end end progress_write.close progress_read end |