Last active
August 29, 2015 14:23
-
-
Save MattSkala/7ba0ed505d05fde25633 to your computer and use it in GitHub Desktop.
Count total length of videos in current dir
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/sh | |
if [ -z "$1" ]; then | |
echo "Missing argument: dir" | |
exit | |
fi | |
if [ -z "$2" ]; then | |
echo "Missing argument: format" | |
exit | |
fi | |
DIR="$1" | |
FORMAT="$2" | |
total=0 | |
IFS=$'\n' | |
for file in $(find $DIR -name "*.$FORMAT"); do | |
length=$(ffmpeg -i "$file" 2>&1 | grep "Duration" | cut -d ' ' -f 4 | sed s/,// | awk '{ split($1, A, ":"); print 3600*A[1] + 60*A[2] + A[3] }') | |
total=$(echo "$total + $length" | bc) | |
echo "$file $length" | |
done | |
echo $total |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment