Created
October 20, 2010 21:05
-
-
Save tekkub/637322 to your computer and use it in GitHub Desktop.
Remux that shit!
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 characters
#!/usr/bin/env ruby | |
raise "Specify a video file!" unless mkv_file = ARGV.first | |
audio_file = mkv_file.gsub(/\.mkv/, ".ac3") | |
audio_track_file = mkv_file.gsub(/\.mkv/, ".mp4") | |
video_file = mkv_file.gsub(/\.mkv/, ".264") | |
m4v_file = mkv_file.gsub(/\.mkv/, ".m4v") | |
VLC_PATH = "/Applications/VLC.app/Contents/MacOS/VLC" | |
MP4BOX_PATH = "/Users/tekkub/bin/MP4box" | |
# MKVEXTRACT_PATH = "/Users/tekkub/bin/mkvextract" | |
# MKVMERGE_PATH = "/Users/tekkub/bin/mkvmerge" | |
puts "Extracting audio track" | |
# puts ident = `mkvmerge --identify "#{mkv_file}"` | |
# raise "Cannot find audio track" unless audio_track = ident.match(/^Track ID (\d+): audio/).to_a[1] | |
# `mkvextract tracks "#{mkv_file}" --raw #{audio_track}:"#{audio_file}"` | |
# `#{VLC_PATH} -I rc "#{mkv_file}" --sout='#transcode{vcodec=dummy,vb=1024,acodec=mp4a,ab=512}:std{mux=mp4,access=file,dst=#{audio_file}}' vlc://quit` | |
`#{VLC_PATH} -I rc "#{mkv_file}" --sout='#transcode{vcodec=dummy,vb=1024,acodec=fl32,ab=192}:standard{mux=wav,access=file,dst=#{audio_file}}' vlc://quit` | |
puts "Transcoding audio" | |
`afconvert "#{audio_file}" --file mp4f --data "aac@48000" --bitrate 320000` | |
# puts "Extracting audio track" | |
# `#{MP4BOX_PATH} "#{audio_file}" -raw 1` | |
puts "Extracting video track" | |
puts ident = `mkvmerge --identify "#{mkv_file}"` | |
raise "Cannot find video track" unless video_track = ident.match(/^Track ID (\d+): video/).to_a[1] | |
`mkvextract tracks "#{mkv_file}" #{video_track}:"#{video_file}"` | |
puts "Muxing streams" | |
puts `#{MP4BOX_PATH} -add "#{video_file}":fps=23.976 -add "#{audio_track_file}" "#{m4v_file}"` | |
File.delete audio_file, audio_track_file, video_file |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment