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
-
#faststart ⇒ Object
TODO use for faststart ffmpeg moveflags.
-
#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
74 75 76 77 78 79 |
# File 'lib/video_converter/base.rb', line 74 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
52 53 54 |
# File 'lib/video_converter/base.rb', line 52 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
60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/video_converter/base.rb', line 60 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 |
#faststart ⇒ Object
TODO use for faststart ffmpeg moveflags
24 25 26 27 28 |
# File 'lib/video_converter/base.rb', line 24 def faststart success = true outputs.each { |output| success &&= Faststart.new(output).run if output.faststart } success end |
#make_screenshots ⇒ Object
30 31 32 33 34 35 36 |
# File 'lib/video_converter/base.rb', line 30 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
56 57 58 |
# File 'lib/video_converter/base.rb', line 56 def mux Ffmpeg.mux(inputs, outputs.first) end |
#run ⇒ Object
12 13 14 |
# File 'lib/video_converter/base.rb', line 12 def run convert && faststart && make_screenshots && segment && encrypt && clear end |
#segment ⇒ Object
38 39 40 41 42 43 44 45 46 |
# File 'lib/video_converter/base.rb', line 38 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 |