media-tester 974 B

123456789101112131415161718192021222324252627282930313233343536
  1. #!/bin/bash
  2. # A tool to scan the current directory for supported media files
  3. # and to verify whether any of them are corrupt using ffmpeg or
  4. # imagemagick accordingly, and bash >= 4.0 syntax.
  5. # Define an image scanner
  6. graphics=("gif" "bmp" "jpg" "png" "jpeg" "ico")
  7. scan_image() {
  8. for t in ${graphics[*]}; do
  9. if [ "${1##*.}" = "$t" ]; then
  10. echo "scanning $1"
  11. local o=$(gm identify "$1")
  12. [ $? -eq 0 ] && echo "$o"
  13. fi
  14. done
  15. }
  16. # Define a video scanner
  17. av=("mkv" "mp3" "rm" "rmvp" "mp4" "m4v" "avi" "wmv" "flv" "mov" "mpg" "mpeg" "ogg" "ogm" "webm" "xvid" "wpl")
  18. scan_video() {
  19. for t in ${av[*]}; do
  20. if [ "${1##*.}" = "$t" ]; then
  21. echo "scanning $1"
  22. local o=$(ffmpeg -v error -i "$1" -f null - 2>&1)
  23. [ $? -ne 0 ] && [ -n "$o" ] && echo "$o"
  24. fi
  25. done
  26. }
  27. # Recursively send all files and their extensions to defined scanners
  28. find "$PWD" -type f -print0 | while IFS= read -r -d $'\0' f; do
  29. scan_image "$f"
  30. scan_video "$f"
  31. done
  32. echo "scan complete"