I use a GoPro Max 360-degree camera in my annual #StillStanding project. This has given me plenty of opportunities to work with GoPro files and explore their structure. Previously, I wrote about the various files generated when recording. In this post, I’ll focus on how keyframes work in GoPro Max recordings and how to extract keyframe information.
What is a Keyframe?
A keyframe (also known as an I-frame) is a frame in a video that contains a complete image, unlike other frames (P-frames and B-frames) that only store changes from previous or future frames. Keyframes are essential for video editing, seeking, and compression.
Finding the Keyframe Rate
You keyframes in a GoPro Max video recording using ffprobe:
ffprobe -v error -select_streams v:0 -show_entries stream=r_frame_rate,nb_frames -of csv=p=0 input_file.mp4
To quickly calculate the frame rate as an integer, you can use:
ffprobe -v error -select_streams v:0 -show_entries stream=r_frame_rate,nb_frames -of csv=p=0 input_file.mp4 | awk -F '/' '{ printf("%.0f\n", $1/$2) }'
Extracting Keyframes
If you want to extract the positions of all keyframes, you can use ffprobe and some command-line tools. This SuperUser post explains the process. Here’s a one-liner to save the keyframe indices to a file:
ffprobe -select_streams v -show_frames \
-show_entries frame=pict_type \
-of csv video.mp4 \
| grep -n I | cut -d ':' -f 1 > keyframes.tsv
This will create a keyframes.tsv file listing the frame numbers of all keyframes in your video.
