简体   繁体   中英

Compositing two soundtracks with moviepy

I am trying to add an audio to a clip. Problem is it's replacing the original soundtrack with the new one ie pond5.wav. I first concat some small clips, each of these clips contain original soundtrack. The end result doesn't contain the original soundtracks, however. I need both original and new soundtracks (the new sound track's volume must be lower than the original). I need clues how to modify the following code and composite two soundtracks.

media = "promo"

clips = [VideoFileClip(clip) 
         for clip in get_filepaths(media) 
         if ntpath.basename(clip).startswith('clip_')
         and ntpath.basename(clip).endswith('.mp4')
         ] 

vclip = concatenate_videoclips([clips[0],
                                clips[1].crossfadein(0.3),
                                clips[2].crossfadein(0.3),
                                clips[3].crossfadein(0.3),
                                ], 
                               method="compose", 
                               padding=-0.3)

audio = AudioFileClip(os.path.join(folder,"pond5.wav"))
audio = audio.audio_loop(duration=vclip.duration)
cc = vclip.set_audio(audio
                     .set_duration(vclip.duration)
                     .volumex(0.3)
                     .audio_fadein(1.0)
                     .audio_fadeout(1.0)
                     )
cc.write_videofile(os.path.join(folder, "demo.mp4"), fps=60, codec="libx264", bitrate="20000k", threads=6)

You need to create a composite audio clip from vclip 's audio and set this as the audio. Something like (did not test) :

    composite = CompositeAudioClip(clicp.audio + [audio])
    # set audio returns a new instance...
    final = vclip.set_audio(composite)
    final.writevideofile(...)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM