33

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
34

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
29

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 '17 at 2:07
13

You can do this with the FFmpeg project:

ffprobe 'Breaking The Girl-EVmfXA3vjuE.mp4'

Result:

Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'Breaking The Girl-EVmfXA3vjuE.mp4':
  Metadata:
    major_brand     : mp42
    minor_version   : 0
    compatible_brands: isommp42
    creation_time   : 2016-10-05T03:35:07.000000Z
  Duration: 00:04:55.38, start: 0.000000, bitrate: 330 kb/s
    Stream #0:0(und): Video: h264 (Main) (avc1 / 0x31637661), yuv420p(tv, bt709),
      1280x720 [SAR 1:1 DAR 16:9], 200 kb/s, 25 fps, 25 tbr, 90k tbn, 50 tbc (default)
    Metadata:
      creation_time   : 2016-10-05T03:35:07.000000Z
      handler_name    : ISO Media file produced by Google Inc.
    Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp,
      125 kb/s (default)
    Metadata:
      creation_time   : 2016-10-05T03:35:07.000000Z
      handler_name    : ISO Media file produced by Google Inc.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.