50

I am writing a bash script that I want to echo out metadata (length, resolution etc.) of a set of videos (mp4) into a file.

Is there a simple way to get this information from an MP4 file?

1

3 Answers 3

54

On a Debian-based system (but presumably, other distributions will also have mediainfo in their repositories):

$ sudo apt-get install mediainfo
$ mediainfo foo.mp4

That will spew out a lot of information. To get, for example, the length, resolution, codec and dimensions use:

$ mediainfo "The Blues Brothers.mp4" | grep -E 'Duration|Format  |Width|Height' | sort | uniq
Duration                                 : 2h 27mn
Format                                   : AAC
Format                                   : AVC
Format                                   : MPEG-4
Height                                   : 688 pixels
Width                                    : 1 280 pixels
37

You can use exiftool. To install it run:

sudo apt-get install libimage-exiftool-perl

Then to get the metadata from mp4 file run:

exiftool video_file.mp4 > medatata.txt

The output saved in the file should be something like this:

ExifTool Version Number         : 9.60
File Name                       : video_file.mp4
Directory                       : .
File Size                       : 11 MB
File Modification Date/Time     : 2014:05:12 21:25:11+03:00
File Access Date/Time           : 2014:05:20 23:05:35+03:00
File Inode Change Date/Time     : 2014:05:12 21:25:11+03:00
File Permissions                : rw-r--r--
File Type                       : MP4
MIME Type                       : video/mp4
Major Brand                     : MP4 v2 [ISO 14496-14]
Minor Version                   : 0.0.0
Compatible Brands               : isom, mp42
Movie Header Version            : 0
Create Date                     : 2014:04:24 05:33:58
Modify Date                     : 2014:04:24 05:33:58
Time Scale                      : 600
Duration                        : 0:03:10
Preferred Rate                  : 1
Preferred Volume                : 100.00%
Preview Time                    : 0 s
Preview Duration                : 0 s
Poster Time                     : 0 s
Selection Time                  : 0 s
Selection Duration              : 0 s
Current Time                    : 0 s
Next Track ID                   : 3
Track Header Version            : 0
Track Create Date               : 0000:00:00 00:00:00
Track Modify Date               : 2014:04:24 05:33:59
Track ID                        : 1
Track Duration                  : 0:03:10
Track Layer                     : 0
Track Volume                    : 0.00%
Image Width                     : 450
Image Height                    : 360
Graphics Mode                   : srcCopy
Op Color                        : 0 0 0
Compressor ID                   : avc1
Source Image Width              : 450
Source Image Height             : 360
X Resolution                    : 72
Y Resolution                    : 72
Bit Depth                       : 24
Buffer Size                     : 19318
Max Bitrate                     : 1059760
Average Bitrate                 : 396688
Video Frame Rate                : 25
Matrix Structure                : 1 0 0 0 1 0 0 0 1
Media Header Version            : 0
Media Create Date               : 2014:04:24 05:33:58
Media Modify Date               : 2014:04:24 05:33:59
Media Time Scale                : 44100
Media Duration                  : 0:03:10
Media Language Code             : und
Handler Description             : IsoMedia File Produced by Google, 5-11-2011
Balance                         : 0
Audio Format                    : mp4a
Audio Channels                  : 2
Audio Bits Per Sample           : 16
Audio Sample Rate               : 44100
Handler Type                    : Metadata
Handler Vendor ID               : Apple
Google Start Time               : 0
Google Track Duration           : 191006
Google Source Data              : B567F7685HH1399919109001385
Google Ping URL                 : 
Google Ping Message             : 
Google Host Header              : r2---sn-gqn-vhge.googlevideo.com
Movie Data Size                 : 11755744
Movie Data Offset               : 60204
Avg Bitrate                     : 493 kbps
Image Size                      : 450x360
Rotation                        : 0
1
  • 1
    On OS X if Homebrew package manager is installed already, then homebrew install exiftool' and it will be compiled by perl and become available the same way, as exiftool video_file.mp4 > medatata.txt`
    – HongPong
    Nov 20, 2017 at 2:07
24

You can do this with the FFmpeg project:

ffprobe 'Yagya (IS) - Topic-Choose-Hlw4YohQzr4.webm'

Result:

Input #0, matroska,webm, from 'Yagya (IS) - Topic-Choose-Hlw4YohQzr4.webm':
  Metadata:
    encoder         : google/video-file
  Duration: 00:08:45.52, start: 0.000000, bitrate: 294 kb/s
  Stream #0:0(eng): Video: vp9 (Profile 0), yuv420p(tv), 720x720,
   SAR 1:1 DAR 1:1, 25 fps, 25 tbr, 1k tbn (default)

You must log in to answer this question.

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