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:

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.