import pyautogui import time import datetime import cv2 import os from moviepy.editor import VideoFileClip, concatenate_videoclips
defcreate_video(image_folder, video_name): images = [img for img in os.listdir(image_folder) if img.endswith(".png")] frame = cv2.imread(os.path.join(image_folder, images[0])) height, width, layers = frame.shape
video = cv2.VideoWriter(video_name, cv2.VideoWriter_fourcc(*'mp4v'), 24, (width, height)) # 24是帧数
for image in images: video.write(cv2.imread(os.path.join(image_folder, image))) os.remove(os.path.join(image_folder, image)) # 删除图片
cv2.destroyAllWindows() video.release()
deffind_videos_of_the_day(directory, date): videos = [] for file in os.listdir(directory): if file.endswith(".mp4") and date in file: videos.append(file) videos.sort(key=lambda x: os.path.getmtime(os.path.join(directory, x))) return videos
defmerge_videos(videos, output_filename): clips = [VideoFileClip(video) for video in videos] final_clip = concatenate_videoclips(clips) final_clip.write_videofile(output_filename, codec="libx264")