Skip to content

Instantly share code, notes, and snippets.

@shouya
Created June 5, 2024 04:32
Show Gist options
  • Save shouya/664762d5fcdd9c66c64f1f6adc290f87 to your computer and use it in GitHub Desktop.
Save shouya/664762d5fcdd9c66c64f1f6adc290f87 to your computer and use it in GitHub Desktop.
Print group of pictures (GoP) structure of a video file
#!/bin/bash
# This script prints the gops structure of the video file in terms of frames between keyframes.
#
# Usage: $0 [--full] <video file>
#
full() {
ffprobe -hide_banner -loglevel error -show_frames "$@" | \
grep -oP 'pict_type=\K.' | \
awk '/I/ {if(a)printf " (%d)\nI", a; a=1} /[PB]/ {a++; printf $0}'
}
simple() {
ffprobe -hide_banner -loglevel error -show_frames "$@" | \
grep -oP 'pict_type=\K.' | \
awk '/I/ {if(a)print a; a=1} /[PB]/ {a++} END {print a}'
}
if [[ "$1" == "--full" ]]; then
shift
full "$@"
else
simple "$@"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment