-
-
Save u20024804/371a531043fca49f851af0802a96a3ed to your computer and use it in GitHub Desktop.
douyu ts concat
This file contains 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 characters
require 'titleize' | |
require 'colorize' | |
Encoding.default_internal = Encoding::UTF_8 | |
Encoding.default_external = Encoding::UTF_8 | |
$dir = Rake.original_dir.encode(Encoding::UTF_8) | |
Dir.chdir($dir) | |
puts "Executing in (#{$dir})..." | |
if $dir =~ /\d-\d/ | |
puts 'Name not found' | |
$stdin.gets | |
exit 1 | |
end | |
m = $dir.match %r(/(\d\d)(\d\d)./(\D*)(\d)?(.+)?) | |
name = "2017-#{m[1]}-#{m[2]} #{m[3].titleize}" | |
name += " \##{m[4]}" if m[4] | |
name += m[5] if m[5] | |
puts name | |
task :default => ['_done.mp4', :cut] | |
task :cut => "#{name}.mp4" | |
file '_comb.ts' do |t| | |
sh "copy /b *_0*.ts #{t.name}" | |
end | |
file '_a.aac' => '_comb.ts' do |t| | |
sh "eac3to #{t.source} 1:_v.h264 2:_a.aac" | |
end | |
file '_a2.aac' => '_a.aac' do |t| | |
sh "eac3to #{t.source} #{t.name} +250ms" | |
end | |
file_create '_v.h264' => '_a.aac' | |
file '_done.mp4' => ['_v.h264', '_a2.aac'] do |t| | |
sh "muxer -i _v.h264 -i _a2.aac -o #{t.name}" | |
end | |
file "#{name}.mp4" => '_done.mp4' do |t| | |
duration = `mediainfo -f #{t.source}`.lines.grep(/Duration/).first | |
duration = duration[/: (\d+)/, 1].to_i / 1000 + 2 | |
sh "mp4box -splitx 12:#{duration} #{t.source} -out \"#{t.name}\"" | |
end | |
# sh 'mp4box -splitx 12:3000 a.mp4' | |
# Pre Check | |
numbers = Dir['*_0*.ts'].map { |f| f[/_0(\d+)/, 1].to_i } | |
dangers = numbers[0..-2].zip(numbers[1..-1]).select { |e| e[1] - e[0] > 1 && e[1] - e[0] < 10 } | |
dangers.each do |e| | |
printf "[WARNING] %04d-%04d Diff:%d\n".on_blue.blink, e[0], e[1], e[1]-e[0] | |
end | |
$stdin.gets if dangers.any? |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment