from multiprocessing import Process, Queue import os from moviepy.editor import VideoFileClip class FileInfo(): def __init__(self, file_dir, size, time): self.__file_dir = file_dir self.__size = size self.__time = time @property def file_dir(self): return self.__file_dir @property def size(self): return self.__size @property def time(self): return self.__time def get_filename(self): #获取当前路径下所有非目录文件 for root, dir, files in os.walk(self.__file_dir): return files def get_all_files(self, dir): #该路径下所有视频完整路径 files_ = [] list = os.listdir(dir) for i in range(0, len(list)): path = os.path.join(dir, list[i]) if os.path.isdir(path): files_.extend(self.get_all_files(path)) if os.path.isfile(path): files_.append(path) return files_ def get_filetime(self, filepath): #返回视频的时长(min) clip = VideoFileClip(filepath) file_time = clip.duration / 60 self.__time += file_time clip.close() return self.__time video_path = r"C:\Users\JQ\Videos" file_info = FileInfo(video_path, 0, 0) whole_path = file_info.get_all_files(video_path) # 单进程实现 print("=============单进程=================")for fn in whole_path: if fn.endswith('.flv'): file_info.get_filetime(fn) print('视频个数:%d,总共%f分钟' % (sum, file_info.time))