folderToMKV.sh 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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. ~/bin/video/findRecode0 "${inFolder}" | xargs -0 -n1 ~/bin/video/recode
  21. # MPEGs must be recoded, not just re-wrapped
  22. for i in "${inFolder}/"*.[mM][pP][gG] "${inFolder}/"*.[mM][pP][eE][gG]; do
  23. # Make sure the file is reasonable
  24. if [ ! -e "${i}" ]; then
  25. continue
  26. fi
  27. # Recode
  28. ~/bin/video/recode "${i}"
  29. done
  30. fi
  31. # Move to the input folder
  32. inFolder="`cd "${inFolder}" && pwd`"
  33. cd "${inFolder}"
  34. # Cycle through the folder looking for certain video files that should be converted to better containers
  35. 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
  36. # Bail if the load is high
  37. if ! ~/bin/video/checkLoad.sh; then
  38. continue
  39. fi
  40. # Construct the full path
  41. file="${inFolder}/${i}"
  42. # Make sure the file is reasonable
  43. if [ ! -e "${file}" ]; then
  44. continue
  45. fi
  46. # Rewrap as MOV
  47. ~/bin/video/toMKV.sh "${file}"
  48. done