Reputation: 11
I used to get my result in windows by just searching *.mp4 and select all files. The sum of duration would show in side panels details. I want to find the same things inside MAC recursively. This is the script I wrote in bash. Tell me what I am doing wrong?
#!/bin/bash
sum=0
find . -type f -name "*.mp4" | while read line; do
duration=`mdls -name kMDItemDurationSeconds "$line" | cut -d "=" -f 2`
sum=$(echo "$duration + $sum"|bc)
all=$sum
done
echo $all
Upvotes: 0
Views: 335
Reputation: 11
#!/bin/bash
sum=0
while read line; do
duration=$(mdls -name kMDItemDurationSeconds "$line" | cut -d "=" -f 2)
sum=$(echo "$duration+$sum"|bc)
done <<< "$(find . -type f -name "*.mp4")"
h=$(bc <<< "$sum/3600")
m=$(bc <<< "($sum%3600)/60")
s=$(bc <<< "$sum%60")
printf "%02d:%02d:%05.2f\n" $h $m $s
My solution, not perfect yet.
Upvotes: 1