Skip to content

Instantly share code, notes, and snippets.

@ctrlcctrlv
Created September 9, 2022 21:34
Show Gist options
  • Select an option

  • Save ctrlcctrlv/ee6baeeccd7829c7ce1845812abadbb9 to your computer and use it in GitHub Desktop.

Select an option

Save ctrlcctrlv/ee6baeeccd7829c7ce1845812abadbb9 to your computer and use it in GitHub Desktop.
Get frame count for arbitrary file with ffmpeg / bash only
#!/usr/bin/env bash
INFILE="$1"
ffmpeg_length() {
export $(ffprobe -show_entries 'format=duration:stream=r_frame_rate' -of 'csv=nk=0:p=0' -v quiet "$1" | grep -v '/0$')
test ! -z "$DEBUG" && >&2 echo $duration $r_frame_rate
bc -l << EOF
r=$r_frame_rate
scale=0
(r*$duration)/1
EOF
}
ffmpeg_length "$INFILE"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment