MambaCodes / BeAnonymous

BeAnonymous is a Python based application with which you can generate videos in the exact same way as the one made by Anonymous.
Apache License 2.0
88 stars 11 forks source link

Slow encoding of video #5

Open hunterhogan opened 11 months ago

hunterhogan commented 11 months ago

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"
iamDyeus commented 11 months ago

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 commented 11 months ago

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.