Class: VideoConverter::Base
Instance Attribute Summary collapse
-
#inputs ⇒ Object
Returns the value of attribute inputs.
-
#outputs ⇒ Object
Returns the value of attribute outputs.
Instance Method Summary collapse
- #clear ⇒ Object
- #concat(method = nil) ⇒ Object
-
#convert ⇒ Object
XXX inject instead of each would be better.
- #encrypt(options = {}) ⇒ Object
-
#initialize(params) ⇒ Base
constructor
A new instance of Base.
- #make_screenshots ⇒ Object
- #mux ⇒ Object
- #run ⇒ Object
- #segment ⇒ Object
- #split ⇒ Object
Constructor Details
#initialize(params) ⇒ Base
Returns a new instance of Base.
7 8 9 10 |
# File 'lib/video_converter/base.rb', line 7 def initialize params self.inputs = Array.wrap(params[:input] || params[:inputs]).map { |input| Input.new(input) } self.outputs = Array.wrap(params[:output] || params[:outputs]).map { |output| Output.new(output.merge(:uid => params[:uid] ? params[:uid].to_s : (Socket.gethostname + object_id.to_s))) } end |
Instance Attribute Details
#inputs ⇒ Object
Returns the value of attribute inputs.
5 6 7 |
# File 'lib/video_converter/base.rb', line 5 def inputs @inputs end |
#outputs ⇒ Object
Returns the value of attribute outputs.
5 6 7 |
# File 'lib/video_converter/base.rb', line 5 def outputs @outputs end |
Instance Method Details
#clear ⇒ Object
55 56 57 58 59 60 |
# File 'lib/video_converter/base.rb', line 55 def clear Command.new("cat #{outputs.first.log} >> #{VideoConverter.log} && rm #{outputs.first.log}").execute outputs.map { |output| output.[:passlogfile] }.uniq.compact.each { |passlogfile| Command.new("rm #{passlogfile}*").execute } outputs.select { |output| output.type == 'segmented' }.each { |output| Command.new("rm #{output.ffmpeg_output}").execute } true end |
#concat(method = nil) ⇒ Object
66 67 68 |
# File 'lib/video_converter/base.rb', line 66 def concat method = nil Ffmpeg.concat(inputs, outputs.first, method) end |
#convert ⇒ Object
XXX inject instead of each would be better
17 18 19 20 21 |
# File 'lib/video_converter/base.rb', line 17 def convert success = true inputs.each { |input| success &&= Ffmpeg.new(input, outputs).run } success end |
#encrypt(options = {}) ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/video_converter/base.rb', line 41 def encrypt( = {}) outputs.each do |output| case output.drm when 'adobe' output..merge!() F4fpackager.run(output) or return false when 'hls' output..merge!() OpenSSL.run(output) or return false end end true end |
#make_screenshots ⇒ Object
23 24 25 26 27 28 29 |
# File 'lib/video_converter/base.rb', line 23 def make_screenshots success = true outputs.each do |output| success &&= VideoScreenshoter.new(output.thumbnails.merge(:ffmpeg => Ffmpeg.bin, :input => output.ffmpeg_output, :output_dir => File.join(output.work_dir, 'thumbnails'))).run if output.thumbnails end success end |
#mux ⇒ Object
70 71 72 |
# File 'lib/video_converter/base.rb', line 70 def mux Ffmpeg.mux(inputs, outputs.first) end |
#run ⇒ Object
12 13 14 |
# File 'lib/video_converter/base.rb', line 12 def run convert && make_screenshots && segment && encrypt && clear end |
#segment ⇒ Object
31 32 33 34 35 36 37 38 39 |
# File 'lib/video_converter/base.rb', line 31 def segment success = true outputs.select { |output| output.type == 'playlist' }.each do |playlist| paths = playlist.streams.map { |stream| stream[:path] } group = outputs.select { |output| paths.include?(output.filename) }.unshift(playlist) success &&= (playlist.filename.end_with?('m3u8') ? LiveSegmenter : Mp4frag).send(:run, group) end success end |