'Why the frame2video function doesn't work?
I write a function in PyQt5 in order to all frames in one directory can convert to a single video. My code is :
import os
import cv2
import numpy as np
from PIL import Image
def frame2video(im_dir, video_dir, fps):
im_list = os.listdir(im_dir)
im_list.sort(key=lambda x: int(x.split('.')[0]))
img = Image.open(os.path.join(im_dir, im_list[0]))
size = img.size
fourcc = cv2.VideoWriter_fourcc('m', 'p', '4', 'v')
videoWriter = cv2.VideoWriter(video_dir, fourcc, fps, size)
for i in im_list:
im_name = os.path.join(im_dir + i)
frame = cv2.imdecode(np.fromfile(im_name, dtype=np.uint8), -1)
videoWriter.write(frame)
videoWriter.release()
if __name__ == '__main__':
video_storedir = 'G:/dataset/video_new.mp4'
if not os.path.exists(video_storedir):
os.mkdir(video_storedir)
path = 'G:/dataset' + '/' + 'example_Trim' + '_new/'
frame2video(path, video_storedir, 30)
but it doesn't work, and run is still work, and the corresponding folder doesn't have the processed video....
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|

