TIL: ffprobe for audio file inspection
TIL Tuesday: I wasted an afternoon once debugging why a speech-to-text API kept returning garbled transcripts. Turned out the audio file was 48 kHz when the API expected 16 kHz. A quick ffprobe would have told me in one second.
ffprobe is part of ffmpeg and prints metadata about media files. For audio processing pipelines, it is the fastest way to check what you are actually working with.
ffprobe -hide_banner recording.wav
Output looks like this:
Input #0, wav, from 'recording.wav':
Duration: 00:02:34.12, bitrate: 768 kb/s
Stream #0:0: Audio: pcm_s16le, 48000 Hz, 2 channels, s16, 768 kb/s
That 48000 Hz and 2 channels line is what I needed. The API expected 16000 Hz mono. So I resampled with sox instead of guessing.
Use -show_streams for structured output you can pipe into other tools:
ffprobe -v quiet -show_streams -select_streams a:0 recording.wav
This returns key-value pairs for the first audio stream. Sample rate, codec name, channel layout, duration. Machine readable. Useful when you are validating files in a batch script.
for file in *.wav; do
rate=$(ffprobe -v quiet -show_streams -select_streams a:0 "$file" | grep "^sample_rate=" | cut -d= -f2)
if [ "$rate" != "16000" ]; then
echo "$file: wrong sample rate ($rate)"
fi
done
ffprobe -v quiet suppresses log output. Combine it with -of json for JSON output that is easier to parse in scripts.
Do I need ffmpeg installed for ffprobe?
Yes. ffprobe ships with ffmpeg. On macOS brew install ffmpeg includes it. On Debian apt install ffmpeg. It is a separate binary but always bundled.
What audio formats does ffprobe support?
Everything ffmpeg can read, which is most of them. WAV, FLAC, MP3, Opus, M4A, WebM. If ffmpeg can decode it, ffprobe can inspect it.
Can ffprobe validate audio before sending to an API?
That is exactly what I used it for. Check sample rate, channel count, codec, and duration against the API’s documented limits before you send anything. Saves a lot of debugging time.