Moviepy freezes after first couple of frames after concatenation

1.2k Views Asked by At

I have been trying to build a project in which a Flask Application can automatically concatenate a selected amount of video's to a 'core video'.

User's can upload a video, which is sent to amazon s3 for storage. All video's are preprocessed by Moviepy to be an mp4 file, running on 24 fps without audio, with a resolution of 720p. After this preprocessing, the video is uploaded to amazon s3.

Of all new uploads in s3, a queue is created which an administrator can approve or delete. All approved video's end up in a list that is concatenated with a current 'core video'. This is done by using Pythons Moviepy library.

from moviepy.editor import VideoFileClip, concatenate_videoclips, AudioFileClip

videos_to_concat(VideoFileClip(core_video.s3_link))

for video in approved_videos:
    videos_to_concat.append(VideoFileClip(video.s3_link))
result = concatenate_videoclips(videos_to_concat, method=compose)

Later, some audio is added under the full duration of the video.

result_with_audio = result.set_audio(some_audio.mp3)

The problem however, is that without throwing any errors, some videos are frozen after the first couple of frames after concatenation has been successfull. A frame remains stationary for the duration of the original clip. The audio keeps playing though. When a next clip is loaded, that one either plays normally or has the same behaviour of freezing after a couple of frames. There seems to be no obvious patern.

Initially I thought the mistake might be that ffmpeg does not download video's from the normal s3 link properly, but that would not explain why the the biggest video in the beginning and some other video's get rendered correctly, and some others aren't.

Could it that this is caused by a potential difference in codecs? (libx264 vs. mpeg4)? Or is this way of accessing the files by URL and then directly feeding that to moviepy a potential cause of troubles? (VideoFileClip(https://amazon.s3.link.to.file.here.mp4) Should I try to download all files and then locally concatenating them, or am I right to assume that the current approach should work.

When inspecting the files, nothing obvious like filename, filetype, resolution seems to be the issue, the preprocessing seems to do what it should.

Would love to hear any idea's on how the corruption of the resulting concatenated video could be explained and hopefully resolved.

1

There are 1 best solutions below

0
On

Okay, I did manage to figure it out in the end. The problem was solved by downloading all video's with the boto3 client that amazon s3 provides for Python. Once downloading all video's to local storage of the webserver, concatenation worked without any issues.

I'm guessing that this might have something to do with s3 not serving the entire video file instantly through the link. In the end it seems quite logical to just use the provided s3 client to download store video's before performing any edits with moviepy.