I would like to use Python to create a video file with 60 frames per second.
I try to make a two-minute video (DURATION_SECONDS = 120
) as follows, but I get a video that lasts for 4 minutes and 48 seconds instead of 2 minutes. So the frame rate seems to be 25, even though I pass 60 to FFmpegWriter
. What am I doing wrong?
FRAMES_PER_SECOND = 60
DURATION_SECONDS = 120
import skvideo
skvideo.setFFmpegPath('C:\\ffmpeg\\x64')
import skvideo.io
import numpy as np
video_writer = skvideo.io.FFmpegWriter("test.mp4", outputdict={'-r':str(FRAMES_PER_SECOND)})
for i in range(DURATION_SECONDS*FRAMES_PER_SECOND):
video_writer.writeFrame(np.zeros((100,100)))
video_writer.close()
I get the same result also with
outputdict={'-vf':f"fps={FRAMES_PER_SECOND}"}
The solution is passing inputdict={'-framerate':str(FRAMES_PER_SECOND)}
to FFmpegWriter
instead of outputdict
with -r
.
Neither inputdict
nor outputdict
are documented in skvideo
(no mention of ffmpeg
documentation, no examples), nor is -framerate
properly documented in the ffmpeg
documentation (it speaks about grabbing rather than saving, and claims that the default is 30000/1001
even though it is 25
), nor is -framerate
even mentioned when calling ffmpeg --help
.
Shout out to @Goury for not deleting this thread (which helped here a lot) despite having received a negative score of -3 from the StackOverflow community in that thread.