Creating video from images

create a video to show the dynamic variation of the data, like just continuously showing the images one by one quickly, so I used images (the images just called 1,2,3,4,…..) and wrote the following code:

import cv2
import numpy as np

img=[]
for i in range(0,5):
img.append(cv2.imread(str(i)+’.png’))

height,width,layers=img[1].shape

video=cv2.VideoWriter(‘video.avi’,-1,1,(width,height))

for j in range(0,5):
video.write(img[j])

cv2.destroyAllWindows()
video.release()

————————-

import cv2

img1 = cv2.imread(‘1.jpg’)
img2 = cv2.imread(‘2.jpg’)
img3 = cv2.imread(‘3.jpg’)

height , width , layers = img1.shape

video = cv2.VideoWriter(‘video.avi’,-1,1,(width,height))

video.write(img1)
video.write(img2)
video.write(img3)

cv2.destroyAllWindows()
video.release()

—————————

if you just want to easily convert a sequence of png images to a movie, you can simply use 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)

————————–

i found an alternative solution using ffmpeg:

def save():
os.system(“ffmpeg -r 1 -i img%01d.png -vcodec mpeg4 -y movie.mp4”)

—————————-

5 Comments

  1. It is tremendous material. It’s actually filled with useful and fascinating details that anybody can grasp. I actually adore reading through articles so much well-written. You’ve performed a remarkably nice job with this particular material.

  2. I can tell you are choosy in regards to what and just how you tend to compile your own content material. This specific is very well written, informative as well as intriguing. I liked this reading very much. I personally agree with you.

  3. I’m going through a hard time fathoming just how much investigation you had to do for this specific data, however I love it and I agree. You tend to make a lot of sense.

Comments are closed.