簡體   English   中英

如何使用Python OpenCV從多個幀生成mp4(而非avi)文件?

[英]How to generate a mp4(not a avi) file from a number of frames using Python OpenCV?

盡管可以生成avi文件,但無法從多個幀生成mp4文件。 如何獲取mp4文件而不是avi文件

# Define the codec and create VideoWriter object.The output is stored in 'outpy.avi' file.
import cv2
out = cv2.VideoWriter('outpy.avi',cv2.VideoWriter_fourcc('M','J','P','G'), 10, (frame_width,frame_height))
out.write(frame) 
out.release()

嘗試使用cv2.VideoWriter_fourcc(*'mpeg')cv2.VideoWriter_fourcc(*'mp4v')


這是一個例子:

sz = (640, 480)
fps = 20
#fourcc = cv2.VideoWriter_fourcc('m', 'p', '4', 'v')
#fourcc = cv2.VideoWriter_fourcc('m', 'p', 'e', 'g')
fourcc = cv2.VideoWriter_fourcc(*'mpeg')

## open and set props
vout = cv2.VideoWriter()
vout.open('output.mp4',fourcc,fps,sz,True)

關於此答案的完整描述: 如何使用opencv將一系列圖像寫入視頻?

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM