FFmpeg Flat Metadata Extraction
Extracting metadata from video files is a common task for developers
and video professionals, and FFmpeg’s companion tool,
ffprobe, makes this process highly efficient. This article
provides a direct, step-by-step guide on how to write and run an FFmpeg
command to extract video metadata in a clean, flat key-value format that
is easy to read and parse.
To extract video metadata in a flat format, you must use the
ffprobe command-line utility with the
-print_format flat writer option.
The Standard Command
Run the following command in your terminal:
ffprobe -v error -show_format -show_streams -print_format flat input.mp4Command Breakdown
ffprobe: The command-line tool used to analyze multimedia streams and gather metadata.-v error: This flag suppresses unnecessary log output and warnings, ensuring that only the actual metadata is returned.-show_format: Instructs the tool to show container-level information, such as duration, file size, bit rate, and format name.-show_streams: Instructs the tool to show detailed information about each stream inside the container, including video resolution, codec, frame rate, and audio channels.-print_format flat: The key argument that tellsffprobeto format the output as a flat list of key-value pairs (e.g.,streams.stream.0.codec_name="h264").input.mp4: Replace this with the path to your video file.
Example Output
When you run this command, you will get output structured like this:
streams.stream.0.index=0
streams.stream.0.codec_name="h264"
streams.stream.0.codec_long_name="H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10"
streams.stream.0.profile="High"
streams.stream.0.codec_type="video"
streams.stream.0.width=1920
streams.stream.0.height=1080
format.filename="input.mp4"
format.nb_streams=2
format.format_name="mov,mp4,m4a,3gp,3g2,mj2"
format.duration="124.500000"
format.size="15243980"
Saving the Output to a File
If you want to export this flat metadata directly into a text file
for scripting or documentation purposes, redirect the output using the
> operator:
ffprobe -v error -show_format -show_streams -print_format flat input.mp4 > metadata.txt