Python:使用几个.png图像制作视频

时间:2022-09-02 00:22:40

I'm trying to make a video using a series of .png images. I found this Python script, but I am not entirely sure on how to use it:

我正在尝试使用一系列.png图像制作视频。我找到了这个Python脚本,但我不完全确定如何使用它:

https://sites.google.com/site/timelapsepy/home

https://sites.google.com/site/timelapsepy/home

I also tried to look into opencv, but it doesn't seem to install properly for me. Any ideas on a simple program to string several images together to create a time-lapse video? I would like to use Python for this if possible.

我也试着调查opencv,但它似乎没有正确安装给我。有关一个简单程序的想法,将几个图像串在一起,以创建一个延时视频?如果可能的话,我想使用Python。

2 个解决方案

#1


46  

If you really need a scripted python solution, you can look into using PIL

如果你真的需要一个脚本化的python解决方案,你可以考虑使用PIL

But if you just want to easily convert a sequence of png images to a movie, you can simply use ffmpeg:

但是如果你只想轻松地将一系列png图像转换为电影,你可以简单地使用ffmpeg:

ffmpeg -f image2 -r 1/5 -i image%05d.png -vcodec mpeg4 -y movie.mp4

This command takes images with 5 digit padding (image00001.png) and compresses them into an mpeg4 quicktime, at a rate of holding each frame for 5 seconds. You could do a different fps if your images are greater: -r 24 (24 frames per second)

此命令使用5位数填充(image00001.png)拍摄图像并将其压缩为mpeg4 quicktime,速度为每帧保持5秒。如果你的图像更大,你可以做不同的fps:-r 24(每秒24帧)

#2


15  

Instead of ffmpeg, you might want to use avconv

您可能希望使用avconv而不是ffmpeg

avconv -f image2 -i figMatplotlib%d.png -r 76 -s 800x600 foo.avi

#1


46  

If you really need a scripted python solution, you can look into using PIL

如果你真的需要一个脚本化的python解决方案,你可以考虑使用PIL

But if you just want to easily convert a sequence of png images to a movie, you can simply use ffmpeg:

但是如果你只想轻松地将一系列png图像转换为电影,你可以简单地使用ffmpeg:

ffmpeg -f image2 -r 1/5 -i image%05d.png -vcodec mpeg4 -y movie.mp4

This command takes images with 5 digit padding (image00001.png) and compresses them into an mpeg4 quicktime, at a rate of holding each frame for 5 seconds. You could do a different fps if your images are greater: -r 24 (24 frames per second)

此命令使用5位数填充(image00001.png)拍摄图像并将其压缩为mpeg4 quicktime,速度为每帧保持5秒。如果你的图像更大,你可以做不同的fps:-r 24(每秒24帧)

#2


15  

Instead of ffmpeg, you might want to use avconv

您可能希望使用avconv而不是ffmpeg

avconv -f image2 -i figMatplotlib%d.png -r 76 -s 800x600 foo.avi