Extract Video Metadata in Flat Format with FFmpeg
This article explains how to use FFmpeg’s companion tool,
ffprobe, to extract video metadata and output it in a flat,
easy-to-parse format. By using the flat print format, you can easily
read video properties like duration, resolution, and codecs directly in
command-line scripts.
To extract video metadata in a flat format, you need to use the
ffprobe command-line utility, which is installed
automatically alongside FFmpeg.
Run the following command in your terminal:
ffprobe -v error -show_format -show_streams -print_format flat input.mp4Parameter Breakdown
ffprobe: The command-line tool used to analyze multimedia streams.-v error: This option suppresses unnecessary log details and banner information, ensuring that only the metadata (and any critical errors) are printed to the console.-show_format: Instructs the tool to output container-level metadata, such as file size, duration, bit rate, and format name.-show_streams: Instructs the tool to output stream-level details, including video resolution, frame rate, audio channels, and codec information.-print_format flat(or-of flat): This is the key argument. It formats the output as a flat list of key-value pairs (e.g.,streams.stream.0.codec_name="h264"), which is ideal for grep filtering or bash scripting.input.mp4: Replace this with the path to your video file.
Saving the Output to a File
If you want to save the flat metadata to a text file for later use,
redirect the output using the > operator:
ffprobe -v error -show_format -show_streams -print_format flat input.mp4 > metadata.txtFiltering Specific Metadata
The flat format makes it easy to filter for specific properties using
standard command-line tools like grep. For example, to find
only the width and height of the video, run:
ffprobe -v error -show_streams -print_format flat input.mp4 | grep -E 'width|height'