Extract Video Metadata to XML Using FFmpeg
This article provides a quick and direct guide on how to extract
video metadata and export it into XML format. By utilizing
ffprobe, a powerful command-line tool bundled with FFmpeg,
you can gather detailed information about video streams, audio tracks,
and container formats, and save it directly into an XML file for easy
parsing and integration.
To extract metadata from a video file in XML format, you should use
ffprobe rather than the main ffmpeg command.
ffprobe is specifically designed to analyze media files and
gather format and stream information.
The Basic Command
Open your terminal or command prompt and run the following command:
ffprobe -v quiet -print_format xml -show_format -show_streams input.mp4 > metadata.xmlCommand Breakdown
ffprobe: Invokes the media analyzer tool.-v quiet: Suppresses the default banner and log messages, ensuring that only the raw metadata is captured in the output.-print_format xml: Instructs the tool to format the output as XML.-show_format: Extracts container-level metadata (such as duration, file size, bit rate, and format tags).-show_streams: Extracts details for every stream inside the container (including video resolution, frame rate, audio codecs, and sample rates).input.mp4: Replace this with the path to your source video file.> metadata.xml: Redirects the command output from the console screen into a file namedmetadata.xml.
Advanced XML Formatting Options
You can customize the structure of the generated XML by adding
specific parameters to the -print_format argument:
1. Fully Qualified XML
To include the official schema definition in your XML header, add
fully_qualified=1:
ffprobe -v quiet -print_format xml=fully_qualified=1 -show_format -show_streams input.mp4 > metadata.xml2. Grouped Elements
To wrap similar elements in a parent tag (such as grouping all
streams inside a <streams> tag), add
list_of_groups=1 (this is often the default behavior but
can be explicitly set):
ffprobe -v quiet -print_format xml=q=1:g=1 -show_format -show_streams input.mp4 > metadata.xmlAdding Chapter Information
If your video file contains chapters and you want to include them in
the XML export, add the -show_chapters flag to your
command:
ffprobe -v quiet -print_format xml -show_format -show_streams -show_chapters input.mp4 > metadata.xml