Get Video Duration with ffprobe in Seconds

This article explains how to use ffprobe, a powerful command-line tool packaged with FFmpeg, to extract the exact duration of a video file. You will learn the specific command-line arguments needed to output the duration as a clean, numeric value in seconds, stripping away all unnecessary metadata, headers, and wrappers.

To get the video duration as a plain number (in seconds, with decimal precision), run the following command in your terminal:

ffprobe -v error -show_entries format=duration -of default=noprint_wrappers=1:nokey=1 input.mp4

How the Command Works

Each flag in the command serves a specific purpose to ensure the output is clean and contains only the raw number:

  • -v error: This suppresses the default FFmpeg banner and log information, showing only the command's actual output or critical errors.
  • -show_entries format=duration: This tells ffprobe to query the container metadata and look specifically for the "duration" field.
  • -of default=noprint_wrappers=1:nokey=1: This configures the output format (writer).
    • noprint_wrappers=1 removes the default wrapper tags (like [FORMAT] and [/FORMAT]).
    • nokey=1 removes the duration= key name, leaving only the numeric value.
  • input.mp4: Replace this with the path to your video file.

Formatting as HH:MM:SS (Sexagesimal)

If you prefer a standard time format (Hours:Minutes:Seconds) instead of raw seconds, add the -sexagesimal flag to the command:

ffprobe -v error -show_entries format=duration -of default=noprint_wrappers=1:nokey=1 -sexagesimal input.mp4

This will return the duration in a clean 00:00:00.000000 format.