toMov.sh 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. #!/bin/bash
  2. # Command line
  3. inFile="${1}"
  4. outFile="${2}"
  5. movLength="${3}"
  6. if [ -z "${inFile}" ] || [ ! -e "${inFile}" ]; then
  7. echo "Usage: `basename "${0}"` input_file [output_file] [mov_length]" 1>&2
  8. exit 1
  9. fi
  10. # Exclude files with DTS soundtracks
  11. ACODECS="`~/bin/video/movInfo.pl "${inFile}" | grep AUDIO_CODEC`"
  12. if [ -z "${ACODECS}" ]; then
  13. echo "`basename "${0}"`: Could not determine audio codec" 1>&2
  14. exit 2
  15. fi
  16. if echo "${ACODECS}" | grep -q ffdca; then
  17. exit 1
  18. fi
  19. # Construct the output file name
  20. if [ -z "${outFile}" ]; then
  21. # Use the input file name with a .mov extension
  22. outFile="`basename "${inFile}"`"
  23. outFile="`echo "${outFile}" | sed 's%\.[A-Za-z0-9]*$%.mov%'`"
  24. outFile="`dirname "${inFile}"`/${outFile}"
  25. fi
  26. # Convert to MOV
  27. tmpFile="`mktemp -t toMov`"
  28. catmovie -q -self-contained -o "${tmpFile}" $chaps "${inFile}" 2>/dev/null
  29. # Check for errors
  30. if [ ! -e "${tmpFile}" ] || [ `stat -f '%z' "${tmpFile}"` -lt 1000 ]; then
  31. echo "`basename "${0}"`: Error creating output file for input: ${inFile}" 1>&2
  32. # Try to recode (with Handbrake/ffmpeg) if QuickTime fails
  33. echo "`basename "${0}"`: Attempting recode instead..." 1>&2
  34. ~/bin/video/recode "${inFile}"
  35. exit "${?}"
  36. fi
  37. # Move into place, dropping the original
  38. tmpOut="`mktemp "${outFile}.XXXXXXXX"`"
  39. cp -X "${tmpFile}" "${tmpOut}" && rm "${inFile}" && mv "${tmpOut}" "${outFile}"
  40. rm -f "${tmpFile}"
  41. # Exit cleanly
  42. exit 0