Extract Packet Timestamps and Sizes Using FFprobe

This guide demonstrates how to use FFprobe, a versatile multimedia stream analyzer included with the FFmpeg suite, to extract granular packet data from audio and video files. By targeting packet-level streams, you can inspect individual packet sizes and decoding or presentation timestamps directly from the command line or export them into formats like CSV and JSON for downstream processing.

The Basic Command

To read packet-level data, use the -show_packets flag combined with -show_entries to limit the output specifically to timestamp and size fields:

ffprobe -v error -show_entries packet=pts_time,dts_time,size -of default=noprint_wrappers=1 input.mp4

Key Parameters Explained

  • -v error: Suppresses diagnostic logs and banner information, ensuring only the requested data is printed.
  • -select_streams v:0 (Optional): Filters output to a specific stream (e.g., v:0 for the first video stream, a:0 for the first audio stream).
  • -show_entries packet=pts_time,dts_time,size: Specifies the exact fields to retrieve:
    • pts_time: Presentation Time Stamp in seconds (when the frame is displayed).
    • dts_time: Decoding Time Stamp in seconds (when the frame is decoded).
    • size: The size of the packet in bytes.
  • -of: Sets the output format (e.g., csv, json, flat, or default).

Output Formats

1. Exporting as CSV

To export clean, comma-separated values ideal for spreadsheets or statistical analysis:

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

Adding p=0 removes the packet, prefix from every line, producing clean pts_time,dts_time,size rows.

2. Exporting as JSON

To parse packet metadata programmatically with Python or JavaScript:

ffprobe -v error -select_streams v:0 \
  -show_entries packet=pts_time,dts_time,size \
  -of json input.mp4 > packets.json

Retrieving Integer Timestamps Instead of Time in Seconds

If your analysis requires exact integer ticks based on the stream's timebase rather than converted seconds, substitute pts_time and dts_time with pts and dts:

ffprobe -v error -select_streams v:0 \
  -show_entries packet=pts,dts,size \
  -of csv=p=0 input.mp4