[FFmpeg-user] Unexpected result when discarding keyframes

James Fowkes jamesfowkes at gmail.com
Mon Dec 23 18:25:35 EET 2019

We have a video conversion process using ffmpeg, for generating
low-quality previews of h264 videos.
This is partially done on a Raspberry Pi, and then uploaded to a
server where some more processing is done.

For testing purposes, I am using a PC (ffmpeg under cygwin) rather
than the raspberry pi itself.
The end results are identical on both.

Currently this process works for a particular set of videos.
We are now adding a second video source that this process does not work with.

As part of the process, we generate files that are only supposed to
have keyframes in:

ffmpeg -discard nokey -i split.mp4 -c copy -y keyframes.h264

Output from this command (for a typical representative file):

On the raspberry pi: http://0x0.st/zGzL.log
On the PC: http://0x0.st/zGz9.log

The issue I am having is that this keyframes.h264 file seems to have
non-keyframes in it at the start.
The original video has a keyframe per second at 25fps.
The created keyframe files have the first 20-25 frames of the original
video, and then the remaining keyframes.

I have determined this by getting ffmpeg to dump the frames from that
keyframe file to jpg.

This ultimately has the effect of "stretching" the first second of
footage to 20-25s when we reconstruct the video.
This is because it assumes that each frame in the uploaded video is at
1s intervals.

I have omitted the remaining steps from the upload and reconstruction
process for clarity.
I can provide details of those steps if needed.

I have upload example input and output files:
1. Representative input file: http://0x0.st/zGzp.mp4
2. Keyframes h264 file: http://0x0.st/zGzf.h264

If I use:
ffprobe -select_streams v -show_frames -show_entries frame=pict_type
-of csv 02-Asplit.mp4 | grep -n I | cut -d ':' -f 1

to get the indexes of the keyframes in the original file, ffprobe
certainly thinks that there is 1 every 25 frames:


so I am reasonably certain that the original files are OK.

For comparison, here are mp4 files and a log from a different source
that is correctly converted using the same commands:
1. Representative input file: http://0x0.st/zG-M.mp4
2. Keyframes h264 file: http://0x0.st/zG-g.h264
3. ffmpeg log: http://0x0.st/zG-l.log

Basically, my question is how can I correctly produce this "raw"
keyframes file from the given input?
I hope all the above is clear.

Thanks in advance for any assistance!

More information about the ffmpeg-user mailing list