How to Extract Video Metadata as XML Using FFmpeg

Extracting video metadata is a crucial step for media cataloging, quality control, and automated post-production workflows. This article provides a quick, step-by-step guide on how to use ffprobe—the metadata analysis tool bundled with FFmpeg—to extract comprehensive video metadata and save it directly as an XML file. You will learn the exact command structure, what each parameter does, and how to customize the output for your needs.

To extract video metadata in XML format, you must use ffprobe, which is automatically installed alongside FFmpeg.

The FFmpeg Command

Run the following command in your terminal to extract the metadata and save it to an XML file:

ffprobe -v quiet -print_format xml=q=1:x=1 -show_format -show_streams input.mp4 > metadata.xml

Replace input.mp4 with the path to your video file, and metadata.xml with your desired output filename.

Parameter Breakdown

  • ffprobe: Calls the stream analyzer tool.
  • -v quiet: Suppresses the standard FFmpeg banner and log messages so that only the XML payload is written to the output.
  • -print_format xml=q=1:x=1: Specifies XML as the output format. The arguments q=1 (qualify) and x=1 (xml schema) ensure the output is well-formed, fully compliant XML with appropriate tags and namespaces.
  • -show_format: Instructs the tool to dump container-level metadata, such as file format, duration, bit rate, and size.
  • -show_streams: Instructs the tool to dump stream-level metadata, providing details on individual video, audio, and subtitle tracks (e.g., codecs, width, height, aspect ratio, frame rate).
  • > metadata.xml: Redirects the command-line output from the terminal screen into a physical .xml file.

Customizing the XML Output

If you need more specific metadata, you can append additional flags to the command:

  • Show Chapters: Add -show_chapters to include chapter marker details.
  • Show Programs: Add -show_programs if your video file contains program-specific streams (common in transport streams like .TS).
  • Show Individual Packets: Add -show_packets if you need deep, frame-by-frame analysis (note: this will result in a very large XML file).

By utilizing these arguments, you can generate clean, structured XML documents ready for parsing by external scripts or database ingestion tools.