【发布时间】:2021-02-06 21:16:51
【问题描述】:
我创建了关注函数。
import cv2
import numpy as np
FPS = 10
def write_video(file_name, images, slide_time=5):
fourcc = cv2.VideoWriter.fourcc(*'X264')
out = cv2.VideoWriter(file_name, fourcc, FPS, (870, 580))
for image in images:
cv_img = cv2.cvtColor(np.array(image), cv2.COLOR_RGB2BGR)
for _ in range(slide_time * FPS):
out.write(cv_img)
out.release()
它曾经工作过,但我打破了它,不知道如何。
当我尝试使用 MPV 打开时,我得到:
[ffmpeg/demuxer] avi: Could not find codec parameters for stream 0 (Video: h264 (X264 / 0x34363258), none, 870x580): unspecified pixel format
[ffmpeg/demuxer] Consider increasing the value for the 'analyzeduration' and 'probesize' options
(+) Video --vid=1 (h264 870x580 10.000fps)
Exiting... (Errors when loading file)
这是一个最小的可重现示例:
import requests
from PIL import Image
from io import BytesIO
import cv2
import numpy as np
FPS = 10
res = requests.get('https://external-content.duckduckgo.com/iu/?u=https%3A%2F%2Ftse1.mm.bing.net%2Fth%3Fid%3DOIP.bNvIoWPYwYWXe-gpRKsalQHaE9%26pid%3DApi&f=1')
image = Image.open(BytesIO(res.content))
image = np.array(image)
image = cv2.cvtColor(image, cv2.COLOR_RGB2BGR)
fourcc = cv2.VideoWriter.fourcc(*'MJPG')
video = cv2.VideoWriter('output.avi', fourcc, FPS, (870, 580))
for _ in range(13 * FPS):
video.write(image)
video.release()
【问题讨论】:
标签: python opencv python-imaging-library cv2