Skip to content

Instantly share code, notes, and snippets.

@MattSkala
Last active August 29, 2015 14:23
Show Gist options
  • Save MattSkala/7ba0ed505d05fde25633 to your computer and use it in GitHub Desktop.
Save MattSkala/7ba0ed505d05fde25633 to your computer and use it in GitHub Desktop.
Count total length of videos in current dir
#!/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