How to Get Duration of Video with FFmpeg

In this tutorial, we will learn how to get the duration of a video with FFmpeg using the ffprobe utility.

 

Getting the Duration

To get the duration with ffprobe, add the -show_entries flag and set its value to format=duration. This tells ffprobe to only return the duration.

 

ffprobe -i sample_5.mp4 -v quiet -show_entries format=duration -hide_banner
[FORMAT]
duration=924.688000
[/FORMAT]

 

If you just want to get the numerical duration of the video in seconds with no wrappers, set the output format to noprint_wrappers=1:nokey=1 using the -of flag like this:

 

ffprobe -i sample_5.mp4 -v quiet -show_entries format=duration -hide_banner -of default=noprint_wrappers=1:nokey=1
924.688000

 

To convert the above value into minutes and seconds, round it to an integer and divide it by 60.

 

924 / 60 = 15.4

 

Another way of formatting the output duration is to add the -sexagesimal flag to the ffprobe command. This will give you an H:MM:SS:MM format:

 

ffprobe -i sample_5.mp4 -v quiet -show_entries format=duration -hide_banner -of default=noprint_wrappers=1:nokey=1 -sexagesimal
0:15:24.688000
ffmpeg video