Skip to content

Instantly share code, notes, and snippets.

@spyesx
Created October 6, 2025 08:27
Show Gist options
  • Save spyesx/b662aa1afa2a852dc9ed3893270d3183 to your computer and use it in GitHub Desktop.
Save spyesx/b662aa1afa2a852dc9ed3893270d3183 to your computer and use it in GitHub Desktop.
MP4 total duration in hours

MP4 Total Duration in Hours

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:

  1. find . -type f -iname "*.mp4": Finds all MP4 files (case-insensitive) recursively.

  2. -exec ffprobe ...: Extracts the duration (in seconds) for each file.

  3. | paste -sd+ -: Joins all the durations into a single string (e.g., 120.5+34.9+...).

  4. | 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment