folderToMKV.sh 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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. # Prefer recoding to rewrapping if the file is overrate
  18. ~/bin/video/findRecode0 "${inFolder}" | xargs -0 -n1 ~/bin/video/recode
  19. # MPEGs must be recoded, not just re-wrapped
  20. for i in "${inFolder}/"*.[mM][pP][gG] "${inFolder}/"*.[mM][pP][eE][gG]; do
  21. # Make sure the file is reasonable
  22. if [ ! -e "${i}" ]; then
  23. continue
  24. fi
  25. # Recode
  26. ~/bin/video/recode "${i}"
  27. done
  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; 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