moviepy icon indicating copy to clipboard operation
moviepy copied to clipboard

Sound doubling / looping when merging clips.

Open LindaLawton opened this issue 1 year ago • 1 comments

I have a directory full of clips currently there are about 40. I'm trying to merge them into one long video its about 6 minutes long when the merge is complete


def merge_videos(video_paths, output_path):
    success = False
    try:
        videos = []
        for video in video_paths:
            videos.append(VideoFileClip(video))

        # Concatenate the video clips
        final_clip = concatenate_videoclips(videos)

        # Write the final clip to a file
        final_clip.write_videofile(output_path, codec='libx264', audio_codec='aac')
        success = True
    except Exception as e:
        # Handle any errors
        print("Error merging videos:", e)
        return False
    finally:
        # Close the clips
        final_clip.close()
        for video in videos:
            video.close()
        return success

The problem is some of the clips are getting the audio doubled. so its like its just looping the audio in the clip. Its not all of the clips that get their audio tracks looped its just some of them and i cant figure out what the issue could be.

To be clear the videos arnt doubling its just the audio track within some of the videos. I even checked to be sure im not sending the same video more then once.

['output\section_6\Intro.mp4', 'output\section_6\video_with_audio\1.mp4', 'output\section_6\video_with_audio\2.mp4', 'output\section_6\video_with_audio\3.mp4', 'output\section_6\video_with_audio\4.mp4', 'output\section_6\video_with_audio\5.mp4', 'output\section_6\video_with_audio\6.mp4', 'output\section_6\video_with_audio\7.mp4', 'output\section_6\video_with_audio\8.mp4', 'output\section_6\video_with_audio\9.mp4', 'output\section_6\video_with_audio\10.mp4', 'output\section_6\video_with_audio\11.mp4', 'output\section_6\video_with_audio\12.mp4', 'output\section_6\video_with_audio\13.mp4', 'output\section_6\video_with_audio\14.mp4', 'output\section_6\video_with_audio\15.mp4', 'output\section_6\video_with_audio\16.mp4', 'output\section_6\video_with_audio\17.mp4', 'output\section_6\video_with_audio\18.mp4', 'output\section_6\video_with_audio\19.mp4', 'output\section_6\video_with_audio\20.mp4', 'output\section_6\video_with_audio\21.mp4', 'output\section_6\video_with_audio\22.mp4', 'output\section_6\video_with_audio\23.mp4', 'output\section_6\video_with_audio\24.mp4', 'output\section_6\video_with_audio\25.mp4', 'output\section_6\video_with_audio\26.mp4', 'output\section_6\video_with_audio\27.mp4', 'output\section_6\video_with_audio\28.mp4', 'output\section_6\video_with_audio\29.mp4', 'output\section_6\video_with_audio\30.mp4', 'output\section_6\video_with_audio\31.mp4', 'output\section_6\video_with_audio\32.mp4', 'output\section_6\video_with_audio\33.mp4', 'output\section_6\video_with_audio\34.mp4', 'output\section_6\video_with_audio\35.mp4', 'output\section_6\video_with_audio\36.mp4', 'output\section_6\video_with_audio\37.mp4', 'output\section_6\video_with_audio\38.mp4', 'output\section_6\video_with_audio\39.mp4', 'output\section_6\video_with_audio\40.mp4']

LindaLawton avatar Apr 21 '24 08:04 LindaLawton

Hmmm. few things you could look at

  1. cycle through the clips and see if they have both c.duration and c.audio set, and doublecheck that the durations are accurate.
  2. pass the write_logfile=True parameter. This will print out a logfile with the same name as the output movie
  3. Try using another audio_codec? Or just not specifying it?

ninjaa avatar Apr 25 '24 00:04 ninjaa

I think it is a bug. I got the same problem. And there is a open issue from Sep 26, 2022. https://github.com/Zulko/moviepy/issues/1832

jushe avatar Dec 10 '24 09:12 jushe

Thank you for your contributions and for reporting issues in this repository. With the release of v2, which introduces significant changes to the codebase and API, we’ve reviewed the backlog of open PRs and issues. Due to the length of the backlog and the likelihood that many of these are either fixed or no longer applicable, we’ve made the decision to close all previous PRs and issues.

If you believe that any of these are still relevant to the current version or if you'd like to reopen a related discussion, please feel free to create a new issue or pull request, referencing the old one.

Thank you for your understanding and continued support!

OsaAjani avatar Jan 10 '25 21:01 OsaAjani