Class: ActiveJob::Ffmpeg::Encoder::Base
- Inherits:
-
Object
- Object
- ActiveJob::Ffmpeg::Encoder::Base
- Defined in:
- lib/active_job/ffmpeg/encoder/base.rb
Instance Attribute Summary collapse
-
#audio_bitrate ⇒ Object
readonly
Returns the value of attribute audio_bitrate.
-
#audio_sample_rate ⇒ Object
readonly
Returns the value of attribute audio_sample_rate.
-
#input_filename ⇒ Object
readonly
Returns the value of attribute input_filename.
-
#on_complete ⇒ Object
Returns the value of attribute on_complete.
-
#on_progress ⇒ Object
Returns the value of attribute on_progress.
-
#other_options ⇒ Object
readonly
Returns the value of attribute other_options.
-
#output_filename ⇒ Object
readonly
Returns the value of attribute output_filename.
-
#size ⇒ Object
readonly
Returns the value of attribute size.
-
#video_bitrate ⇒ Object
readonly
Returns the value of attribute video_bitrate.
Instance Method Summary collapse
- #acodec ⇒ Object
- #aspect(filename = nil) ⇒ Object
- #do_encode(input, output) ⇒ Object
- #format ⇒ Object
-
#initialize(options = {}) ⇒ Base
constructor
A new instance of Base.
- #preset_options ⇒ Object
- #vcodec ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Base
Returns a new instance of Base.
12 13 14 15 16 17 18 19 20 21 |
# File 'lib/active_job/ffmpeg/encoder/base.rb', line 12 def initialize( = {}) raise ArgumentError unless .is_a?(Hash) = .merge() @size = [:size] @aspect = [:aspect] @video_bitrate = [:video_bitrate] @audio_bitrate = [:audio_bitrate] @audio_sample_rate = [:audio_sample_rate] @other_options = [:other_options] end |
Instance Attribute Details
#audio_bitrate ⇒ Object (readonly)
Returns the value of attribute audio_bitrate.
8 9 10 |
# File 'lib/active_job/ffmpeg/encoder/base.rb', line 8 def audio_bitrate @audio_bitrate end |
#audio_sample_rate ⇒ Object (readonly)
Returns the value of attribute audio_sample_rate.
8 9 10 |
# File 'lib/active_job/ffmpeg/encoder/base.rb', line 8 def audio_sample_rate @audio_sample_rate end |
#input_filename ⇒ Object (readonly)
Returns the value of attribute input_filename.
9 10 11 |
# File 'lib/active_job/ffmpeg/encoder/base.rb', line 9 def input_filename @input_filename end |
#on_complete ⇒ Object
Returns the value of attribute on_complete.
10 11 12 |
# File 'lib/active_job/ffmpeg/encoder/base.rb', line 10 def on_complete @on_complete end |
#on_progress ⇒ Object
Returns the value of attribute on_progress.
10 11 12 |
# File 'lib/active_job/ffmpeg/encoder/base.rb', line 10 def on_progress @on_progress end |
#other_options ⇒ Object (readonly)
Returns the value of attribute other_options.
8 9 10 |
# File 'lib/active_job/ffmpeg/encoder/base.rb', line 8 def @other_options end |
#output_filename ⇒ Object (readonly)
Returns the value of attribute output_filename.
9 10 11 |
# File 'lib/active_job/ffmpeg/encoder/base.rb', line 9 def output_filename @output_filename end |
#size ⇒ Object (readonly)
Returns the value of attribute size.
8 9 10 |
# File 'lib/active_job/ffmpeg/encoder/base.rb', line 8 def size @size end |
#video_bitrate ⇒ Object (readonly)
Returns the value of attribute video_bitrate.
8 9 10 |
# File 'lib/active_job/ffmpeg/encoder/base.rb', line 8 def video_bitrate @video_bitrate end |
Instance Method Details
#acodec ⇒ Object
35 36 37 |
# File 'lib/active_job/ffmpeg/encoder/base.rb', line 35 def acodec raise NotImplementedError end |
#aspect(filename = nil) ⇒ Object
39 40 41 |
# File 'lib/active_job/ffmpeg/encoder/base.rb', line 39 def aspect(filename = nil) @aspect || Ffmpeg.get_aspect(filename) end |
#do_encode(input, output) ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/active_job/ffmpeg/encoder/base.rb', line 53 def do_encode(input, output) @input_filename = input @output_filename = output cmd = %W(#{Ffmpeg.ffmpeg_cmd} -y -i #{@input_filename} -f #{format} -s #{size} -aspect #{aspect(@input_filename)} -vcodec #{vcodec} -b:v #{video_bitrate} -acodec #{acodec} -ar #{audio_sample_rate} -b:a #{audio_bitrate}) cmd.concat(.split(" ")) cmd.reject!(&:empty?) cmd << @output_filename if ENV["DEBUG"] Ffmpeg.logger.debug(cmd.map(&:shellescape).join(" ")) end duration = nil time = nil progress = nil Open3.popen3(*cmd) do |stdin, stdout, stderr, wait_th| while line = stderr.gets("\r") if line =~ /Duration:(\s.?(\d*):(\d*):(\d*)\.(\d*))/ duration = $2.to_i * 3600 + $3.to_i * 60 + $4.to_i end if line =~ /frame=.*time=(\s*(\d*):(\d*):(\d*)\.(\d*))/ time = $2.to_i * 3600 + $3.to_i * 60 + $4.to_i end if duration && time progress = (time / duration.to_f) on_progress.call(progress) if on_progress end end wait_th.join end on_complete.call(self) if on_complete end |
#format ⇒ Object
27 28 29 |
# File 'lib/active_job/ffmpeg/encoder/base.rb', line 27 def format raise NotImplementedError end |
#preset_options ⇒ Object
23 24 25 |
# File 'lib/active_job/ffmpeg/encoder/base.rb', line 23 def {} end |
#vcodec ⇒ Object
31 32 33 |
# File 'lib/active_job/ffmpeg/encoder/base.rb', line 31 def vcodec raise NotImplementedError end |