1.ffmpeg
只需要把要合成的文件,后缀改成 -cd1 -cd2 这样的格式,就会自动合成
#!/usr/bin/python
# -*- coding:UTF-8 -*-
import os
import sys
path = sys.path[0]
def exte(a, *endstring):
array = map(a.endswith, endstring)
if True in array:
return True
else:
return False
def make_thumb():
for dirpath, dirnames, filenames in os.walk(path):
if dirpath.find("nowchange") < 0 and dirpath.find("系列") < 0:
for name in filenames:
if exte(name, type):
if name.find("-cd1") > -1 or name.find("-CD1") > -1:
try:
filetxtpath = os.path.join(dirpath, "filelist.txt")
if name.find("-cd1"):
videoname = name.replace("-cd1","")
elif name.find("-CD1"):
videoname = name.replace("-CD1","")
if os.path.exists(filetxtpath):
os.remove(filetxtpath)
file = open(filetxtpath,'a')
for i in range(1,10):
if name.find("-cd1"):
nowname = name.replace("cd1","cd"+bytes(i))
elif name.find("-CD1"):
nowname = name.replace("CD1","CD"+bytes(i))
nowallname = os.path.join(dirpath,nowname)
if os.path.exists(nowallname):
file.write("file '" + nowname + "'")
file.write('\n')
file.close()
videonameall = os.path.join(dirpath, videoname)
if os.path.exists(videonameall):
os.remove(videonameall)
shell = ' ffmpeg -f concat -i filelist.txt -c copy %s' % (videoname)
os.system(shell)
except Exception as result:
print('未知错误: %s' % result)
return
types = ['.mp4', '.avi', '.wmv', '.mkv', '.flv', '.ts', '.mov', '.m4v']
for type in types:
make_thumb()