原创 

python opencv 图片转视频无法播放问题解决

分类:python    563人阅读    IT小君  2023-08-01 13:09

注意下方尺寸问题

images_directory = 'G:\\opt\\upload\\imageGroup\\123'
video_output = 'G:\\opt\\upload\\imageGroup\\123\\output_video.mp4'
import cv2
import os

# Get the list of image filenames in the directory
image_files = sorted(os.listdir(images_directory))
fps = 30
frame_size = (1080, 1620) # 图片尺寸根据下方 print(image.shape) 确认 大小不一致 无法播放
# Initialize the video writer
fourcc = cv2.VideoWriter_fourcc(*'mp4v')
video_writer = cv2.VideoWriter(video_output, fourcc, fps, frame_size,True)
# Iterate through the image files and write them to the video
for image_file in image_files:
    image_path = os.path.join(images_directory, image_file)
    if image_path.endswith('.jpg'):
        print(image_path)
        image = cv2.imread(image_path)
        cv2.imshow('frame', image)
        print(image.shape)
        video_writer.write(image)
# Release the video writer
video_writer.release()
支付宝打赏 微信打赏

如果文章对你有帮助,欢迎点击上方按钮打赏作者

 工具推荐 更多»