How to use the command 'mediainfo' (with examples)
The ‘mediainfo’ command is a powerful tool for displaying metadata from video and audio files. It provides detailed information about various attributes such as duration, format, codec, bitrate, and much more. This command can be useful for media file analysis or when you need to extract specific information from media files.
Use case 1: Display metadata for a given file in the console
Code:
mediainfo file
Motivation: Sometimes you may want to quickly view the metadata of a media file without the need to open it in a media player or an editor. This use case allows you to display the metadata directly in the console, providing a convenient way to access the information.
Explanation: In this use case, ‘mediainfo’ is the command to start the tool, and ‘file’ is the name or path of the media file. The command will parse and display the metadata of the specified file in the console.
Example output:
General
Complete name : example.mp4
Format : MPEG-4
Format profile : Base Media
Codec ID : isom
File size : 5.28 MiB
Duration : 1 min 30 s
Overall bit rate mode : Variable
Overall bit rate : 493 kb/s
Video
ID : 1
Format : AVC
Format/Info : Advanced Video Codec
Format profile : Baseline@L4.1
Format settings : 1 Ref Frames
Format settings, CABAC : No
Format settings, ReFrames : 1 frame
Bit rate : 365 kb/s
Width : 640 pixels
Height : 360 pixels
Display aspect ratio : 16:9
Frame rate mode : Constant
Frame rate : 29.970 (30000/1001) FPS
Color space : YUV
Chroma subsampling : 4:2:0
Bit depth : 8 bits
Scan type : Progressive
Bits/(Pixel*Frame) : 0.053
Stream size : 3.93 MiB (74%)
Use case 2: Store the output to a given file along with displaying in the console
Code:
mediainfo --Logfile=out.txt file
Motivation: Saving the output to a file can be useful when you need to document or analyze the metadata later. This use case allows you to store the metadata information in a specified file while simultaneously displaying it in the console.
Explanation: In this use case, ‘–Logfile=out.txt’ is an argument that tells ‘mediainfo’ to save the output to a file named ‘out.txt’ in addition to displaying it in the console. ‘file’ is the name or path of the media file.
Example output:
General
Complete name : example.mp4
Format : MPEG-4
...
...
-- Log file created at 2022-01-01 12:00:00 --
Use case 3: Display the list of metadata attributes that can be extracted
Code:
mediainfo --Info-Parameters
Motivation: Sometimes you may want to extract specific metadata information from media files, but you’re not sure which attributes are available. This use case allows you to get a comprehensive list of all available metadata attributes that can be extracted using the ‘mediainfo’ command.
Explanation: In this use case, ‘–Info-Parameters’ is an argument that tells ‘mediainfo’ to display a list of all available metadata attributes that can be extracted.
Example output:
General;Complete name\\
General;Format\\
General;Format profile\\
General;Codec ID\\
...
Conclusion:
The ‘mediainfo’ command is a great utility for extracting and displaying metadata from video and audio files. Whether you need to quickly view metadata in the console, save it to a file, or explore available attributes, ‘mediainfo’ provides flexibility and convenience. With its rich set of features, this command is a valuable tool for media analysis and information extraction.