[英]Python- Convert .png images in a folder into a video
我想用 python 構建一個屏幕錄像機。所以,我使用了 pyautogui 庫的 Screenshot() function。 當我運行該程序時,我會在這樣的文件夾中獲得單獨的 PNG 圖像-----
C:\rec\1.png
C:\rec\2.png
C:\rec\3.png
C:\rec\4.png
C:\rec\5.png
等等。 現在我想將這些PNG圖像轉換成MP4或AVI格式的視頻。 我該如何進行?
我發現了這個。
他們使用opencv庫:
pip install opencv-python
然后:
import cv2 import numpy as np import glob img_array = [] for filename in glob.glob('C:/rec/*.png'): # (The only change I have made is here to the filepath.) img = cv2.imread(filename) height, width, layers = img.shape size = (width,height) img_array.append(img) out = cv2.VideoWriter('project.avi',cv2.VideoWriter_fourcc(*'DIVX'), 15, size) for i in range(len(img_array)): out.write(img_array[i]) out.release()
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.