Created
March 4, 2016 08:36
-
-
Save shunirr/d33fc55ed7cb9f93de1a to your computer and use it in GitHub Desktop.
Revisions
-
shunirr created this gist
Mar 4, 2016 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,28 @@ #!/usr/bin/env ruby require "open3" base_url = ARGV.shift hls_file = ARGV.shift o, e, s = Open3.capture3 "curl #{base_url}#{hls_file}" tslist = o.split("\n").delete_if{|i| i =~ /^#/ } v_cmd = "ffmpeg " a_cmd = "ffmpeg " tslist.each do |ts| Open3.capture2e "curl -O #{base_url}#{ts}" Open3.capture2e "ffmpeg -i #{ts} -vcodec copy -an #{ts}.mp4" Open3.capture2e "ffmpeg -i #{ts} -acodec copy -vn #{ts}.aac" v_cmd += "-i #{ts}.mp4 " a_cmd += "-i #{ts}.aac " end Open3.capture2e "#{v_cmd} -filter_complex 'concat=n=#{tslist.size}:v=1:a=0' video.mp4" Open3.capture2e "#{a_cmd} -filter_complex 'concat=n=#{tslist.size}:v=0:a=1' audio.aac" Open3.capture2e "ffmpeg -i video.mp4 -i audio.aac #{Time.now.to_i}.mp4" Open3.capture2e "rm video.mp4 audio.aac" tslist.each do |ts| Open3.capture2e "rm #{ts} #{ts}.mp4 #{ts}.aac" end