Class: Tootsie::Processors::VideoProcessor
- Inherits:
-
Object
- Object
- Tootsie::Processors::VideoProcessor
- Defined in:
- lib/tootsie/processors/video_processor.rb
Instance Attribute Summary collapse
-
#input_url ⇒ Object
Returns the value of attribute input_url.
-
#thumbnail_options ⇒ Object
Returns the value of attribute thumbnail_options.
-
#versions ⇒ Object
Returns the value of attribute versions.
Instance Method Summary collapse
- #execute!(&block) ⇒ Object
-
#initialize(params = {}) ⇒ VideoProcessor
constructor
A new instance of VideoProcessor.
- #params ⇒ Object
- #valid? ⇒ Boolean
Constructor Details
#initialize(params = {}) ⇒ VideoProcessor
Returns a new instance of VideoProcessor.
8 9 10 11 12 13 14 |
# File 'lib/tootsie/processors/video_processor.rb', line 8 def initialize(params = {}) @input_url = params[:input_url] @thumbnail_options = (params[:thumbnail] || {}).with_indifferent_access @versions = [params[:versions] || {}].flatten @thread_count = Application.get.configuration.ffmpeg_thread_count @logger = Application.get.logger end |
Instance Attribute Details
#input_url ⇒ Object
Returns the value of attribute input_url.
92 93 94 |
# File 'lib/tootsie/processors/video_processor.rb', line 92 def input_url @input_url end |
#thumbnail_options ⇒ Object
Returns the value of attribute thumbnail_options.
94 95 96 |
# File 'lib/tootsie/processors/video_processor.rb', line 94 def @thumbnail_options end |
#versions ⇒ Object
Returns the value of attribute versions.
93 94 95 |
# File 'lib/tootsie/processors/video_processor.rb', line 93 def versions @versions end |
Instance Method Details
#execute!(&block) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 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 90 |
# File 'lib/tootsie/processors/video_processor.rb', line 28 def execute!(&block) result = {:urls => []} input, output, thumbnail_output = Input.new(@input_url), nil, nil begin input.get! begin versions.each_with_index do |, version_index| = .with_indifferent_access if version_index == 0 and @thumbnail_options[:target_url] thumbnail_output = Output.new(@thumbnail_options[:target_url]) else thumbnail_output = nil end begin output = Output.new([:target_url]) begin if [:strip_metadata] # This actually strips in-place, so no need to swap streams CommandRunner.new("id3v2 --delete-all '#{input.file_name}'").run do |line| if line.present? and line !~ /\AStripping id3 tag in.*stripped\./ @logger.warn "ID3 stripping failed, ignoring: #{line}" end end end = .dup .delete(:target_url) if thumbnail_output [:thumbnail] = @thumbnail_options.merge(:filename => thumbnail_output.file_name) else .delete(:thumbnail) end adapter = Tootsie::FfmpegAdapter.new(:thread_count => @thread_count) if block adapter.progress = lambda { |seconds, total_seconds| yield(:progress => (seconds + (total_seconds * version_index)) / (total_seconds * versions.length).to_f) } end adapter.transcode(input.file_name, output.file_name, ) output.content_type = [:content_type] if [:content_type] output.put! result[:urls].push output.result_url ensure output.close end if thumbnail_output thumbnail_output.put! result[:thumbnail_url] = thumbnail_output.result_url end ensure thumbnail_output.close if thumbnail_output end end end ensure input.close end result end |
#params ⇒ Object
20 21 22 23 24 25 26 |
# File 'lib/tootsie/processors/video_processor.rb', line 20 def params return { :input_url => @input_url, :thumbnail => @thumbnail_options, :versions => @versions } end |
#valid? ⇒ Boolean
16 17 18 |
# File 'lib/tootsie/processors/video_processor.rb', line 16 def valid? return @input_url && !@versions.blank? end |