0

This is the current code i have and its too slow. I am a noobie programmer and have tried to use stuff like njit but it doesn't work. I need a script that merges multiple videos faster!

from moviepy.editor import *
import os
from functools import cache
@cache 
def merge():
    vidstmp = []
    for x in os.listdir():
        try:
            if (x[0]).isnumeric():
                vidstmp.append(int(x.replace('.mp4','')))
        except:
            pass
    vidstmp.sort()
    vids = []
    for y in vidstmp:
        vids.append(f'{y}.mp4')
    clips= []
    for x in vids:
        video = VideoFileClip(x)
        clips.append(video)
    final_clip = concatenate_videoclips(clips)
    final_clip.to_videofile("output.mp4", fps=24, remove_temp=True)
  • 2
    You could try running ffmpeg cli via subprocess, there's a method shown here https://stackoverflow.com/a/11175851/202168 that can concat mp4 files without re-encoding... I guess that will be about as fast as is possible. You could also try the same idea via this Python library https://kkroening.github.io/ffmpeg-python/#ffmpeg.concat – Anentropic Jul 06 '22 at 11:28
  • Thanks a lot! the ffmpeg cli is very fast and I use os.system() to run it from python! – IAM々Unknown Jul 06 '22 at 12:40
  • @Anentropic how do we install it? Can anyone please add a guide to use python library? – Meric Ozcan Apr 15 '23 at 13:27
  • @MericOzcan https://github.com/kkroening/ffmpeg-python#installing-ffmpeg ... on a Mac I would `brew install ffmpeg` (see also https://ffmpeg.org/download.html) ... once that is installed you should be able to use the python wrapper above – Anentropic Apr 15 '23 at 18:33

0 Answers0