$ find . -print0 | xargs -0 -P 40 -n 1 sh -c 'ffmpeg -i "$1" 2>&1 | grep "Duration:" | cut -d " " -f 4 | sed "s/.$//" | tr "." ":"' - | awk -F ':' '{ sum1+=$1; sum2+=$2; sum3+=$3; sum4+=$4; if (sum4 > 100) { sum3+=1; sum4=0 }; if (sum3 > 60) { sum2+=1; sum3=0 }; if (sum2 > 60) { sum1+=1; sum2=0 } if (NR % 100 == 0) { printf "%.0f:%.0f:%.0f.%.0f\n", sum1, sum2, sum3, sum4 } } END { printf "%.0f:%.0f:%.0f.%.0f\n", sum1, sum2, sum3, sum4 }' ExplanationFirst the The The A subshell is executed by
Awk is a "pattern-directed scanning and processing language", often used in shell scripts for simple text processing. Here we use it to split the time elements into 4 variables and add them up. If one of the variables overflows (e.g. not more than 60 seconds per minute), the next one is incremented and that variable is reset to 0. Every 100 lines, the current values are printed, and at the end, they are printed again. LimitationsRequires |