Calculate the total duration (in hours) of all MP4 files in the current directory and its subdirectories.
Requires the ffprobe utility (part of FFmpeg) to be installed.
find . \
-type f \
-iname "*.mp4" \
-exec ffprobe \
-v quiet \
-of csv=p=0 \
-show_entries \
format=duration {} \; \
| paste -sd+ - \
| bc -l <<< "scale=2; ($(< /dev/stdin)) / 3600"Breakdown:
-
find . -type f -iname "*.mp4": Finds all MP4 files (case-insensitive) recursively. -
-exec ffprobe ...: Extracts the duration (in seconds) for each file. -
| paste -sd+ -: Joins all the durations into a single string (e.g., 120.5+34.9+...). -
| bc -l ...: Uses the bc calculator (with math library enabled) to sum the total seconds and divide the result by 3600, presenting the final total in hours with 2 decimal places.