macos 如何根据一组图像编写电影的脚本?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/945250/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-21 06:11:49  来源:igfitidea点击:

How can I script the creation of a movie from a set of images?

pythonmacosvideo

提问by Pietro Speroni

I managed to get a set of images loaded using Python.

我设法使用 Python 加载了一组图像。

I'd like my script to take this series of images (in whatever format I need them), and create a video from them. The big limit in all this is that I am looking for something easy and simple to install. Ideally, using the standard OS X installation procedure:

我希望我的脚本采用这一系列图像(以我需要的任何格式),并从中创建视频。所有这一切的最大限制是我正在寻找易于安装的东西。理想情况下,使用标准的 OS X 安装过程:

  • download .dmg
  • click
  • move into the application folder
  • 下载.dmg
  • 点击
  • 进入应用程序文件夹

I do not want to expend a lot of effort to install the video editing program. Just something simple that works.

我不想花费很多精力来安装视频编辑程序。只是一些简单的工作。



Questions

问题

  1. What format should I aim for? I need my video to be playable on Linux, Mac, and Windows systems. The images are graphs, so we are speaking of discreet images, not photographs. It should be pretty easy to compress it. There will be about 1000 images, so this will be a short movie.

  2. What tools should I use to produce the actual video? I need to either do it directly from Python using a library designed for this purpose, or by scripting command-line tools called from Python.

  1. 我应该瞄准什么格式?我需要我的视频可以在 Linux、Mac 和 Windows 系统上播放。图像是图表,所以我们说的是谨慎的图像,而不是照片。压缩它应该很容易。将有大约 1000 张图像,所以这将是一部短片。

  2. 我应该使用什么工具来制作实际视频?我需要使用为此目的设计的库直接从 Python 执行此操作,或者通过编写从 Python 调用的命令行工具的脚本来执行此操作。

回答by Shawn Chin

If you're not averse to using the command-line, there's the convertcommand from the ImageMagick package. It's available for Mac, Linux, Windows. See http://www.imagemagick.org/script/index.php.

如果您不反对使用命令行,则可以使用convertImageMagick 包中的命令。它适用于 Mac、Linux、Windows。请参阅http://www.imagemagick.org/script/index.php

It supports a huge number of image formats and you can output your movie as an mpeg file:

它支持大量图像格式,您可以将电影输出为 mpeg 文件:

convert -quality 100 *.png outvideo.mpeg

or as animated gifs for uploading to webpages:

或作为用于上传到网页的 gif 动画:

convert -set delay 3 -loop 0 -scale 50% *.png animation.gif

More options for the convertcommand available here: ImageMagick v6 Examples - Animation Basics

convert此处提供的命令的更多选项:ImageMagick v6 示例 - 动画基础

回答by Daniyar

You may use OpenCV. And it can be installed on Mac. Also, it has a python interface.

您可以使用 OpenCV。它可以安装在 Mac 上。此外,它有一个python 接口

I have slightly modified a program taken from here, but don't know if it compiles, and can't check it.

我稍微修改了一个从这里获取的程序,但不知道它是否编译,也无法检查它。

import opencv
from opencv.cv import *
from opencv.highgui import *

isColor = 1
fps     = 25  # or 30, frames per second
frameW  = 256 # images width
frameH  = 256 # images height
writer = cvCreateVideoWriter("video.avi",-1, 
fps,cvSize(frameW,frameH),isColor)

#-----------------------------
#Writing the video file:
#-----------------------------

nFrames = 70; #number of frames
for i in range(nFrames):
    img = cvLoadImage("image_number_%d.png"%i) #specify filename and the extension
     # add the frame to the video
    cvWriteFrame(writer,img)

cvReleaseVideoWriter(writer) #

回答by user49117

Do you have to use python? There are other tools that are created just for these purposes. For example, to use ffmpeg or mencoder.

你必须使用python吗?还有其他工具专为这些目的而创建。例如,使用ffmpeg 或 mencoder