python 将图片合成视频

 fourcc = cv2.VideoWriter_fourcc('D', 'I', 'V', 'X')  对应格式 mp4

其他编码格式

CV_FOURCC('P','I','M','1') = MPEG-1 codec
CV_FOURCC('M','J','P','G') = motion-jpeg codec
CV_FOURCC('M', 'P', '4', '2') = MPEG-4.2 codec
CV_FOURCC('D', 'I', 'V', '3') = MPEG-4.3 codec
CV_FOURCC('D', 'I', 'V', 'X') = MPEG-4 codec
CV_FOURCC('U', '2', '6', '3') = H263 codec
CV_FOURCC('I', '2', '6', '3') = H263I codec
CV_FOURCC('F', 'L', 'V', '1') = FLV1 codec
#!/usr/bin/env python
# -*-coding:utf-8-*-
import cv2
import os
from tqdm import tqdm
fsp = 25
fourcc = cv2.VideoWriter_fourcc('D', 'I', 'V', 'X')

//https://blog.csdn.net/zj360202/article/details/79026891
# for n in range(4):

n = 0
video_path = './1-camrea{}.mp4'.format(n)
img_path = "D:\\data_test\\1\\Camera{}\\".format(n)
list_image = os.listdir('D:\\data_test\\1\\Camera{}\\'.format(n))
list_image.sort()


list_image = [os.path.join(img_path,x) for x in list_image]
width = cv2.imread(list_image[0]).shape[1]
heighth = cv2.imread(list_image[0]).shape[0]

video_out = cv2.VideoWriter(video_path, fourcc, fsp, (width,heighth))
print(len(list_image))

count = 0
for i in tqdm(range(len(list_image))):

     if os.path.exists(list_image[i]):
          frame = cv2.imread(list_image[i])
          video_out.write(frame)
          count += 1

print('cout',count)

video_out.release()

 

  • 3
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值