How to Export ffprobe Results to CSV

Extracting multimedia metadata into a spreadsheet-friendly format is a common task when analyzing video and audio files in bulk. This guide demonstrates how to use ffprobe—the multimedia stream analyzer included with FFmpeg—to output stream, format, packet, or frame data directly into CSV (Comma-Separated Values) format. By utilizing the built-in -print_format csv option and standard command-line redirection, you can generate clean CSV files ready for import into tools like Microsoft Excel, Google Sheets, or data analysis pipelines.


The Basic Command

To export metadata to a CSV file, specify the CSV output format using the -print_format csv (or -of csv) argument and redirect standard output to a .csv file using the > operator.

ffprobe -v error -show_format -show_streams -print_format csv input.mp4 > output.csv
  • -v error: Suppresses diagnostic and banner messages so only actual errors and output data appear in the final file.
  • -show_format: Gathers container-level metadata (such as overall duration, bit rate, and tags).
  • -show_streams: Gathers information for each audio, video, or subtitle stream.
  • -print_format csv: Tells ffprobe to format the selected output as CSV.

Customizing CSV Output Options

The csv writer in ffprobe accepts sub-parameters to control formatting:

  • p=0 or print_section=0: Disables the leading section identifier (such as stream, or format,) at the beginning of each row.
  • s=x or separator=x: Changes the delimiter character (default is ,).
  • nk=1 or nokey=1: Prints only the values without field keys (only applies when printing flat sections).

To pass sub-parameters, use the syntax -print_format csv=key=value:key=value:

ffprobe -v error -show_entries stream=index,codec_name,width,height -print_format csv=p=0 input.mp4 > streams.csv

Common Use Cases

1. Export Specific Stream Attributes

To export only selected attributes (such as codec name, dimensions, and frame rate) instead of all data fields:

ffprobe -v error -select_streams v:0 \
  -show_entries stream=codec_name,width,height,r_frame_rate,bit_rate \
  -print_format csv=p=0 input.mp4 > video_info.csv
  • -select_streams v:0: Limits analysis to the primary video stream.

2. Export Frame-by-Frame Data

To analyze every frame in a video file (useful for detecting keyframes or variable frame rates):

ffprobe -v error -select_streams v:0 \
  -show_frames \
  -show_entries frame=pkt_pts_time,pict_type,key_frame \
  -print_format csv=p=0 input.mp4 > frames.csv

3. Export Packet Information

To inspect individual packet presentation timestamps (PTS) and sizes:

ffprobe -v error -select_streams v:0 \
  -show_packets \
  -show_entries packet=pts_time,dts_time,size,flags \
  -print_format csv=p=0 input.mp4 > packets.csv

Batch Processing Multiple Files

To export data from multiple video files into a single CSV using a Bash loop:

echo "file,codec,width,height,duration" > batch_report.csv
for f in *.mp4; do
  ffprobe -v error -select_streams v:0 \
    -show_entries stream=codec_name,width,height,duration \
    -print_format csv=p=0 "$f" | sed "s/^/$f,/" >> batch_report.csv
done

This command loops through all .mp4 files in the directory, appends the filename as the first column, and writes the results to batch_report.csv.