程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

Python splices pictures into videos

編輯:Python
import cv2
import os
# Saved video path and video size(1920, 1080)
writer = cv2.VideoWriter('D:/achenf/data/0618/data0706/fold2/val/val.mp4', cv2.VideoWriter_fourcc('m', 'p', '4', 'v'), 25, (1920, 1080), True)
# ********** Set the number of frames **********
total_frame = len(os.listdir('D:/achenf/data/0618/data0706/fold2/val/img/'))
print(total_frame)
for frame_num in range(total_frame):
img_path = 'D:/achenf/data/0618/data0706/fold2/val/img/%d.jpg' % frame_num # Picture path 
read_img = cv2.imread(img_path)
writer.write(read_img)
writer.release()

VideoWriter

use OpenCV To save the video, you need to call its VideoWriter class

VideoWriter(filename, fourcc, fps, frameSize[, isColor]) -> <VideoWriter object>

1. The first parameter is the path of the file to be saved
2.fourcc Specify encoder
3.fps The frame rate of the video to save
4.frameSize The picture size of the file to be saved
5.isColor Indicates whether the picture is black and white or color

The specified size of video storage should be the same as the size of the written image , Otherwise, video storage fails


  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved