Is there a command analogous to afinfo for videos on a Mac OS X?

12

8

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?

smokinguns

Posted 2012-04-19T23:54:20.410

Reputation: 1 188

Answers

27

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

slhck

Posted 2012-04-19T23:54:20.410

Reputation: 182 472

Also port install mediainfo if using ports. – toddkaufmann – 2016-09-28T01:03:45.560

5

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

BrunoFrechette

Posted 2012-04-19T23:54:20.410

Reputation: 51

I think this is a very good answer, since it uses the same tool as the system, and it works out of the box. It should have won ;) – Christian Tismer – 2019-10-02T10:55:07.257

0

Small improvement over using mediainfo.

You'll need jq (brew install jq) and use JSON output from mediainfo

Then you can use it as a stand-alone script or put it into your ~/.bashrc or ~/.zshrc:

    #!/bin/bash

    IFS=$'\n'

    # accepts any list of files, eg. video_times *.{mp4,mov}
    video_times() {
        for file in $* ; do
            duration=$(mediainfo --Output=JSON "$file" | jq -r '.media.track[] | select(."@type"=="General") | .Duration | tonumber | floor')
            minutes=$(($duration / 60))
            seconds=$(($duration % 60))
            echo "$file: ${minutes}m${seconds}s"
        done
    }

    video_times $*

bonkey

Posted 2012-04-19T23:54:20.410

Reputation: 101

0

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.

Ric

Posted 2012-04-19T23:54:20.410

Reputation: 1