fix-file.sh 716 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. #!/bin/bash
  2. set -e
  3. if [ $# -ne 1 ]; then
  4. echo "usage: $0 in.mp4"
  5. exit 1
  6. fi
  7. if [ ! -f "$1" ]; then
  8. echo "$1 doesn't exist"
  9. exit 1
  10. fi
  11. tmpfile="$1.tmp"
  12. if [ -f "$tmpfile" ]; then
  13. echo "$tmpfile exists"
  14. exit 1
  15. fi
  16. mv "$1" "$tmpfile"
  17. audiofile=$(mktemp).aac
  18. videofile=$(mktemp).mp4
  19. function finish {
  20. rm -f $audiofile
  21. rm -f $videofile
  22. }
  23. trap finish EXIT
  24. ffmpeg -hide_banner -analyzeduration 16M -i "$tmpfile" -c:v copy -an -f mp4 -y $videofile
  25. ffmpeg -hide_banner -analyzeduration 16M -i "$tmpfile" -c:a copy -vn -bsf:a aac_adtstoasc -y $audiofile
  26. ffmpeg -hide_banner -i $audiofile -i $videofile -c copy -bsf:a aac_adtstoasc -y "$1"
  27. rm -f "$tmpfile" #no quiero borrarlo a menos que todo haya salido bien