1. Overview

We sometimes need to retrieve important information from video files. This information can include the length, bitrate, resolution, audio quality, subtitles, etc. Fortunately, Linux has many tools that can retrieve all this information on the command line and even edit video files.

In this tutorial, we’ll cover some tools we can use to retrieve important information from an input video file.

2. Setup

To test these methods out, we first need to have a video file that we can use.

Let’s download a short sample mp4 video file:

$ wget https://download.samplelib.com/mp4/sample-5s.mp4
...truncated...

Length: 2848208 (2.7M)
Saving to: ‘sample-5s.mp4’

...truncated....

We used the wget command to download a video file called sample-5s.mp4, which has a size of 2.7MB.

3. Using MediaInfo

MediaInfo is one of the most powerful Linux utilities for displaying information about audio or video files.

It offers technical and tag information about an input audio or video. This includes information like the audio type, video type, subtitles, numbers of chapters, etc. It also supports a multitude of audio and video formats.

First, let’s download and install MediaInfo:

$ sudo apt install mediainfo

Then, we can use it to get information about the sample-5s.mp4 file:

$ mediainfo sample-5s.mp4 
General
Complete name                            : sample-5s.mp4
Format                                   : MPEG-4
Format profile                           : Base Media
Codec ID                                 : isom (isom/iso2/avc1/mp41)
File size                                : 2.72 MiB
Duration                                 : 5 s 759 ms
Overall bit rate                         : 3 957 kb/s
Writing application                      : Lavf58.44.100
...truncated...

We can use the –full-scan option for more detailed descriptions:

$ mediainfo --full-scan sample-5s.mp4

We can even query for specific information about an audio or video file. Let’s display only the duration of the sample-5.mp4 file:

$ mediainfo --Inform="Video;%Duration%" sample-5s.mp4 
5700

Here, we’re using the –Inform option to specify the information we want to retrieve. The value of 5700 returned is in milliseconds, i.e., 5.7 seconds.

4. Using FFprobe

FFprobe is a Linux utility that gathers information from multimedia streams and outputs it in either human-readable or machine-readable formats. It’s used to gather information such as the height, width, bitrate, codecs, pixel format, size, etc.

We can use FFprobe as a standalone program or combine it with a textual filter, which allows us to do more complex processing, e.g., statistical plotting and processing.

Let’s first install FFprobe through the package manager:

$ sudo apt install ffmpeg

Then, we can use it to display information about the sample-5s.mp4 file:

$ ffprobe sample-5s.mp4 
...truncated...
  libpostproc    55.  9.100 / 55.  9.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'sample-5s.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf58.44.100
  Duration: 00:00:05.76, start: 0.000000, bitrate: 3956 kb/s
  Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 1920x1080 [SAR 1:1 DAR 16:9], 3857 kb/s, 30 fps, 30 tbr, 15360 tbn, 60 tbc (default)
    Metadata:
      handler_name    : ISO Media file produced by Google Inc. Created on: 08/17/2020.
      vendor_id       : [0][0][0][0]
  Stream #0:1(eng): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 127 kb/s (default)
    Metadata:
      handler_name    : ISO Media file produced by Google Inc. Created on: 08/17/2020.
      vendor_id       : [0][0][0][0]

Alternatively, we can use the -hide-banner option to trim the results and only display information regarding the input file:

$ ffprobe sample-5s.mp4 -hide_banner

We can also specify the information we want to display by using options. Let’s use the -show_format option to display more information about the format of the file:

$ ffprobe sample-5s.mp4 -show_format -hide_banner
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'sample-5s.mp4':
  ...Truncated...
[FORMAT]
filename=sample-5s.mp4
nb_streams=2
nb_programs=0
format_name=mov,mp4,m4a,3gp,3g2,mj2
format_long_name=QuickTime / MOV
start_time=0.000000
duration=5.759000
size=2848208
bit_rate=3956531
probe_score=100
TAG:major_brand=isom
TAG:minor_version=512
TAG:compatible_brands=isomiso2avc1mp41
TAG:encoder=Lavf58.44.100
[/FORMAT]

5. Using ExifTool

ExifTool is an open-source application that reads, writes, and updates metadata of different types of files, e.g., Audio, video, images, PDF, etc. Metadata includes information like file size, file type, date created, and more.

It’s available as a Perl library as well as a command-line application which makes it platform-independent.

Let’s first install ExifTool:

$ sudo apt install libimage-exiftool-perl

After installation, we can use it to get information about the sample-5s.mp4:

$ exiftool sample-5s.mp4 
ExifTool Version Number         : 12.16
File Name                       : sample-5s.mp4
Directory                       : .
File Size                       : 2.7 MiB
File Modification Date/Time     : 2020:08:23 22:31:05+03:00
File Access Date/Time           : 2022:04:17 07:53:51+03:00
File Inode Change Date/Time     : 2022:04:17 07:53:50+03:00
File Permissions                : rw-rw-r--
File Type                       : MP4
File Type Extension             : mp4
MIME Type                       : video/mp4
Major Brand                     : MP4  Base Media v1 [IS0 14496-12:2003]
Minor Version                   : 0.2.0
Compatible Brands               : isom, iso2, avc1, mp41
Media Data Size                 : 2840535

We can also trim the information we get by using its options. For example, here’s an example of using the -common option:

$ exiftool -common sample-5s.mp4 
File Name                       : sample-5s.mp4
File Size                       : 2.7 MiB
Image Size                      : 1920x1080

To be more precise about the information we want to retrieve, we can specify a metadata property name before the input file:

$ exiftool -FileType sample-5s.mp4 
File Type                       : MP4

Here, we specified the metadata property -FileType, which retrieves information about the type of file.

6. Using MPlayer

Mplayer is an open-source cross-platform media player that plays audio and video files from its GUI and command line. It’s one of the oldest media players in Linux and supports a variety of audio and video file formats, subtitle types, and codecs.

First, we need to install Mplayer:

$ sudo apt install mplayer

Then, we can use it to display information about our sample file:

$ mplayer -identify -frames 0 sample-5s.mp4 
...truncated...
ID_VIDEO_ID=0
[lavf] stream 0: video (h264), -vid 0
ID_AUDIO_ID=0
ID_AID_0_LANG=eng
[lavf] stream 1: audio (aac), -aid 0, -alang eng
VIDEO:  [H264]  1920x1080  24bpp  30.000 fps  3857.4 kbps (470.9 kbyte/s)
==========================================================================
Opening video decoder: [ffmpeg] FFmpeg's libavcodec codec family
libavcodec version 58.134.100 (external)
Mismatching header version 58.91.100
Selected video codec: [ffh264] vfm: ffmpeg (FFmpeg H.264)
==========================================================================
ID_VIDEO_CODEC=ffh264
ID_FILENAME=sample-5s.mp4
...truncated...

We’re using the -identify option to retrieve information about the input file.

By default, Mplayer plays any input audio or video file. We’re passing the -frames option and setting it to 0 to prevent the video from playing.

7. Conclusion

In this article, we’ve discussed different methods we can use to retrieve information from video files on the command line. This information includes things like file type, file size, video quality, subtitles, metadata, etc.

While, by default, each tool outputs a lot of information about the input file, we can trim the results using its options.

Comments are open for 30 days after publishing a post. For any issues past this date, use the Contact form on the site.