class VideoConverter::Base
Attributes
inputs[RW]
outputs[RW]
Public Class Methods
new(params)
click to toggle source
# 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
Public Instance Methods
clear()
click to toggle source
# 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.options[: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)
click to toggle source
# File lib/video_converter/base.rb, line 66 def concat method = nil Ffmpeg.concat(inputs, outputs.first, method) end
convert()
click to toggle source
XXX inject instead of each would be better
# 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 = {})
click to toggle source
# File lib/video_converter/base.rb, line 41 def encrypt(options = {}) outputs.each do |output| case output.drm when 'adobe' output.options.merge!(options) F4fpackager.run(output) or return false when 'hls' output.options.merge!(options) OpenSSL.run(output) or return false end end true end
make_screenshots()
click to toggle source
# 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()
click to toggle source
# File lib/video_converter/base.rb, line 70 def mux Ffmpeg.mux(inputs, outputs.first) end
run()
click to toggle source
# File lib/video_converter/base.rb, line 12 def run convert && make_screenshots && segment && encrypt && clear end
segment()
click to toggle source
# 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
split()
click to toggle source
# File lib/video_converter/base.rb, line 62 def split Ffmpeg.split(inputs.first, outputs.first) end