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.mp4

Command Breakdown

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