I'm writing some shell scripts that automatically convert some video files. Except I don't want to run the conversion on files that are already h264 encoded. Is there a way I can tell via a terminal command whether a video has a certain codec?

2 Answers 2


This won't work for .avi files (at least it didn't for one I tried), but for .mp4 or .mov files, it should.

To list a file's codecs:

$ mdls -name kMDItemCodecs "/path/to/some/file.mp4"
kMDItemCodecs = (

To find files that are movies, but don't have the H.264 codec:

mdfind "kMDItemContentTypeTree == 'public.movie' && kMDItemCodecs != '*H.264*'"
  • Isn't that because Quicktime components don't ship any of the various AVI codecs? I imagine mdls is almost exclusively functional to the MPEG series of codecs and not much more. Aug 16, 2011 at 20:00
  • FWIW, QuickTime Player's Movie Inspector does list the AVI file's codecs. Aug 16, 2011 at 21:05
  • Good point :). That also goes in line with your public.movie != H.264 in your answer as well. Aug 16, 2011 at 21:14

With ffmpeg : ffmpeg -i video_file

see : http://videotranscoding.wikispaces.com/GetVideoMetadata

  • The provided link is broken. Jun 22, 2017 at 15:56

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .