folderToMKV.sh 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. #!/bin/bash
  2. # Bail if media is not available
  3. if ! ~/bin/video/isMediaMounted; then
  4. exit 0
  5. fi
  6. # Command line
  7. inFolder="${1}"
  8. if [ -z "${inFolder}" ] || [ ! -e "${inFolder}" ]; then
  9. echo "Usage: `basename "${0}"` input_folder" 1>&2
  10. exit 1
  11. fi
  12. # Bail if we're already running a lot
  13. me="`basename "${0}"`"
  14. if [ `ps auwx | grep -v grep | grep "${me}" | wc -l` -gt 10 ]; then
  15. exit 0
  16. fi
  17. # Skip recoding if the host is not capable
  18. if ~/bin/video/canRecode.sh; then
  19. # Prefer recoding to rewrapping if the file is overrate
  20. NO_LAST_RECODE_FILE=1 ~/bin/video/findRecode0 "${inFolder}" | \
  21. xargs -0 -n1 ~/bin/video/recode
  22. # MPEGs must be recoded, not just re-wrapped
  23. for i in "${inFolder}/"*.[mM][pP][gG] "${inFolder}/"*.[mM][pP][eE][gG]; do
  24. # Make sure the file is reasonable
  25. if [ ! -e "${i}" ]; then
  26. continue
  27. fi
  28. # Recode
  29. ~/bin/video/recode "${i}"
  30. done
  31. fi
  32. # Move to the input folder
  33. inFolder="`cd "${inFolder}" && pwd`"
  34. cd "${inFolder}"
  35. # Cycle through the folder looking for certain video files that should be converted to better containers
  36. for i in *.[aA][vV][iI] *.[wW][mM][vV] *.[dD][iI][vV][xX] *.[fF][lL][vV] *.[mM][pP]4 *.3[gG][pP] *.[wW][eE][bB][mM]; do
  37. # Bail if the load is high
  38. if ! ~/bin/video/checkLoad.sh; then
  39. continue
  40. fi
  41. # Construct the full path
  42. file="${inFolder}/${i}"
  43. # Make sure the file is reasonable
  44. if [ ! -e "${file}" ]; then
  45. continue
  46. fi
  47. # Rewrap as MOV
  48. ~/bin/video/toMKV.sh "${file}"
  49. done