如何在 cv2.VideoWriter 中使用 FPS 参数? [英] How do I use the FPS argument in cv2.VideoWriter?
问题描述
好的,所以我正在制作视频.我想确切地知道如何使用 FPS 参数.它是一个浮点数,所以我认为这是我想要的每帧之间的间隔.你能给个例子吗?我只想知道视频会如何随着 FPS 参数值的变化而变化.,因为我制作的视频现在太快了.谢谢!
Ok, so I am making a video. I want to know exactly how to use the FPS argument. It is a float, so I assumed it was what interval do I want between each frame. Can you give an example? I just want to know how the video would change with varying FPS argument values., because my video I made is way too fast now. Thanks!
推荐答案
确实如此 - 每秒帧数
.换句话说,你想每秒显示多少帧?
It really is just that - frames per second
. In other words, how many frames do you want to display every second?
这是一个例子:
writer = cv2.VideoWriter(filename="my_video.avi", #Provide a file to write the video to
fourcc=cv2.cv.CV_FOURCC('i','Y', 'U', 'V'), #Use whichever codec works for you...
fps=15, #How many frames do you want to display per second in your video?
frameSize=(width, height)) #The size of the frames you are writing
示例用法:
while True:
flag, frame = capture.read()
cv2.imshow("Camera", frame)
key_pressed = cv2.waitKey(10)
if key_pressed == 27: #Escape key
break
writer.write(frame)
cv2.destroyAllWindows()
因此,您将拥有一个视频文件,其中包含您的相机捕获的所有静止帧,这些帧拼接在一起作为单个视频.每秒显示的帧数将与您使用 fps
参数设置的一样.(如果你的视频太快,我建议设置一个较低的fps
)
Thus, you will have a video file that consists of all the still frames that your camera captured stitched together as a single video. The number of frames that are displayed per second will be as you set with the fps
parameter. (If your video is too fast, I recommend setting a lower fps
)
这段代码是我脑子里写的,所以我还没有测试过,但它应该可以工作.如果您有任何疑问或问题,请告诉我.希望对你有帮助!
I wrote this code off the top of my head, so I haven't tested it, but it should work. Let me know if you have any questions or problems. I hope this helps you!
这篇关于如何在 cv2.VideoWriter 中使用 FPS 参数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!