I recently stumbled upon corrupted music files randomly during playback. My player (Poweramp) would skip them before the end, and I was worried more might be corrupted and started looking for a way to easily check my whole library. FFmpeg is great for the job (of course it is). Here’s the command I ended up with after browsing multiple Stack Overflow threads.
The command recursively checks FLAC files in the current directory. You can adjust the file extension, or remove it entirely to check all files. Add -maxdepth 1 after find ./ to disable recursion. You might want to run it in Screen since the process will read through your entire library, which could take some time.
IFS=$'\n'
set -f
for f in $(find ./ -name '*.flac')
do ffmpeg -v error -i "$f" -f null - |& sed -e "1i $f" -e '$a\---' | tee -a error.log
done
unset IFS
set +f
One-liner:
IFS=$'\n'; set -f; for f in $(find ./ -name '*.flac'); do ffmpeg -v error -i "$f" -f null - |& sed -e "1i $f" -e '$a\---' | tee -a error.log; done; unset IFS; set +f
Changing the IFS and disabling filename expansion with set -f allows the command to handle special characters like spaces or question marks in filenames. It will print out errors in the terminal and also write them in error.log.
FFmpeg might find problems that do not affect the actual stream in your files:
./OST/Jujutsu Kaisen/01. LOST IN PARADISE (feat. AKLO).flac
=> [flac @ 0x5579ca9e51c0] Could not read mimetype from an attached picture.
---
./Tut Tut Child - You Hide (feat. Augustus Ghost).flac
[mjpeg @ 0x5a6c0c161e40] No JPEG data found in image
[mjpeg @ 0x5a6c0c1650c0] No JPEG data found in image
=> Error while decoding stream #0:1: Invalid data found when processing input.
stream #0:1 is the cover file, while stream #0:0 would be the audio stream. Up to you if you want to deal with them. I personally don’t, since they doesn’t affect playback.
You can guestimate the time the check will take by taking a look at the read throughput on your drive by using iotop or iostat for example.