python image frames to video

前端 未结 4 1600
长发绾君心
长发绾君心 2021-01-12 03:55

I am writing a python/django application and it needs to do image manipulation and then combine the images into a video (each image is a frame). Image manipulation is easy.

4条回答
  •  被撕碎了的回忆
    2021-01-12 04:09

    If u have a folder of images to be framed as video. You can tune the parameters and arrange the frames in sorted manner.

    import cv2
    import os
    from tqdm import tqdm
    import glob
    #TODO
    image_folder = '/*'
    video_name = 'Dir to store the video'#save as .avi
    #is changeable but maintain same h&w over all  frames
    width=640 
    height=400 
    #this fourcc best compatible for avi
    fourcc = cv2.VideoWriter_fourcc('M','J','P','G')
    video=cv2.VideoWriter(video_name,fourcc, 2.0, (width,height))
    
    
    
    for i in tqdm((sorted(glob.glob(image_folder),key=os.path.getmtime))):
         x=cv2.imread(i)
         video.write(x)
    
    cv2.destroyAllWindows()
    video.release()
    

提交回复
热议问题