我的CPU使用率是否会从96%-100%下降 在运行此脚本时平均喜欢30%。
我希望它能够以100%的速度运行,以便更快地处理视频。任何帮助都会提前谢谢。
import moviepy.editor as mp
from moviepy.editor import VideoFileClip, concatenate
import os, glob
from random import randint
from shutil import copyfile
def clipexport():
video1 = mp.VideoFileClip(clips)
Duration = video1.duration
if "sin" in clips:
try:
startp = filename[filename.find("sin")+3:filename.find("sin")+6].strip()
print(startp)
if "}" in startp:
startp = startp[:startp.find('}')]
print(startp)
start = int(startp)
else:
print(startp)
start = int(startp)
except:
start = 0.35
print('using default start value')
else:
start = 0.35
print(start)
if "sout" in clips:
try:
endp = filename[filename.find("sout")+4:filename.find("sout")+7].strip()
print(endp)
if "}" in endp:
endp = endp[:endp.find('}')]
print(endp)
end = int(endp)
else:
print(endp)
end = int(endp)
except:
end = Duration - 0.35
print('using default end value')
else:
end = Duration - 0.35
print(Duration)
print(end)
trimmedvideo = mp.VideoFileClip(clips).subclip(start, end).resize(width=1920)
trimmedvideo.write_videofile(exportPath, bitrate="8000k", threads="8")
def videocreator():
calculateClips = 0
for filename in os.listdir(newpath):
print(filename)
if ".mp4" in filename:
calculateClips = calculateClips + 1
calculateClips = calculateClips -1
videolist = []
videoLength = 0
totalClips = 0
for filename in os.listdir(newpath):
print(filename + "Check Videos")
if ".mp4" in filename:
videolist.append(VideoFileClip(newpath + filename).crossfadein(1))
final = concatenate(videolist, padding=-1, method="compose")
final.write_videofile('myvideo.mp4', bitrate ='8000k', threads="8")
path = 'C:/TBD/TBD/#Frikkie/'
for infile in glob.glob( os.path.join(path, '**') ):
if "-" in infile:
Refno = infile[infile.find('kie')+4:infile.find('-')].strip()
else:
Refno = infile[infile.find('kie')+4:].strip()
print(Refno)
clippath = infile + "/"
length = len(clippath)
#print(length)
for clips in glob.glob( os.path.join(clippath, '**') ):
#print(clips)
filename = clips[clips.find(infile)+length:]
filename = filename[:filename.find(".")]
filename = filename + ".mp4"
print(filename)
exportPath = infile + "/" + "Export" + "/" + filename
exportfolder = infile + "/" + "Export"
print(exportfolder)
if not os.path.exists(exportfolder):
os.makedirs(exportfolder)
try:
if ".mp4" in clips:
#clipexport()
print("done mp4")
elif ".m4v" in clips:
#clipexport()
print("done mp4")
elif ".MOV" in clips:
#clipexport()
print("done mp4")
else:
continue
except:
print("Error")
newpath = exportfolder + '/'
newpath = newpath.replace('/', '\\')
try:
mp3number = str(randint(1,5))
src = ("C:\music\{}.mp3".format(mp3number))
dst = ("{}{}.mp3".format(newpath, mp3number))
copyfile(src, dst)
except:
print("could not copy mp3")
print("Mp3 Copied")
try:
print("Video Path = " + newpath)
videolist= []
for filename in os.listdir(newpath):
if "{" in filename:
newfilename = filename[:filename.find("{")].strip()
newfilename = newfilename + ".mp4"
oldfilename = newpath + filename
rename = newpath + newfilename
os.rename(oldfilename, rename)
videolist.append(newfilename)
else:
videolist.append(filename)
for files in videolist:
if files == "1.mp4":
print(files)
oldfilename = newpath + files
rename = newpath + "01.mp4"
os.rename(oldfilename, rename)
elif files == "2.mp4":
print(files)
oldfilename = newpath + files
rename = newpath + "02.mp4"
os.rename(oldfilename, rename)
elif files == "3.mp4":
print(files)
oldfilename = newpath + files
rename = newpath + "03.mp4"
os.rename(oldfilename, rename)
elif files == "4.mp4":
print(files)
oldfilename = newpath + files
rename = newpath + "04.mp4"
os.rename(oldfilename, rename)
elif files == "5.mp4":
print(files)
oldfilename = newpath + files
rename = newpath + "05.mp4"
os.rename(oldfilename, rename)
elif files == "6.mp4":
print(files)
oldfilename = newpath + files
rename = newpath + "06.mp4"
os.rename(oldfilename, rename)
elif files == "7.mp4":
print(files)
oldfilename = newpath + files
rename = newpath + "07.mp4"
os.rename(oldfilename, rename)
elif files == "8.mp4":
print(files)
oldfilename = newpath + files
rename = newpath + "08.mp4"
os.rename(oldfilename, rename)
elif files == "9.mp4":
print(files)
oldfilename = newpath + files
rename = newpath + "09.mp4"
os.rename(oldfilename, rename)
print('done')
except:
print('not done')
videocreator()