본문 바로가기
Computer Vision

[OpenCV] cv2.VideoWriter로 동영상 생성하기

by hymndaniel 2023. 4. 19.
output_dir = "/content/drive/MyDrive/crop_monitoring_project/videos/"

# Set the video parameters
fourcc = cv2.VideoWriter_fourcc(*'mp4v') 
frame_shape = cv2.imread(test_data_path_list[0]).shape # 저장할 프레임의 크기는 인풋 이미지의 사이즈로
video_height = frame_shape[0]
video_width = frame_shape[1]
frame_rate = 2

# Create the video writer
out = cv2.VideoWriter("file_path/file_name.mp4", fourcc, frame_rate, (video_width, video_height))


# Create frames to saving video
for i in range(len(test_data_path_list)): 
	file_path = test_data_path_list[i]
	frame = cv2.imread(file_path)

    # Add the image to the video
    out.write(frame)

# Release the video writer
out.release()
 

 

 

Reference

https://github.com/ContinuumIO/anaconda-issues/issues/223

 

opencv - not writing output with cv2.VideoWriter.write · Issue #223 · ContinuumIO/anaconda-issues

OpenCV is not writing to output video files with cv2.VideoWriter.write. I only get an empty video file (8 KB) and no error messages. Where is the problem? Thanks a lot! I am running 2.7.8 |Anaconda...

github.com

 

728x90