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

前端 未结 3 1638
盖世英雄少女心
盖世英雄少女心 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: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) #
    

提交回复
热议问题