Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 2nd, 2012  |  syntax: None  |  size: 3.56 KB  |  hits: 19  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. -- Based on the inner workings of MKV4XBox created by Stephan Linke
  2. -- http://www.macupdate.com/info.php/id/30486/mkv4xbox
  3.  
  4. on open names
  5.         -- tools
  6.         set MEDIAINFO to "/Library/Application\\ Support/MKV4XBox/Tools/mediainfo"
  7.         set MKVEXTRACT to "/Library/Application\\ Support/MKV4XBox/Tools/mkvextract"
  8.         set MKVPATCH to "/Library/Application\\ Support/MKV4XBox/Tools/mkvpatch"
  9.         set FFMPEG to "/Library/Application\\ Support/MKV4XBox/Tools/ffmpeg"
  10.         set DTSDEC to "/Library/Application\\ Support/MKV4XBox/Tools/dtsdec"
  11.         set MP4BOX to "/Library/Application\\ Support/MKV4XBox/Tools/mp4box"
  12.        
  13.         -- process each file supplied  
  14.         repeat with input_file in names
  15.                
  16.                 -- get the path to the file
  17.                 set input_path to POSIX path of input_file
  18.                
  19.                 -- get the base directory of file
  20.                 set file_dir to do shell script "perl -e '$_=\"" & input_path & "\";/(.*)\\/(.*?)$/;print $1'"
  21.                
  22.                 -- get the file name, minus .mkv extension
  23.                 set file_name to do shell script "perl -e '$_=\"" & input_path & "\";/(.*)\\/(.*?).mkv$/i;print $2'"
  24.                
  25.                 -- get the name of TV show - probably want to separate this out at some point
  26.                 -- set tv_show_name to do shell script "perl -e '$_=\"" & input_path & "\";/.*\\/(.*?)$/;$1=~/(.*?\\.s\\d\\de\\d\\d)/i;$filename=$1;$filename=~tr/A-Z/a-z/;print $filename'"
  27.                
  28.                 -- get the ID for the video
  29.                 set video_id to do shell script MEDIAINFO & " '--Inform=Video;%ID%' " & quoted form of input_path
  30.                 -- get the ID for the audio
  31.                 set audio_id to do shell script MEDIAINFO & " '--Inform=Audio;%ID%' " & quoted form of input_path
  32.                 -- get the video framerate
  33.                 set frame_rate to do shell script MEDIAINFO & " '--Inform=Video;%FrameRate%' " & quoted form of input_path
  34.                 -- get the audio format
  35.                 set audio_format to do shell script MEDIAINFO & " '--Inform=Audio;%Format%' " & quoted form of input_path
  36.                 -- get the audio sampling rate
  37.                 set sampling_rate to do shell script MEDIAINFO & " '--Inform=Audio;%SamplingRate%' " & quoted form of input_path
  38.                
  39.                 -- working directory
  40.                 set working_dir to file_dir & "/convert-" & file_name
  41.                 -- create working directory
  42.                 try
  43.                         do shell script "mkdir " & quoted form of working_dir
  44.                 end try
  45.                
  46.                 -- set up some variables
  47.                 set file_movie to working_dir & "/movie.x264"
  48.                 set file_audiotrack to working_dir & "/audiotrack.ac3"
  49.                 set file_audio to working_dir & "/audio.mp4"
  50.                 set file_moviemp4 to working_dir & "/movie.mp4"
  51.                 set file_outputfile to file_dir & "/" & file_name & ".mp4"
  52.                
  53.                 -- extract mkv         
  54.                 do shell script MKVEXTRACT & " tracks " & quoted form of input_path & " " & video_id & ":" & quoted form of file_movie & " " & audio_id & ":" & quoted form of file_audiotrack
  55.                
  56.                 -- patch the source video file
  57.                 do shell script "dd if=" & MKVPATCH & " bs=1 conv=notrunc of=" & quoted form of file_movie & " seek=7 count=2"
  58.                
  59.                 -- convert the source audio file
  60.                 do shell script FFMPEG & " -i " & quoted form of file_audiotrack & " -ab 320 -aq " & sampling_rate & " -vol 256 -ac 2 -acodec aac " & quoted form of file_audio
  61.                
  62.                 -- mux audio and video together
  63.                 do shell script MP4BOX & " -add " & quoted form of file_movie & "#video -add " & quoted form of file_audio & "#audio -fps " & frame_rate & " " & quoted form of file_moviemp4
  64.                
  65.                 -- move output file back to file dir
  66.                 do shell script "mv " & quoted form of file_moviemp4 & " " & quoted form of file_outputfile
  67.                
  68.                 -- clean up working directory
  69.                 try
  70.                         do shell script "rm -rf " & quoted form of working_dir
  71.                 end try
  72.                
  73.                 -- move source file to trash
  74.                 do shell script "mv " & quoted form of input_path & " ~/.Trash/"
  75.                
  76.         end repeat
  77. end open