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

前端 未结 3 1620
盖世英雄少女心
盖世英雄少女心 2020-12-23 23:49

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

I\'d like my script to take this series of images (in whatever format I need them), and create a video from them

相关标签:
3条回答
  • 2020-12-24 00:08

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

    0 讨论(0)
  • 2020-12-24 00:23

    If you're not averse to using the command-line, there's the convert command from the ImageMagick package. It's available for Mac, Linux, Windows. See 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:

    convert -quality 100 *.png outvideo.mpeg
    

    or as animated gifs for uploading to webpages:

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

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

    0 讨论(0)
  • 2020-12-24 00:24

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

    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) #
    
    0 讨论(0)
提交回复
热议问题