zoukankan      html  css  js  c++  java
  • python VideoFileClip 获取多级文件目录下的视频时长

    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:UsersJQVideos"
    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))
  • 相关阅读:
    数据排序
    (一)Spark简介Java&Python版Spark
    醒 了
    祈福
    可以接受失败,但不选择放弃
    烦中偷乐
    Yahoo! UI Library入门
    文章内容的简单优化方法
    Asp.Net网站速度优化
    ASP.NET实现GZIP压缩优化
  • 原文地址:https://www.cnblogs.com/jiaoqiang/p/11195346.html
Copyright © 2011-2022 走看看