Get Video Keyframe Interval (ffprobe)



Published: 2017-07-19 12:15:31 +0000
Categories: BASH,

Language

BASH

Description

The command will output where keyframes exist within the input video. Useful to know when trying to segment for HLS etc, or troubleshoot playback issues

Snippet

# Print Timestamps
ffprobe -show_frames -select_streams v:0 -print_format csv $VIDEO_FILE 2> /dev/null | awk -F ',' '{ if ($4 > 0) print $6; }'

# Calculate the durations between keyframes and their distribution
ffprobe -show_frames -select_streams v:0 -print_format csv $VIDEO_FILE 2> /dev/null \
    | awk -F ',' '{ if ($4 > 0) print $6; }' \
    | awk 'NR>1{print $1-p} {p=$1}'\
    | sort | uniq -c

# Getting Keyframe positions by frame number
ffprobe -show_frames -select_streams v:0 -print_format csv $VIDEO_FILE 2> /dev/null | awk -F ',' '{ if ($4 > 0) print NR; }'

# Calculating the Keyframe interval by framecount
ffprobe -show_frames -select_streams v:0 -print_format csv $VIDEO_FILE 2> /dev/null \
    | awk -F ',' '{ if ($4 > 0) print NR; }'  \
    | awk 'NR>1{print $1-p} {p=$1}'\
    | sort | uniq -c

# Getting the average framerate
ffprobe -v 0 -of compact=p=0 -select_streams 0 -show_entries stream=r_frame_rate $VIDEO_FILE | grep -o -P "[0-9,/]+" | bc

Keywords

ffprobe, media, framerate, i-frame, keyframe, interval, statistics,

Latest Posts


Copyright © 2022 Ben Tasker | Sitemap | Privacy Policy
Available at snippets.bentasker.co.uk, http://phecoopwm6x7azx26ctuqcp6673bbqkrqfeoiz2wwk36sady5tqbdpqd.onion and http://snippets.bentasker.i2p
hit counter