Skip to content

Instantly share code, notes, and snippets.

@afriza
Created April 10, 2022 11:51
Show Gist options
  • Save afriza/ad45040bf620df0f8b6968b89b3ede1a to your computer and use it in GitHub Desktop.
Save afriza/ad45040bf620df0f8b6968b89b3ede1a to your computer and use it in GitHub Desktop.
Get video duration using ffprobe from ffmpeg suite
#! /bin/sh
DIR=${1:-"."}
find "$DIR" -type f -iname "*.mp4" -print0 | sort -z | xargs -r0 -I{} duration.sh "{}"
#! /bin/sh
FILE=$1
if [ -z "$FILE" ]; then
echo file paramater is required.
exit 1
fi
# remove -sexagesimal to get duration in seconds
#DURATION=$(ffprobe -i "$FILE" -show_entries format=duration -v fatal -of csv=p=0)
DURATION=$(ffprobe -i "$FILE" -show_entries format=duration -v fatal -of csv=p=0 -sexagesimal)
echo "$DURATION $FILE"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment