Advertisement
Guest User

Untitled

a guest
Oct 22nd, 2014
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.13 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3.  
  4. # Evaluate the file passed to the script for information relevant to the process
  5. find . -type f | grep .mkv$ | while read file
  6. do
  7. directory=`dirname "$file"`
  8. title=`basename "$file" .mkv`
  9.  
  10. # Check the audio track used in the files
  11. AC3=`mkvinfo "$file" | grep AC3` #check if it's AC3 audio or DTS
  12. AAC=`mkvinfo "$file" | grep AAC`
  13. order=`mkvinfo "$file" | grep "Track type" | sed 's/.*://' | head -n 1 | tr -d " "` #check if the video track is first or the audio track
  14.  
  15. # Start processing
  16. # If video is the first track
  17. if [ "$order" = "video" ]; then
  18. fps=`mkvinfo "$file" | grep duration | sed 's/.*(//' | sed 's/f.*//' | head -n 1` #store the fps of the video track
  19.  
  20. # If audio is encoded in AC3
  21. if [ -n "$AC3" ]; then
  22. mkvextract tracks "$file" 1:"${title}".264 2:"${title}".ac3
  23. ffmpeg -i "${title}".ac3 -acodec libfaac -ab 576k "${title}".aac
  24. # mplayer -ao pcm:file="${title}".wav:fast "${title}".ac3
  25. # faac -o "${title}".aac "${title}".wav
  26.  
  27.  
  28. # If audio is encoded in AAC
  29. elif [ -n "$AAC" ]; then
  30. mkvextract tracks "$file" 1:"${title}".264 2:"${title}".aac
  31.  
  32. # If encoded in DTS or something else
  33. else
  34. mkvextract tracks "$file" 1:"${title}".264 2:"${title}".dts
  35. ffmpeg -i "${title}".dts -acodec libfaac -ab 576k "${title}".aac
  36. fi
  37. else
  38.  
  39. # If video is not the first track
  40. fps=`mkvinfo "$file" | grep duration | sed 's/.*(//' | sed 's/f.*//' | tail -n 1`
  41. if [ -n "$AC3" ]; then
  42. mkvextract tracks "$file" 1:"${title}".ac3 2:"${title}".264
  43. ffmpeg -i "${title}".ac3 -acodec libfaac -ab 576k "${title}".aac
  44. # mplayer -ao pcm:file="${title}".wav:fast "${title}".ac3
  45. # faac -o "${title}".aac "${title}".wav
  46. elif [ -n "$AAC" ]; then
  47. mkvextract tracks "$file" 1:"${title}".264 2:"${title}".aac
  48. else
  49. mkvextract tracks "$file" 1:"${title}".dts 2:"${title}".264
  50. ffmpeg -i "${title}".dts -acodec libfaac -ab 576k "${title}".aac
  51. fi
  52. fi
  53. MP4Box -new "${directory}/${title}".mp4 -add "${title}".264 -add "${title}".aac -fps $fps
  54. rm -f "$title".aac "$title".dts "$title".ac3 "$title".264 "${title}".wav
  55. # if [ -f "${directory}/${title}".mp4 ]; then
  56. # rm -f "$file"
  57. # fi
  58. done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement