Extract Video Metadata in Python

So, in this blog, you will learn how to extract video metadata using Python programming. There are several ways of extracting the metadata of different media files and in this text, we are going to discuss a few very simple and quick methods of extracting the metadata of video files using Python programming. Read the text below to learn and explore new methods.

Methods: Metadata extraction of a video file in Python

Two methods of extracting video metadata have been discussed in this text. These two methods are using TinyTag module and the ExifTool method respectively.

Using TinyTag:

This method of extracting the metadata of a video file is very easy but, in this method, you have to manually write the information you want to extract from the video file itself in the program as shown below. Also, install the tinytag library using the pip install method.

pip install tinytag


# import the module
from tinytag import TinyTag
# Use TinyTag.get() method to get the info of the video file
# paste the path of the video file along with its type for example mp4
Video_file=TinyTag.get("C:/Users/kovid/Downloads/365 Days (2022) (WebRip) (PC HD Full Movie).mp4")
# Now manually write the headings of the particular information you want to extract
# for title
# for composer
# for bitrate
# for video size in bytes
# for the duration of the video in seconds
# for the genre of the video


Extract Video Metadata in Python


This method is very helpful if you want to extract only a little information of your video file.

Using ExifTool:

This method is used to extract the entire information of your video file and for that, you need to install the ExifTool on your device. You can download this tool for windows from the link below.


subprocess.Popen– This function commands the subprocess to open a process for extracting the data.
stdout– It is the standard output that reads the output.
subprocess.PIPE– It helps in connecting one method to the other. It makes an interconnection between different methods.
stderr- It stands for standrad errors. We use it to eliminate errors.
universal_newlines– It is set to True to remove unwanted symbols from the metadata.


# import the preinstalled module
import subprocess
# write the complete path of your video file along with its type for example mp4 
input_file="C:/Users/kovid/Downloads/365 Days (2022) (WebRip) (PC HD Full Movie).mp4"
# write the complete path of the ExifTool in your device along with .exe at last
# process is a variable
# For the output
for output in process.stdout:
    print(output.strip()) # strip is used to remove unwanted spaces
File Name                       : 365 Days (2022) (WebRip) (PC HD Full Movie).mp4
Directory                       : C:/Users/kovid/Downloads
File Size                       : 825 MB
Zone Identifier                 : Exists
File Modification Date/Time     : 2022:10:04 19:23:12+05:30
File Access Date/Time           : 2022:11:30 09:48:25+05:30
File Creation Date/Time         : 2022:10:04 19:03:25+05:30
File Permissions                : -rw-rw-rw-
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                 : 816985846
Media Data Offset               : 48
Movie Header Version            : 0
Create Date                     : 2022:05:05 07:25:10
Modify Date                     : 2022:05:05 07:25:10
Time Scale                      : 1000
Duration                        : 1:51:17
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                   : 4
Track Header Version            : 0
Track Create Date               : 2022:05:05 07:25:10
Track Modify Date               : 2022:05:05 07:25:10
Track ID                        : 1
Track Duration                  : 1:51:16
Track Layer                     : 0
Track Volume                    : 0.00%
Image Width                     : 1152
Image Height                    : 480
Graphics Mode                   : srcCopy
Op Color                        : 0 0 0
Compressor ID                   : avc1
Source Image Width              : 852
Source Image Height             : 480
X Resolution                    : 72
Y Resolution                    : 72
Bit Depth                       : 24
Pixel Aspect Ratio              : 96:71
Video Frame Rate                : 25
Matrix Structure                : 1 0 0 0 1 0 0 0 1
Media Header Version            : 0
Media Create Date               : 2022:05:05 07:25:10
Media Modify Date               : 2022:05:05 07:25:10
Media Time Scale                : 48000
Media Duration                  : 1:51:17
Media Language Code             : eng
Handler Description             : SoundHandler
Balance                         : 0
Audio Format                    : mp4a
Audio Channels                  : 2
Audio Bits Per Sample           : 16
Audio Sample Rate               : 48000
Handler Type                    : Metadata
Handler Vendor ID               : Apple
Title                           : 365 Days (2022) (WebRip)
Encoder                         : Lavf58.13.100
Image Size                      : 1152x480
Megapixels                      : 0.553
Avg Bitrate                     : 979 kbps
Rotation                        : 0

With this method, we can extract the entire metadata of our video file.

Leave a Reply

Your email address will not be published. Required fields are marked *