I am trying to generate synthetic video using FFmpeg.
I want the frame rate to be 10 fps, and I want testsrc
counter to advance every frame.
Problem:
When the output file is mp4
, the first video frame is duplicated 10 times.
Question:
Is it a bug in FFmpeg, or a problem in the command line arguments?
I am using the following command:
ffmpeg -y -r 10 -f lavfi -i testsrc=duration=10:size=192x108:rate=1 -c:v libx264 vid.mp4
- The reason for setting
rate=1
is for the counter to advance on each frame.
The generated source pattern is designed to advance the counter every second. - The reason for setting
-r 10
before the input, is for "remuxing" the video at 10 fps, and ignoring the timestamps of the input.
I found the syntax in the following post: Using ffmpeg to change framerate:
Remux with new framerate
ffmpeg -y -r 24 -i seeing_noaudio.h264 -c copy seeing.mp4
When the output file is AVI
it's working correctly (first frame is not duplicated):
ffmpeg -y -r 10 -f lavfi -i testsrc=duration=10:size=192x108:rate=1 -c:v libx264 vid.avi
When generating AVI
at 1 fps, and Remux to mp4
at 10 fps, there is a different problem:
The first and second frames are duplicated twice, and the last frame is missing.
Here are the commands:
ffmpeg -y -f lavfi -i testsrc=duration=10:size=92x54:rate=1 -c:v libx264 -r 1 vid.avi
ffmpeg -y -r 10 -i vid.avi -c:v copy -r 10 vid.mp4
Parsing the mp4
video to PNG
images:
ffmpeg -i vid.mp4 %02d.png
Result:
The first frame is duplicated 10 times.
Parsing the AVI
video to PNG
images:
Result:
There are 10 frames as expected.