BeAnonymous icon indicating copy to clipboard operation
BeAnonymous copied to clipboard

Slow encoding of video

Open hunterhogan opened this issue 2 years ago • 2 comments

video_generator.py creates the video using write_videofile(), which requires re-encoding the entire video. Furthermore, I think this code is recursively concatenating the video clip one clip at a time, which is inefficient, to say the least.

#Generating Stock Video 
    if (stockclip.duration < final_audio.duration):
        while (stockclip.duration < final_audio.duration):
            stockclip=concatenate_videoclips([stockclip,stockclip])

Since the video files are merely concatenated, it would be much faster to stream copy the files. I don't know how to write the command using moviepy but I know the command for FFmpeg. The following command should work for videos without the introduction. The FFmpeg wiki has an excellent explanation of concatenation. (To make it easier to read, it is split across multiple lines, but it should all be on one line.)

ffmpeg
-hide_banner 
-loglevel quiet
-an -stream_loop -1 -t final_audio.duration -i "stockclip"
-i "final_audio"
-codec:video copy 
"FinalPath"

hunterhogan avatar Sep 22 '23 18:09 hunterhogan

Yeah, am Aware that the video encoding is slow. When I first started the project, I didn't focus on efficiency. If it worked, I left it. It's great that you understood the code. Lately, I've been rewriting the entire code for better performance. I've also integrated Eleven Labs Speech for better text-to-speech. Honestly, even I found my own initial code a bit tricky to follow!

iamDyeus avatar Sep 30 '23 01:09 iamDyeus

Also, I'll make sure to enhance the video encoding in the upcoming commit, which I plan to make by the end of next month. Thanks for pointing out the FFMPEG command and resources.

iamDyeus avatar Sep 30 '23 01:09 iamDyeus