其他分享
首页 > 其他分享> > 统计视频时长VideoFlipClip--在VideoFileClip函數中獲取“OSError:[WinError 6]句柄無效”

统计视频时长VideoFlipClip--在VideoFileClip函數中獲取“OSError:[WinError 6]句柄無效”

作者:互联网

import os
import datetime
import sys
import argparse
from moviepy.editor import VideoFileClip

if __name__ == "__main__":
    parser = argparse.ArgumentParser(
        description='Compute Total Time of a Series of Videos')
    parser.add_argument("--path", metavar="PATH", default=".",
                        help="the root path of the videos(default: .)")
    parser.add_argument("--type", metavar="TYPE", default=".mp4",
                        help="the type of the videos(default: .mkv)")
    args = parser.parse_args()
    filelist = []
    
    for a, b, c in os.walk(args.path):
        for name in c:
            fname = os.path.join(a, name)
            if fname.endswith(args.type):
                filelist.append(fname)
    
    ftime = 0.0
    for item in filelist:
        clip = VideoFileClip(item)
        clip.reader.close()  #
        clip.audio.reader.close_proc()  #
        #上面2句主要是解决在VideoFileClip函數中獲取“OSError:[WinError 6]句柄無效” 问题的
        ftime += clip.duration
    print("%d seconds: " % ftime,str(datetime.timedelta(seconds=ftime)))
 杨杨 发布了21 篇原创文章 · 获赞 22 · 访问量 1万+ 私信 关注

标签:WinError,__,獲取,clip,句柄,parser,VideoFileClip,ftime,import
来源: https://blog.csdn.net/weixin_42699651/article/details/104486821