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

Remotely backing up PFsense Configuration (BASH)
FFMPEG: Converting RMVB to X264 MP4 (BASH)
Recursively print table (print_r equivalent) (LUA)
Bulk Delete Comments from (Self-Hosted) JIRA Issues (Misc)
Add a static entry to the ARP table (BASH)
SSL Cipher Hex codes to Human Readable Names (Misc)
Convert Ascii to Binary (BASH)
Intercepting Outbound DNS Queries (BASH)
Handle Google Verification files within NGinx Configuration (NGinx)
Getting WhatsApp Rich Snippet Previews Working (Misc)

Copyright © 2018 Ben Tasker | Sitemap | Privacy Policy
Available at snippets.bentasker.co.uk and snippets.6zdgh5a5e6zpchdz.onion