Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Mac OS X has the command afinfo to fetch audio file info. Is there a similar command to fetch video file info for videos (.mov, .m4v) other than the mdls command?

share|improve this question
up vote 12 down vote accepted

None that comes with OS X itself.

You can download the MediaInfo command-line interface (see the "CLI" link under x64). It's also available through Homebrew in the media-info package.

Sample terminal usage:

$ mediainfo myMovie.mov

For a video, it'll produce something like the following output:

Format                                   : MPEG-4
Format profile                           : QuickTime
Format settings                          : Compressed header
Codec ID                                 : qt  
File size                                : 12.1 MiB
Duration                                 : 2mn 27s
Overall bit rate mode                    : Variable
Overall bit rate                         : 689 Kbps
Encoded date                             : UTC 2006-06-13 06:43:09
Tagged date                              : UTC 2006-06-13 06:43:12
Writing library                          : Apple QuickTime

Video #1
ID                                       : 2
Format                                   : AVC
Format/Info                              : Advanced Video Codec
Format profile                           : Main@L2.1
Format settings, CABAC                   : No
Format settings, ReFrames                : 2 frames
Format settings, GOP                     : M=2, N=24
Codec ID                                 : avc1
Codec ID/Info                            : Advanced Video Coding
Duration                                 : 2mn 23s
Source duration                          : 2mn 23s
Bit rate mode                            : Variable
Bit rate                                 : 569 Kbps
Maximum bit rate                         : 770 Kbps
Width                                    : 320 pixels
Height                                   : 240 pixels
Display aspect ratio                     : 4:3
Frame rate mode                          : Constant
Frame rate                               : 24.975 fps
Color space                              : YUV
Chroma subsampling                       : 4:2:0
Bit depth                                : 8 bits
Scan type                                : Progressive
Bits/(Pixel*Frame)                       : 0.297
Stream size                              : 9.74 MiB (80%)
Source stream size                       : 9.74 MiB (80%)
Language                                 : English
Encoded date                             : UTC 2006-06-13 06:18:04
Tagged date                              : UTC 2006-06-13 06:43:12
Color primaries                          : BT.601-6 525, BT.1358 525, BT.1700 NTSC, SMPTE 170M
Transfer characteristics                 : BT.709-5, BT.1361
Matrix coefficients                      : BT.601-6 525, BT.1358 525, BT.1700 NTSC, SMPTE 170M
share|improve this answer

You can get much information using the mdls builtin command, which is a general purpose file metadata utility. It works not only for video files, but for all types of files. It is the utility used by the finder when you use the "get info" menu command.

Here's part of the output I get when with the command on an mp4 file named forest.mp4

$mdls forest.mp4
kMDItemCodecs                  = (
    "H.264"
)
kMDItemContentCreationDate     = 2014-10-17 05:08:09 +0000
kMDItemContentModificationDate = 2014-10-17 05:08:09 +0000
kMDItemContentType             = "public.mpeg-4"
kMDItemContentTypeTree         = (
    "public.mpeg-4",
    "public.movie",
    "public.audiovisual-content",
    "public.data",
    "public.item",
    "public.content"
)
kMDItemDateAdded               = 2016-01-11 20:30:01 +0000
kMDItemDisplayName             = "forest.mp4"
kMDItemDownloadedDate          = (
    "2014-12-08 15:11:56 +0000"
)
kMDItemDurationSeconds         = 29.96166666666667
kMDItemFSContentChangeDate     = 2014-10-17 05:08:09 +0000
kMDItemFSCreationDate          = 2014-10-17 05:08:09 +0000
kMDItemFSCreatorCode           = ""
kMDItemFSFinderFlags           = 0
kMDItemFSHasCustomIcon         = (null)
kMDItemFSInvisible             = 0
kMDItemFSIsExtensionHidden     = 0
kMDItemFSIsStationery          = (null)
kMDItemFSLabel                 = 0
kMDItemFSName                  = "forest.mp4"
kMDItemFSNodeCount             = (null)
kMDItemFSOwnerGroupID          = 20
kMDItemFSOwnerUserID           = 501
kMDItemFSSize                  = 45363721
kMDItemFSTypeCode              = ""
kMDItemKind                    = "MPEG-4 Movie"
kMDItemLogicalSize             = 45363721
kMDItemMediaTypes              = (
    Video
)
kMDItemPhysicalSize            = 45367296
kMDItemPixelHeight             = 1080
kMDItemPixelWidth              = 1920
kMDItemStreamable              = 0
kMDItemTotalBitRate            = 12110
kMDItemVideoBitRate            = 12110

Furthermore, you can specify which attribute you want listed. For example, to only get the duration of the movie:

$ mdls -name kMDItemDurationSeconds forest.mp4
kMDItemDurationSeconds = 29.96166666666667
share|improve this answer

If it's helpful, here's a little script to output the filename and length for all the MP4s in a specific directory:

#! /bin/bash
# get video length of file.
for MP4 in `ls *mp4`
do
    echo "\"$MP4\",\c"
    mediainfo $MP4 | grep "^Duration" | head -1 | sed 's/^.*: \([0-9][0-9]*\)mn *\([0-9][0-9]*\)s/00:\1:\2/'
done
# END

Doesn't work if there are spaces in filenames. If your videos > 1hr just adjust the REGEXP to suit.

share|improve this answer

You must log in to answer this question.

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