To address your underlying requirement, you should iterate across the files, passing them one at a time to ffprobe. This will allow you to get the durations in hours, minutes, seconds.
for mp4 in *.mp4
do
echo "Processing $mp4"
ffprobe "$mp4" 2>&1 | awk '/Duration/ {print $2}'
done
Looking around somewhat more carefully, it's possible to get ffprobe to deliver seconds directly
for mp4 in *.mp4
do
echo "Processing $mp4"
ffprobe -v error -show_entries format=duration -of default=noprint_wrappers=1:nokey=1 "$mp4"
done
Having done that, it's not a giant leap to add them all together
for mp4 in *.mp4
do
echo "Processing $mp4"
ffprobe -v error -show_entries format=duration -of default=noprint_wrappers=1:nokey=1 "$mp4"
done |
awk -F '
{ sec += $1 } # Total time (seconds)
END {
h = int(sec / 3600); # Hours
m = int((sec - (h*3600)) / 60); # Minutes
s = sec - (h*3600) - (m*60); # Seconds
printf "%d (%d hour, %d min, %d sec)\n", sec, h, m, s # Print the result
}
'
Finally, to process files not only in the current directory but also in all subdirectories, modify the outer loop. This next step uses a bash feature that allows ** to match subdirectories
shopt -s globstar # Enable extended globbing
for mp4 in **/*.mp4
do
echo "Processing $mp4"
ffprobe -v error -show_entries format=duration -of default=noprint_wrappers=1:nokey=1 "$mp4"
done |
# Continue as before...