How can I check keyframe interval of a video file?
all I can see in ffmpeg output is:
Metadata: metadatacreator : Yet Another Metadata Injector for FLV - Version 1.8 hasKeyframes : true hasVideo : true hasAudio : true hasMetadata : true canSeekToEnd : true datasize : 256600272 videosize : 210054362 audiosize : 45214634 lasttimestamp : 5347 lastkeyframetimestamp: 5347 lastkeyframelocation: 256649267 Duration: 01:29:07.24, start: 0.040000, bitrate: 383 kb/s Stream #0:0: Video: h264 (High), yuv420p, 720x304 [SAR 1:1 DAR 45:19], 312 kb/s, 25 tbr, 1k tbn, 50 tbc Stream #0:1: Audio: mp3, 44100 Hz, mono, s16p, 64 kb/s
Choosing a keyframe interval at the encoder level Wirecast is different as the interval is actually denoted in frames. So for a 30 FPS broadcast, setting the “key frame every” 60 frames would roughly give a keyframe interval of 2 seconds, as you have 30 frames every second.
Having a keyframe interval of 2 means that it takes at most 2 seconds for the viewers to catch up to a point where they can properly display the feed. We recommend a framerate of 25 Frames Per Second (FPS) and a keyframe interval of 2 seconds (or 50 frames).
We typically recommend a keyframe interval of 2 seconds. Please note that if you set the keyframe interval to 0 seconds in OBS Studio, this does not mean 0 seconds, it will instead instruct OBS to change the keyframe interval to “AUTO”. A Setting of 0 or AUTO is around 8 seconds.
Keyframes are points in the video where the entire frame is sent instead of just the differences from the previous frame. Having a keyframe interval of 2 means that it takes at most 2 seconds for the viewers to catch up to a point where they can properly display the feed. Okay Thanks.
If you're streaming to Twitch, I believe they still want you to use a 2 second keyframe interval. If you're just recording, you can use whatever you want. I typically go for a 5 second keyframe interval on my recordings.
The answer to this is part of the reason Twitch is requiring a set interval and recommending 2. The Automatic setting 0 keyframe intervals is a default setting of 250 frames (about 8.5 seconds) before it updates with a full frame image. Twitch wants to guarantee a certain level of image quality across the platform.
The correct keyframe interval is crucial as streamers need to make sure their stream is acceptable in quality and the stream is not being choppy. For this, a keyframe interval value of “2” in OBS is considered the optimal and best balance between quality and smoothness.
You can display the timestamp for each frame with ffprobe
with awk
to only output key frame info. Works in Linux and macOS.
ffprobe -loglevel error -select_streams v:0 -show_entries packet=pts_time,flags -of csv=print_section=0 input.mp4 | awk -F',' '/K/ {print $1}'
Or a slower method that works on any OS and does not require awk
or similar additional processing tools:
ffprobe -loglevel error -skip_frame nokey -select_streams v:0 -show_entries frame=pkt_pts_time -of csv=print_section=0 input.mp4
Results:
0.000000 2.502000 3.795000 6.131000 10.344000 12.554000 16.266000 17.559000 ...
See the ffprobe
documentation for more info.
The following command will give you the offsets of all key Frames in the Video
ffprobe -show_frames -select_streams v:0 \ -print_format csv Video.mov 2> /dev/null | stdbuf -oL cut -d ',' -f4 | grep -n 1 | stdbuf -oL cut -d ':' -f1
Note that the command might respond a little late. Have patience :-)
The ffprobe
command gives you the frame level details in CSV format. Rest is a smart combination of cut
and grep
commands.
cut -d ',' -f4
filters the fourth column - this refers to the 'key_frame' flag.
grep -n 1
filters the key-frames only, and shows their line numbers in the CSV feed.
The
stdbuf -oL
with the cut
command manipulates the buffer of the cut command.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With