计算一个文件下的所有视频总时长

https://blog.csdn.net/qq_22210253/article/details/86684658
https://blog.csdn.net/HelloWorld_SDK/article/details/88088513
注意:
出现错误

Traceback (most recent call last):
  File "compute_duration.py", line 23, in <module>
    clip = VideoFileClip(item)
  File "D:\Python\Python36\lib\site-packages\moviepy\video\io\VideoFileClip.py", line 91, in __init__
    fps_source=fps_source)
  File "D:\Python\Python36\lib\site-packages\moviepy\video\io\ffmpeg_reader.py", line 69, in __init__
    self.initialize()
  File "D:\Python\Python36\lib\site-packages\moviepy\video\io\ffmpeg_reader.py", line 104, in initialize
    self.proc = sp.Popen(cmd, **popen_params)
  File "D:\Python\Python36\lib\subprocess.py", line 596, in __init__
    _cleanup()
  File "D:\Python\Python36\lib\subprocess.py", line 205, in _cleanup
    res = inst._internal_poll(_deadstate=sys.maxsize)
  File "D:\Python\Python36\lib\subprocess.py", line 1035, in _internal_poll
    if _WaitForSingleObject(self._handle, 0) == _WAIT_OBJECT_0:
OSError: [WinError 6] 句柄无效。

解决:clip.close()#加上这个

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=".mkv",
                        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)
        ftime += clip.duration
        clip.close()#加上这个
    print("%d seconds: " % ftime,str(datetime.timedelta(seconds=ftime)))

发布了26 篇原创文章 · 获赞 4 · 访问量 2万+
展开阅读全文

没有更多推荐了,返回首页

©️2019 CSDN 皮肤主题: 大白 设计师: CSDN官方博客

分享到微信朋友圈

×

扫一扫,手机浏览