ffprobe is a tool within the FFmpeg package used for analyzing metadata of audio and video files to obtain detailed information about the file content, including duration. ffprobe determines the duration of media files by reading the container information of the file. Specifically, it inspects the metadata tags within the file, which describe the total duration of the audio or video streams. In some cases, if the container lacks explicit duration metadata, ffprobe may also inspect individual audio or video frames to estimate the total duration.
To determine the duration of a file using ffprobe, you can run a command similar to the following:
bashffprobe -v error -show_entries format=duration -of default=noprint_wrappers=1:nokey=1 input_file
In this command:
-v errorindicates that only error messages are output, which helps filter out non-critical information.-show_entries format=durationspecifies that only the duration information from the format entries is displayed.-of default=noprint_wrappers=1:nokey=1defines the output format, wherenoprint_wrappers=1prevents printing the wrappers around the output, andnokey=1means not to display key names, directly outputting the values.
After executing this command, ffprobe outputs the total duration of the file in seconds. This value is typically represented as a floating-point number, providing millisecond-level precision.
For example, suppose I have a video file named example.mp4 and I want to determine its duration. I would run the following command in the terminal or command line:
bashffprobe -v error -show_entries format=duration -of default=noprint_wrappers=1:nokey=1 example.mp4
If the duration is 120.321 seconds, ffprobe outputs:
shell120.321
This allows me to quickly and accurately determine the duration of the example.mp4 file. It is particularly useful for writing scripts to process large numbers of media files or for determining progress and estimating time during video encoding and transcoding operations.