在moviepy上同时将视频剪辑作为视频文件并行编写,而无需等待该过程完成,
因此,我将我的视频分成 5 秒的片段
n=0
p = 5
clip = mp.VideoFileClip(videofile).subclip(n, n+p)
然后我在视频中添加字幕,
x = 0
text2 = 'hello'+str(x)
text[x] = TextClip(text2, font='Amiri-regular',color='white',fontsize=24).set_duration(p).set_start(0)
然后我对前五个剪辑一次又一次地执行此操作,在第五个剪辑中,我将剪辑写入视频文件
随着写作在后台继续,我想继续处理视频的其余部分,所以我使用多处理,在编辑@Roland Smith 建议的代码后,我使用:
if float.is_integer(float(x)/5.0) == True and x != 0:
text2 = concatenate(text.values())
textd = text2.on_color(size=(clip.w ,text2.h),color=(0,0,0), col_opacity=0.6).set_pos('bottom')
video3[n] = CompositeVideoClip([VideoFileClip(videofile).subclip(n,5+n), textd])
def audioclip(data):
outname = str(data)[-10:].strip('>') + '.mp4'
data.write_videofile(outname,fps=24, codec='libx264')
return outname
names = video3.values()
h = multiprocessing.Pool()
audiofiles = h.map(audioclip, names)
gc.collect()
n = n+p
x = x+1
我已经进口了
from moviepy.editor import *
import moviepy.editor as mp
import os
import multiprocessing
from multiprocessing import pool
但是,我收到此错误:
Traceback (most recent call last):
File "p2 (copy).py", line 128, in <module>
audiofiles = h.map(audioclip, names)
File "/usr/lib/python2.7/multiprocessing/pool.py", line 251, in map
return self.map_async(func, iterable, chunksize).get()
File "/usr/lib/python2.7/multiprocessing/pool.py", line 558, in get
raise self._value
cPickle.PicklingError: Can't pickle <type 'function'>: attribute lookup __builtin__.function failed
请帮忙