Guest

Untitled

By: a guest on Mar 18th, 2010  |  syntax: None  |  size: 3.62 KB  |  hits: 66  |  expires: Never
download  |  raw  |  embed  |  report abuse
Copied
  1. #!/bin/bash
  2.  
  3. ##########################
  4. ## CHECK FOR SOME TOOLS ##
  5. ##########################
  6.  
  7. if [ -f $(which mplayer) ]; then
  8.     echo "We have $(which mplayer) good..."
  9. else echo "We don't have $(which mplayer) binary in your PATH." && exit 1
  10. fi
  11.  
  12. if [ -f $(which mencoder) ]; then
  13. echo "We have $(which mencoder) good..."
  14. else echo "We don't have $(which mencoder) binary in your PATH." && exit 1
  15. fi
  16.  
  17. if [ -f $(which x264) ]; then
  18. echo "We have $(which x264) good..."
  19. else echo "We don't have $(which x264) binary in your PATH." && exit 1
  20. fi
  21.  
  22. if [ -f $(which neroAacEnc) ]; then
  23. echo "We have $(which neroAacEnc) good..."
  24. else echo "We don't have $(which neroAacEnc) binary in your PATH." && exit 1
  25. fi
  26.  
  27. #################################
  28. ## Setup some global variables ##
  29. #################################
  30.  
  31. declare -x audiopipe="audiopipe"
  32. declare -x videopipe="videopipe"
  33. declare -x br="900"
  34. declare -x fps="23.976"
  35. declare -x basedir="$(pwd)"
  36. declare -x res="720x480"
  37. declare -x message0="USAGE: $0 <Bitrate> <resolution> <final mp4 name> <video to encode>..."
  38. declare -x message1="The defaults are:<$br> <$fps> <$finalmp4> <$thevideo>"
  39. declare -x message2="Arguments cannot be skipped.  Type no args for all defaults, or all args"
  40. declare -x vidstream="x264_tmp.mp4"
  41. declare -x m4astream="audiostream.m4a"
  42. declare -x finalmp4="finalmp4.mp4"
  43. declare -x thevideo="title.vob"
  44.  
  45. ################################
  46. ## Setup some DEFAULT Values  ##
  47. ################################
  48.  
  49. BR=${1:-"$br"}
  50. RES=${2:-"$res"}
  51. FINALMP4=${3:-"$finalmp4"}
  52. THEVIDEO=${4:-"$thevideo"}
  53.  
  54. ################################
  55. ## Check the number of ARGS   ##
  56. ################################
  57.  
  58. if [ $# -ne 4 ]; then
  59.     echo "$message0" && echo && echo "$message1" && echo "$message2"
  60. fi
  61.  
  62. cd "$basedir"
  63.  
  64. # Make the pipes
  65. mkfifo "$audiopipe" 2> /dev/null
  66. mkfifo "$videopipe" 2> /dev/null
  67.  
  68. #Encode the audio to HC/AAC
  69. if [ -f "$m4astream" ]; then
  70. rm "$m4astream"
  71. fi
  72. rm *.bz2 2> /dev/null
  73. neroAacEnc -ignorelength -br 48000 -he -if "$audiopipe" -of "$m4astream" 2> neroAacEnc.log & mplayer -nocorrect-pts -vo null -vc null -ao pcm:file="$audiopipe":fast "$THEVIDEO" 2> audiorip.err > audiorip.log
  74. rm "$audiopipe"
  75. # Join the stderr files and stdout files then compress with bzip2
  76. cat neroAacEnc.log audiorip.err audiorip.log | bzip2 -9c > audiostream.log.bz2
  77. rm neroAacEnc.log audiorip.err audiorip.log
  78.  
  79. #Encode the video
  80. if [ -f "$vidstream" ]; then
  81. rm "$vidstream"
  82. fi
  83. # Start Pass 1
  84. x264 --pass 1 --threads 3 --bitrate "$BR" --fps "$fps" --ref 3 --bframes 3 --direct auto --analyse all --8x8dct --subme 7 --me umh --trellis 1 --mixed-refs -q 30 --crf 20 --output "$vidstream" "$videopipe" "$RES" &> myx264_pass1.log & mencoder -vf format=i420 -nosound -ovc raw -of rawvideo -ofps "$fps" -o "$videopipe" "$THEVIDEO" 2> mencoder_raw.err > mencoder_raw.log
  85.  
  86. x264 --pass 2 --threads 3 --bitrate "$BR" --fps "$fps" --ref 3 --bframes 3 --direct auto --analyse all --8x8dct --subme 7 --me umh --trellis 1 --mixed-refs --output "$vidstream" "$videopipe" "$RES" &> myx264_pass2.log & mencoder -vf format=i420 -nosound -ovc raw -of rawvideo -ofps "$fps" -o "$videopipe" "$THEVIDEO" 2> mencoder_raw-pass2.err > mencoder_raw-pass2.log
  87.  
  88. # Archive log files for future analysis...
  89. cat *.log x264_2pass* *.err | bzip2 -9c > videostream.log.bz2
  90. rm *.log x264_2pass* *.err 2> /dev/null
  91.  
  92. # Build MP4 container
  93. MP4Box -add "$vidstream"#video "$FINALMP4" &> container_vid.log
  94. MP4Box -add "$m4astream"#audio "$FINALMP4" &> container_audio.log
  95. cat container* | bzip -9c > MP4Box.log.bz2
  96. rm container*
  97. rm "$videopipe"
  98. if [ -f mkx264_sh.scriptoutput ]; then
  99. cat mkx264_sh.scriptoutput | bzip2 -9c > mkx264_sh.scriptoutput.bz2 && rm mkx264_sh.scriptoutput
  100. fi