question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Concatenating VideoFileClip is too slow

See original GitHub issue

In our django project we are receiving a text from the user and integrating the text to 6 different parts of the the video. Below is the code we are using. It is very slow, takes more than 1 minute to load the page. Is there any way to load it faster ?

def videoView(request):
    if request.method == "POST":
        brand=request.POST["brand"]
        video = VideoFileClip("video.mp4").subclip(0,3)
        
        txt_clip = ( TextClip(brand,fontsize=40,color='black', font="Helvetica-Bold")
                     .set_position((1325,670))
                     .set_duration(3) )
        result1 = CompositeVideoClip([video, txt_clip])

        video = VideoFileClip("video.mp4").subclip(3.01,6)        
        txt_clip = ( TextClip(brand,fontsize=40,color='black')
                     .set_position((450,450))
                     .set_duration(3) )
        result2 = CompositeVideoClip([video, txt_clip]) # Overlay text on video

        video = VideoFileClip("video.mp4").subclip(6.01,9)
        txt_clip = ( TextClip(brand,fontsize=40,color='black')
                     .set_position((1305,590))
                     .set_duration(3) )
        result3 = CompositeVideoClip([video, txt_clip]) # Overlay text on video

        video = VideoFileClip("video.mp4").subclip(9.01,12)
        txt_clip = ( TextClip(brand,fontsize=40,color='black')
                     .set_position((1235,520))
                     .set_duration(3) )
        result4 = CompositeVideoClip([video, txt_clip]) # Overlay text on video

        video = VideoFileClip("video.mp4").subclip(12.01,15)
        txt_clip = ( TextClip(brand,fontsize=40,color='black')
                     .set_position((470,500))
                     .set_duration(3) )

        result5 = CompositeVideoClip([video, txt_clip]) # Overlay text on video

        video = VideoFileClip("video.mp4").subclip(15.01,18.08)
        txt_clip = ( TextClip(brand,fontsize=40,color='black')
                     .set_position((1250,510))
                     .set_duration(3) )
        result6 = CompositeVideoClip([video, txt_clip]) # Overlay text on video

        result = concatenate([result1, result2, result3, result4, result5, result6]) # Overlay text on video
        result.resize(width=480).write_videofile("media/{}.webm".format(brand) ,
        fps=5,threads=4,logger=None, audio=False) # Many options...

    else:
        brand=None
        print("Sorry,Something went wrong.")
    return render(request, 'video/video_display.html',{'brand':brand})

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:9 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
Beadsworthcommented, Jul 30, 2020

I am also experiencing prohibitively slow video-writing. See below for simple code example – 10 second clip with low-def resolution, 1FPS, ultrafast setting takes 40 seconds to render. This is on a computer with 4.0 GHz, 4 core CPU & 32GB RAM.

import moviepy.editor

input_path = r'some\input\path.mp4'
output_path = r'some\output\path.mp4'

clip1 = moviepy.editor.VideoFileClip(filename=input_path).subclip(t_start=0, t_end=10)

clip1.write_videofile(output_path, preset='ultrafast', fps=1, audio=False)
0reactions
keikorocommented, Oct 11, 2022

Closing this issue as we haven’t heard back from OP since 2019 and the suggestions above sound like useful workarounds.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Concat videos too slow using Python MoviePY - Stack Overflow
Is there anyway I can speed this process up ? padding = 10 # padding option video_clips = [VideoFileClip(video_dir + video) for video...
Read more >
combine list of video into single video ffmpeg-python - Reddit
I am trying to trying to combine a list of multiple videos into one video file. Currently I am using moviepy which is...
Read more >
How to be efficient with MoviePy
Press Escape abort the previewing. Note that if the clip is complex and your computer not fast enough, the preview will appear slowed...
Read more >
Solved: Python Error - Experts Exchange
Hi Guys I'm using Python 3.8.1 and below is a script I use import glob import numpy as np # for numerical operations...
Read more >
Moviepy TextClip
from moviepy.editor import VideoFileClip, concatenate_videoclips Define two ... the merging of two videos is possible using Python and that too without any ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found