Find All MP4 Files With DTS or AC3/A52 Audio

audiospotlight

Okay, so after spending a lot of time encoding (or re-encoding) files to mp4's hoping they'd be compatible with iTunes, it turns out that iTunes won't play files with DTS or AC3/A52 audio, so I'm going to have to re-encode the audio on such files to AAC (where before I simply passed it through).

Anyway, I need a way to find all files with these audio types or, if it's easier, all MP4 files without AAC audio.

What is the best way to do this? Ideally I'd like to use Spotlight if I can, though I've tried several search criteria without much luck, but I'll also accept answers that use Terminal-based solutions, as I'll probably use ffmpeg to convert the audio anyway.

Best Answer

I made a shell script. This will print any file that has a different codec. Set the directory and extension to look for.

#!/bin/zsh
directory=~/Music
extension=m4a
codec=aac

find $directory -type f -name "*.$extension" -print0 | while read -d $'\0' file
do
    file_codec="$(ffprobe -v quiet -show_streams -print_format json $file | jq '.streams[0].codec_name')"
    [[ "${file_codec//\"}" != $codec ]] && echo $file
done

You need ffmpeg and jq. You can install both of them from homebrew.