SHARE
TWEET

Untitled

a guest Feb 17th, 2019 78 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. require 'titleize'
  2. require 'colorize'
  3.  
  4. Encoding.default_internal = Encoding::UTF_8
  5. Encoding.default_external = Encoding::UTF_8
  6.  
  7. $dir = Rake.original_dir.encode(Encoding::UTF_8)
  8. Dir.chdir($dir)
  9. puts "Executing in (#{$dir})..."
  10.  
  11. if $dir =~ /\d-\d/
  12.   puts 'Name not found'
  13.   $stdin.gets
  14.   exit 1
  15. end
  16.  
  17. m = $dir.match %r(/(\d\d)(\d\d)./(\D*)(\d)?(.+)?)
  18. name = "2017-#{m[1]}-#{m[2]} #{m[3].titleize}"
  19. name += " \##{m[4]}" if m[4]
  20. name += m[5] if m[5]
  21. puts name
  22.  
  23. task :default => ['_done.mp4', :cut]
  24. task :cut => "#{name}.mp4"
  25.  
  26. file '_comb.ts' do |t|
  27.   sh "copy /b *_0*.ts #{t.name}"
  28. end
  29.  
  30. file '_a.aac' => '_comb.ts' do |t|
  31.   sh "eac3to #{t.source} 1:_v.h264 2:_a.aac"
  32. end
  33. file '_a2.aac' => '_a.aac' do |t|
  34.   sh "eac3to #{t.source} #{t.name} +250ms"
  35. end
  36. file_create '_v.h264' => '_a.aac'
  37. file '_done.mp4' => ['_v.h264', '_a2.aac'] do |t|
  38.   sh "muxer -i _v.h264 -i _a2.aac -o #{t.name}"
  39. end
  40. file "#{name}.mp4" => '_done.mp4' do |t|
  41.   duration = `mediainfo -f #{t.source}`.lines.grep(/Duration/).first
  42.   duration = duration[/: (\d+)/, 1].to_i / 1000 + 2
  43.   sh "mp4box -splitx 12:#{duration} #{t.source} -out \"#{t.name}\""
  44. end
  45. # sh 'mp4box -splitx 12:3000 a.mp4'
  46.  
  47. # Pre Check
  48.  
  49. numbers = Dir['*_0*.ts'].map { |f| f[/_0(\d+)/, 1].to_i }
  50. dangers = numbers[0..-2].zip(numbers[1..-1]).select { |e| e[1] - e[0] > 1 && e[1] - e[0] < 10 }
  51. dangers.each do |e|
  52.   printf "[WARNING] %04d-%04d Diff:%d\n".on_blue.blink, e[0], e[1], e[1]-e[0]
  53. end
  54. $stdin.gets if dangers.any?
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top