Export Frame Entropy to CSV with FFmpeg

This guide explains how to calculate frame-by-frame visual entropy in a video and export those metrics directly into a CSV file using FFmpeg and FFprobe. By chaining the entropy multimedia filter with FFprobe's structured output formatting, you can generate per-frame complexity measurements for luminance and chrominance channels for video analysis, research, or machine learning pipelines.

The Standard FFprobe Command

The most direct way to generate a clean CSV file containing per-frame entropy values is using ffprobe with the lavfi (Libavfilter) virtual input device.

Run the following command in your terminal:

ffprobe -v error -f lavfi -i "movie=input.mp4,entropy=mode=normal" \
-show_entries frame=pkt_pts_time:frame_tags=lavfi.entropy.entropy.normal.Y \
-of csv=p=0 > entropy.csv

How the Command Works

  • -v error: Suppresses non-essential log outputs, preventing debugging logs from polluting your terminal or file redirects.
  • -f lavfi: Directs FFprobe to read from the Libavfilter virtual input device rather than demuxing the file directly.
  • -i "movie=input.mp4,entropy=mode=normal": Loads the source file (input.mp4) through the movie source filter and passes it through the entropy filter. The mode=normal parameter calculates standard Shannon entropy across pixel intensities.
  • -show_entries: Limits the output to only the necessary metadata.
    • frame=pkt_pts_time: Includes the presentation timestamp of each frame.
    • frame_tags=lavfi.entropy.entropy.normal.Y: Extracts the calculated entropy metric for the Y (luminance) channel.
  • -of csv=p=0: Sets the output format to CSV. The p=0 flag removes the default prefixes (such as frame, or tag:), yielding clean, comma-separated values.
  • > entropy.csv: Redirects standard output to a CSV file.

Exporting All Color Channels (Y, U, and V)

To export the entropy values for the luminance channel alongside both chrominance channels, expand the frame_tags field:

ffprobe -v error -f lavfi -i "movie=input.mp4,entropy=mode=normal" \
-show_entries frame=pkt_pts_time:frame_tags=lavfi.entropy.entropy.normal.Y,lavfi.entropy.entropy.normal.U,lavfi.entropy.entropy.normal.V \
-of csv=p=0 > entropy_all_channels.csv

Adding a CSV Header Row

Because -of csv=p=0 removes all metadata labels, the resulting CSV file will contain raw values without a header. You can add a header manually by prepending it before running the command:

echo "timestamp,entropy_y,entropy_u,entropy_v" > entropy_final.csv
ffprobe -v error -f lavfi -i "movie=input.mp4,entropy=mode=normal" \
-show_entries frame=pkt_pts_time:frame_tags=lavfi.entropy.entropy.normal.Y,lavfi.entropy.entropy.normal.U,lavfi.entropy.entropy.normal.V \
-of csv=p=0 >> entropy_final.csv

Alternative: Using the FFmpeg Metadata Filter

If you must use ffmpeg rather than ffprobe, use the metadata filter to print values directly to a text file:

ffmpeg -i input.mp4 -vf "entropy=mode=normal,metadata=print:key=lavfi.entropy.entropy.normal.Y:file=entropy_raw.txt" -f null -

This generates a structured text file containing lines in the format lavfi.entropy.entropy.normal.Y=value, which can be converted to standard CSV using basic text processing tools such as awk, sed, or Python.