Last active
July 22, 2023 17:13
-
-
Save vitalizzare/511b8d21c2780a188a0536909b005e3a to your computer and use it in GitHub Desktop.
Calculating the total duration of all the videos in a directory passed as the first parameter, ffprobe and awk needed
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/ven bash | |
# Finding the total duration of all the videos | |
# in the local Videos directory by default | |
# or in the directory passed as the first parameter | |
folder="${1:-$HOME/Videos}" | |
[ -d "$folder" ] || { echo "Folder not found: $folder" >&2; exit 1; } | |
echo "Calculating total video duration in $folder" >&2 | |
find "$folder" -type f | | |
while read f | |
do | |
if [[ $(file --brief --mime-type "$f") =~ "video/" ]]; then | |
ffprobe -v quiet -show_entries format=duration -of csv="p=0" "$f" | |
fi | |
done | | |
awk '{t+=$1} | |
END { | |
h=int(t/60/60); | |
m=int(t/60)%60; | |
s=t%60; | |
printf "%02i:%02i:%02.2f\n", h, m, s | |
}' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment