folderToMov.sh 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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. # Bail if the load average is high
  14. LOAD="`uptime | awk -F ': ' '{print $2}' | cut -d '.' -f 1`"
  15. CPU_COUNT="`sysctl -n hw.ncpu`"
  16. if [ $LOAD -gt $(( 2 * $CPU_COUNT )) ]; then
  17. exit 0
  18. fi
  19. # Prefer recoding to rewrapping if the file is overrate
  20. ~/bin/video/findRecode0 "${inFolder}" | xargs -0 -n1 ~/bin/video/recode
  21. # Move to the input folder
  22. inFolder="`cd "${inFolder}" && pwd`"
  23. cd "${inFolder}"
  24. # Cycle through the folder looking for certain video files that should be converted to better containers
  25. for i in *.[aA][vV][iI] *.[wW][mM][vV] *.[mM][kK][vV] *.[dD][iI][vV][xX] *.[fF][lL][vV]; do
  26. # Construct the full path
  27. file="${inFolder}/${i}"
  28. # Make sure the file is reasonable
  29. if [ ! -e "${file}" ]; then
  30. continue
  31. fi
  32. # Bail if WoW is running
  33. if ps auwx | grep -v grep | grep -q "World of Warcraft/World of Warcraft.app/Contents/MacOS/World of Warcraft"; then
  34. exit 0
  35. fi
  36. # Convert to M4V/MOV
  37. ~/bin/video/toMov.sh "${file}"
  38. done