How to Configure FFprobe to Write XML Output

This guide explains how to configure FFprobe to generate structured XML output for media file analysis and automation workflows. FFprobe includes a built-in writer system that can serialize container and stream metadata into multiple formats, including XML. By using the -print_format (or -of) flag along with output redirection, you can extract comprehensive audio and video details into standard XML files suitable for automated ingestion pipelines, databases, or archival systems.

The Basic XML Output Command

FFprobe uses the -print_format option (aliased as -of) to specify the output serialization type. To print metadata in XML format to the console, set the writer to xml:

ffprobe -v quiet -print_format xml -show_format -show_streams input.mp4

In this command:

  • -v quiet: Suppresses redundant FFmpeg header logs, banner text, and warnings so that only the XML payload is generated.
  • -print_format xml (or -of xml): Tells FFprobe to output the metadata structured as XML.
  • -show_format: Gathers container-level metadata (duration, bitrate, tags).
  • -show_streams: Gathers stream-level metadata (codecs, resolutions, frame rates, audio channels).

Saving XML Output Directly to a File

FFprobe prints its structured output to standard output (stdout). To save this data to an XML file, redirect the output using the shell redirection operator (>):

ffprobe -v quiet -print_format xml -show_format -show_streams input.mp4 > output.xml

This ensures the generated file contains pure XML without extraneous command-line logs.

Customizing the XML Structure

FFprobe's XML writer supports specific options to control the schema definition and qualification of tags. You can pass options by appending =key=value pairs to the xml argument, separated by colons (:).

1. Fully Qualified XML (fully_qualified or q)

By default, FFprobe writes compact tags without namespaces. Setting fully_qualified=1 (or q=1) generates complete, namespace-prefixed tags based on FFprobe's schema definitions:

ffprobe -v quiet -print_format xml=q=1 -show_format input.mp4 > output.xml

2. Include XML Schema Definition (xsd or x)

To make the XML output self-validating against the FFprobe XML Schema Definition (XSD), enable the xsd flag:

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

When enabled, the root element will include the xmlns:xsi and xsi:noNamespaceSchemaLocation attributes pointing to the official FFprobe schema specification.

Practical Examples

Extract Container and Stream Details

To produce a well-formed XML file containing all stream specifications and format information:

ffprobe -v error -of xml=q=1 -show_entries stream:format input.mkv > metadata.xml

Extract Frame-Level Data

To analyze every video or audio frame and save the timecodes, frame types (I, P, B), and sizes into XML:

ffprobe -v error -of xml -show_frames -select_streams v:0 input.mp4 > frames.xml

Extract Packet Information

To log individual packet sizes and timestamps into XML:

ffprobe -v error -of xml -show_packets -select_streams a:0 input.mp4 > audio_packets.xml