Python JPEG to movie

前端 未结 4 1141
再見小時候
再見小時候 2020-12-29 10:20

I am looking for a way to concatenate a directory of images files (e.g., JPEGs) to a movie file (MOV, MP4, AVI) with Python. Ideally, this would also allow me to take multip

4条回答
  •  悲&欢浪女
    2020-12-29 10:30

    here's a cut-down version of a script I have that took frames from one video and them modified them(that code taken out), and written to another video. maybe it'll help.

    import cv2
    
    fourcc = cv2.cv.CV_FOURCC(*'XVID')
    out = cv2.VideoWriter('out_video.avi', fourcc, 24, (704, 240))
    
    c = cv2.VideoCapture('in_video.avi')
    
    while(1):
      _, f = c.read()
      if f is None:
        break
    
      f2 = f.copy() #make copy of the frame
      #do a bunch of stuff (missing)
    
      out.write(f2)  #write frame to the output video
    
    out.release()
    cv2.destroyAllWindows()
    c.release()
    

    If you have a bunch of images, load them in a loop and just write one image after another to your vid.

提交回复
热议问题