python create video from images

Solutions on MaxInterview for python create video from images by the best coders in the world

showing results for - "python create video from images"
Emil
30 Mar 2020
1import cv2
2import numpy as np
3import glob
4
5img_array = []
6for filename in glob.glob('C:/New folder/Images/*.jpg'):
7    img = cv2.imread(filename)
8    height, width, layers = img.shape
9    size = (width,height)
10    img_array.append(img)
11
12
13out = cv2.VideoWriter('project.avi',cv2.VideoWriter_fourcc(*'DIVX'), 15, size)
14 
15for i in range(len(img_array)):
16    out.write(img_array[i])
17out.release()
Elizabeth
28 Nov 2018
1import os 
2import cv2  
3from PIL import Image  
4  
5print(os.getcwd())  
6  
7os.chdir("C:\\Python\\Geekfolder2")   
8path = "C:\\Python\\Geekfolder2"
9  
10mean_height = 0
11mean_width = 0
12  
13num_of_images = len(os.listdir('.')) 
14  
15for file in os.listdir('.'): 
16    im = Image.open(os.path.join(path, file)) 
17    width, height = im.size 
18    mean_width += width 
19    mean_height += height 
20    
21  
22mean_width = int(mean_width / num_of_images) 
23mean_height = int(mean_height / num_of_images) 
24  
25  
26for file in os.listdir('.'): 
27    if file.endswith(".jpg") or file.endswith(".jpeg") or file.endswith("png"): 
28        
29        im = Image.open(os.path.join(path, file))  
30   
31        
32        width, height = im.size    
33        print(width, height) 
34  
35        
36        imResize = im.resize((mean_width, mean_height), Image.ANTIALIAS)  
37        imResize.save( file, 'JPEG', quality = 95) 
38        
39        print(im.filename.split('\\')[-1], " is resized"40  
41  
42def generate_video(): 
43    image_folder = '.'
44    video_name = 'mygeneratedvideo.avi'
45    os.chdir("C:\\Python\\Geekfolder2") 
46      
47    images = [img for img in os.listdir(image_folder) 
48              if img.endswith(".jpg") or
49                 img.endswith(".jpeg") or
50                 img.endswith("png")] 
51     
52    
53    
54    print(images)  
55  
56    frame = cv2.imread(os.path.join(image_folder, images[0])) 
57  
58    
59    
60    height, width, layers = frame.shape   
61  
62    video = cv2.VideoWriter(video_name, 0, 1, (width, height))  
63  
64    
65    for image in images:  
66        video.write(cv2.imread(os.path.join(image_folder, image)))  
67      
68    
69    cv2.destroyAllWindows()  
70    video.release()  
71  
72  
73generate_video() 
74
Florencia
01 Sep 2019
1  import cv2
2  import numpy as np
3  
4  # choose codec according to format needed
5  fourcc = cv2.VideoWriter_fourcc(*'mp4v') 
6  video = cv2.VideoWriter('video.avi', fourcc, 1, (width, height))
7
8  for j in range(0,5):
9     img = cv2.imread(str(i) + '.png')
10     video.write(img)
11
12  cv2.destroyAllWindows()
13  video.release()
14
queries leading to this page
python image to videogenerate video from images pythonpython display a video from imagesmake video using images in pythonpython create video from images ffmpegimages to video pythoniimages to video pythonvideo to image pythonpython turn video into imagesmake video from pictures pythoncreate video from images pythonpython video from imagespython video to imagesconvert video to images pythoncreate video from photo pythoncreate video from images python3 python images to videopython create images from videocreate video auto thumbnail in pythonmaking video from images pythonmake video from images pythonmake 5 video of image pythonpython turn images into videomaking a video from images in pythonhow to create a video using photos pythonhow to make a video from images in pythongenerate thumbnail from video in pythonpython convert video to imageshow to make video from images pythonpython make a video from imagesvideo to image using pythonimage to video pythonpython make video from imageswrite images to video pythonpython how to save image of a video how to set a video on images in pythonmake video from bunch pictures using pythonmake video from image pythoncreate a video with images pythonmake video using image pythonpython video converter create a video from iamge and mp4 pythonhow to turn imatges to video in pythonwrite video from images pythonpython create video from imagesimages to video maker pythonpython picture to videoshow video on python imagesimages to video in pythonpython script to create video from imageshow to create video from images in pythonpython create video from images