folderToMKV.sh 1.3 KB

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