folderToMKV.sh 1.2 KB

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