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)}toFFmpegWriterinstead ofoutputdictwith-r.Neither
inputdictnoroutputdictare documented inskvideo(no mention offfmpegdocumentation, no examples), nor is-framerateproperly documented in theffmpegdocumentation (it speaks about grabbing rather than saving, and claims that the default is30000/1001even though it is25), nor is-framerateeven mentioned when callingffmpeg --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.