pythonffmpeggpucpumoviepy

FFMPEG with moviepy


I'm working on something that concatenate videos and adds some titles on through moviepy.

As I saw on the web and on my on pc moviepy works on the CPU and takes a lot of time to save(render) a movie. Is there a way to improve the speed by running the writing of moviepy on GPU? Like using FFmpeg or something like this?

I didn't find an answer to that on the web, so I hope that some of you can help me. I tried using thread=4 and thread=16 but they are still very very slow and didn't change much.

My CPU is very strong (i7 10700k), but still, rendering on moviepy takes me for a compilation with a total of 8 minutes 40 seconds, which is a lot.

Any ideas?Thanks! the code doesnt realy matter but :

def Edit_Clips(self):

    clips = []

    time=0.0
    for i,filename in enumerate(os.listdir(self.path)):
        if filename.endswith(".mp4"):
            tempVideo=VideoFileClip(self.path + "\\" + filename)

            txt = TextClip(txt=self.arrNames[i], font='Amiri-regular',
                           color='white', fontsize=70)
            txt_col = txt.on_color(size=(tempVideo.w + txt.w, txt.h - 10),
                                   color=(0, 0, 0), pos=(6, 'center'), col_opacity=0.6)

            w, h = moviesize = tempVideo.size
            txt_mov = txt_col.set_pos(lambda t: (max(w / 30, int(w - 0.5 * w * t)),
                                                 max(5 * h / 6, int(100 * t))))

            sub=txt_mov.subclip(time,time+4)
            time = time + tempVideo.duration

            final=CompositeVideoClip([tempVideo,sub])

            clips.append(final)

    video = concatenate_videoclips(clips, method='compose')
    print("after")
    video.write_videofile(self.targetPath+"\\"+'test.mp4',threads=16,audio_fps=44100,codec = 'libx264')

Solution

  • in the past I was same problem and I solved that.

    You need to use this command in your code ONLY one time.

    video = CompositeVideoClip([clip1, clip2, clip3])

    and export the video:

    video.write_videofile(path_final_video)

    while the video is export, moviepy will use all your cores.

    Hope I helped :)