python怎么制作图像_如何用python中的图像制作电影

I currently try to make a movie out of images, but i could not find anything helpful .

Here is my code so far:

import time

from PIL import ImageGrab

x =0

while True:

try:

x+= 1

ImageGrab().grab().save('img{}.png'.format(str(x))

except:

movie = #Idontknow

for _ in range(x):

movie.save("img{}.png".format(str(_)))

movie.save()

解决方案

You could consider using an external tool like ffmpeg to merge the images into a movie (see answer here) or you could try to use OpenCv to combine the images into a movie like the example here.

I'm attaching below a code snipped I used to combine all png files from a folder called "images" into a video.

import cv2

import os

image_folder = 'images'

video_name = 'video.avi'

images = [img for img in os.listdir(image_folder) if img.endswith(".png")]

frame = cv2.imread(os.path.join(image_folder, images[0]))

height, width, layers = frame.shape

video = cv2.VideoWriter(video_name, 0, 1, (width,height))

for image in images:

video.write(cv2.imread(os.path.join(image_folder, image)))

cv2.destroyAllWindows()

video.release()

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值