Export FFprobe Results to JSON Format
This guide provides a straightforward tutorial on how to use FFprobe, the media analysis tool included with FFmpeg, to extract video and audio metadata and export the results directly into JSON format. Generating JSON output is highly useful for developers and system administrators who need to parse media information programmatically in scripts and applications.
To export FFprobe results in JSON, you use the
-print_format option (which can be abbreviated as
-of) followed by json.
Here is the standard command to output the metadata of a media file in JSON format to your terminal:
ffprobe -v quiet -print_format json -show_format -show_streams input.mp4Command Breakdown
-v quiet: Suppresses the default FFmpeg banner and log outputs, ensuring that only the clean JSON data is returned.-print_format json(or-of json): Tells FFprobe to format the output as standard JSON.-show_format: Instructs FFprobe to include container-level information, such as duration, bit rate, size, and format tags.-show_streams: Instructs FFprobe to include detailed information about each stream inside the file, such as video codecs, resolution, frame rate, and audio channels.input.mp4: The path to your input media file.
Saving the Output to a JSON File
To save the JSON output directly to a file rather than printing it to
your terminal screen, redirect the output using the >
operator in your terminal:
ffprobe -v quiet -print_format json -show_format -show_streams input.mp4 > output.jsonFormatting the JSON Output
By default, FFprobe prints the JSON in a compact format. If you want
the JSON to be “pretty-printed” with indentation and newlines for easier
manual reading, add :compact=0 to the print format
option:
ffprobe -v quiet -print_format json=compact=0 -show_format -show_streams input.mp4