class VideoConverter::LiveSegmenter
Attributes
chunks_pattern[RW]
command[RW]
Public Class Methods
run(outputs)
click to toggle source
# File lib/video_converter/live_segmenter.rb, line 12 def self.run(outputs) success = true threads = [] p = Proc.new do |output| Command.new(command, prepare_params(output)).execute end outputs.select { |output| output.type != 'playlist' }.each do |output| if VideoConverter.paral threads << Thread.new { success &&= p.call(output) } else success &&= p.call(output) end end success &&= gen_group_playlist(outputs.detect { |output| output.type == 'playlist' }) threads.each { |t| t.join } if VideoConverter.paral success end
Private Class Methods
gen_group_playlist(playlist)
click to toggle source
# File lib/video_converter/live_segmenter.rb, line 32 def self.gen_group_playlist playlist res = "#EXTM3U\n#EXT-X-VERSION:3\n#EXT-X-PLAYLIST-TYPE:VOD\n" playlist.streams.sort { |s1, s2| s1[:bandwidth].to_i <=> s2[:bandwidth].to_i }.each do |stream| res += "#EXT-X-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=#{stream[:bandwidth].to_i * 1000}\n" res += stream[:path] + "\n" end res += "#EXT-X-ENDLIST\n" File.open(File.join(playlist.work_dir, playlist.filename), 'w') { |f| f.write res } true end
prepare_params(output)
click to toggle source
# File lib/video_converter/live_segmenter.rb, line 43 def self.prepare_params output { :ffmpeg_bin => Ffmpeg.bin, :ffmpeg_output => output.ffmpeg_output, :segment_time => Output.keyframe_interval_in_seconds, :segment_list => File.join(output.work_dir, output.filename), :segment_list_entry_prefix => File.basename(output.chunks_dir) + '/', :chunks => File.join(output.chunks_dir, chunks_pattern), :log => output.log } end