How to Use the Command 'mediainfo' (with examples)
The mediainfo
command is a powerful tool designed to extract and display metadata from video and audio files. Metadata includes information such as file format, duration, codec, bit rate, and more, which can be crucial for various tasks like media management, quality control, and troubleshooting. The tool is favored for its simplicity and effectiveness, making it ideal for both casual users and professionals who deal with multimedia content regularly.
Use Case 1: Display Metadata for a Given File in the Console
Code:
mediainfo file
Motivation:
Understanding the metadata of audio or video files can be critical for several reasons. Whether you’re verifying the technical specifications of a file, ensuring compatibility with specific media players, or simply managing a large collection of media, having quick access to this information is invaluable. The mediainfo file
command provides this needed information directly in your console, allowing for a quick inspection without needing an elaborate GUI application.
Explanation:
mediainfo
: This is the command that invokes the program MediaInfo.file
: This represents the file for which you want to display metadata. It can be an audio or video file, and by specifying its path, you tellmediainfo
what file to analyze.
Example Output:
General
Complete name : ExampleFile.mp4
Format : MPEG-4
Format profile : Base Media / Version 2
Codec ID : mp42 (isom/mp42)
File size : 600 KiB
Duration : 30 s 0 ms
Overall bit rate : 167 kb/s
Video
ID : 1
Format : AVC
Format/Info : Advanced Video Codec
Codec ID : avc1
Bit rate : 150 kb/s
Width : 720 pixels
Height : 480 pixels
Audio
ID : 2
Format : AAC LC
Bit rate : 16.1 kb/s
Use Case 2: Store the Output to a Given File Along with Displaying it in the Console
Code:
mediainfo --Logfile=out.txt file
Motivation:
There are situations where you might need to save the metadata output for documentation, further analysis, or sharing with team members. This could be particularly useful in professional settings like media production or IT support, where maintaining records of file specifications is necessary. By using the --Logfile
option, you can both view the data in real-time and store it for future use, enabling efficient workflow management and data retention.
Explanation:
mediainfo
: Initiates the MediaInfo command to start analyzing the file.--Logfile=out.txt
: This tells MediaInfo to save a copy of the metadata output into a file namedout.txt
. This file path can be changed to whatever suits your file-naming convention or directory setup.file
: The specific media file being analyzed for metadata, similar to the previous example.
Example Output:
Console (as seen on screen):
General
Complete name : ExampleFile.mp4
Format : MPEG-4
File size : 600 KiB
Contents of out.txt
:
General
Complete name : ExampleFile.mp4
Format : MPEG-4
File size : 600 KiB
Use Case 3: List Metadata Attributes That Can Be Extracted
Code:
mediainfo --Info-Parameters
Motivation:
Knowing the range of metadata attributes that can be extracted by MediaInfo allows users to understand the full potential of the tool. This can be especially beneficial for developers and analysts who need to programmatically extract specific pieces of information or who are looking to parse detailed data for integration into larger systems. By listing the available parameters, users can tailor the command usage to fit their specific needs, ensuring that they extract exactly what is necessary for their project or inquiry.
Explanation:
mediainfo
: The command itself that activates the MediaInfo software.--Info-Parameters
: This instructs MediaInfo to list all the metadata attributes it can extract, rather than analyzing a specific file. This option provides a comprehensive guide to users about the capabilities of the software regarding metadata extraction.
Example Output:
Format
Format_Profile
Codec_ID
Bit_Rate
Width
Height
Duration
Audio_Format
Sample_Rate
Channels
Bit_Depth
... (Continued with many more attribute options)
Conclusion:
The mediainfo
command is a versatile tool for anyone working with multimedia files. Whether you need a quick look at a file’s specifications, need to save the metadata for documentation, or want to explore the full range of metadata fields available, mediainfo
serves as a reliable and easy-to-use option. Its ability to deliver detailed insights efficiently makes it an essential tool in media management, ensuring that users can maintain control and understanding of their audio and video file libraries.