https://blog.youkuaiyun.com/qq_22210253/article/details/86684658
https://blog.youkuaiyun.com/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)))