How to get video duration with ffmpeg


ffmpeg-logo

Method 1:

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

Example:

[root@tutorialspots ~]# ffprobe -v error -show_entries format=duration -of default=noprint_wrappers=1:nokey=1 "/home/tutorialspots/tutorialspots.mp4"
38.823767

See this method with PHP:
PHP: How to fix error shell_exec can’t run some command on Linux

Method 2:

ffmpeg -i "INPUT.mp4" 2>&1 | grep Duration | awk '{print $2}' | tr -d ,

Example:

[root@tutorialspots ~]# ffmpeg -i "/tutorialspots/tutorialspots.mp4" 2>&1 | grep Duration | awk '{print $2}' | tr -d ,
00:00:38.82

Method 3:

ffmpeg -i "INPUT.mp4" 2>&1 | grep Duration | awk '{print $2}' | tr -d , | awk -F ':' '{print ($3+$2*60+$1*3600)}'

Example:

[root@tutorialspots ~]# ffmpeg -i "/tutorialspots/tutorialspots.mp4" 2>&1 | grep Duration | awk '{print $2}' | tr -d , | awk -F ':' '{print ($3+$2*60+$1*3600)}'
38.82

1 Comment

Leave a Reply