FFMpeg overlay videos freezing with consecutive overlays

84 Views Asked by At

I'm making a program that loops through a list of mp4 videos, and one by one overlays them onto an mp4 for a given duration. The first overlay works fine and has no freezing, however all of the overlays after the first are frozen.

Here is my code:

` def add_videos_to_original_clip(self, original_clip, videos, original_clip_width, original_clip_height, overlay_zone_width, overlay_zone_height, overlay_zone_x, overlay_zone_y):

    # Sine code initializing the input video path
    
    for index, video in enumerate(videos):
        # some code initializing overlay_video_file_name and output_video
        # some code initializing overlay_top_left and overlay_top_right

        #remove the audio from the overlay video and the input video
        self.remove_audio(overlay_video_file_name, index)
        self.remove_audio(input_video, index)

        command = [
            "ffmpeg",
            "-i", input_video,
            "-i", overlay_video_file_name,
            "-filter_complex",
            f"[1:v]scale={video['width']}x{video['height']},format=yuva420p[ovrl];"
            f"[0:v][ovrl]overlay={overlay_top_left}:{overlay_top_right}:enable='between("
            f"t,{video['start_time']},{video['end_time']})'",
            "-c:a", "copy",
            output_video
        ]
        subprocess.run(command)
        
        # set the input video to the output video
        input_video = output_video`

I read that removing the audio from the mp4 files could resolve this bug, however after removing the audio, the freezing still happens.

I used the following to remove the audio: ` def remove_audio(self, original_clip, index): overlay_video_no_audio = original_clip + f'_{index}_no_audio.mp4'

    command = [
        "ffmpeg",
        "-i", original_clip,
        "-an",
        overlay_video_no_audio
    ]
    subprocess.run(command)
    
    # delete the original video
    os.remove(original_clip)
    
    # change the name of the video to the one without audio
    os.rename(overlay_video_no_audio, original_clip)

`

0

There are 0 best solutions below