Friday, May 3, 2024
13
rated 0 times [  13] [ 0]  / answers: 1 / hits: 4799  / 3 Years ago, fri, june 18, 2021, 8:26:29

Is there a script(bash, python etc.) that outputs the total duration time of all video files in a Directory(recursively) ?



For e.g on executing the following :



script mypath


it gives x minutes/hours .


More From » command-line

 Answers
6

First install mediainfo with:



sudo apt-get install mediainfo


You can now use the following oneliner to get the total video time of a directory:



find . -type f -exec mediainfo --Inform="General;%Duration%" "{}" ; 2>/dev/null | awk '{s+=$1/1000} END {h=s/3600; s=s%3600; printf "%.2d:%.2d
", int(h), int(s/60)}'


The find command will call mediainfo for every files recursively and get the video duration in ms.



Then the awk part will sum those values and return the total time in the HH:MM format.






Update: avprobe is indeed faster than mediainfo (thanks @souravc)



For better results please use the command below instead (you'll need to sudo apt-get install libav-tools first)



find . -type f -exec avprobe -v quiet -show_format_entry duration "{}" ; | awk '{s+=$1} END {h=s/3600; s=s%3600; printf "%.2d:%.2d
", int(h), int(s/60)}'

[#20813] Saturday, June 19, 2021, 3 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
calcur

Total Points: 189
Total Questions: 80
Total Answers: 95

Location: Burkina Faso
Member since Thu, Dec 15, 2022
1 Year ago
;