Esempio n. 1
0
    def _concatenate(self, clip: Clip, buffer=5):
        if self._transition == 'crossfadein':
            try:
                before_cross_part = self._final_clip.subclip(
                    t_end=self._final_clip.duration - buffer)
                before_buffer = self._final_clip.subclip(
                    t_start=self._final_clip.duration - buffer)
                after_cross_part = clip.subclip(
                    t_start=self._transition_padding)
                after_buffer = clip.subclip(
                    t_end=self._transition_padding).set_start(
                        buffer - self._transition_padding)
            except OSError:
                if buffer >= 60:
                    raise Exception('Buffer {} is very big'.format(buffer))
                self._concatenate(clip, buffer=buffer * 2)
                return

            crossfade = CompositeVideoClip([
                before_buffer,
                after_buffer.crossfadein(self._transition_padding)
            ],
                                           use_bgclip=True)
            crossfade = crossfade.set_audio(before_buffer.audio)

            self._final_clip = concatenate_videoclips(
                [before_cross_part, crossfade, after_cross_part])
        else:
            self._final_clip = concatenate_videoclips([self._final_clip, clip])
Esempio n. 2
0
# sources
video = VideoFileClip("D:\\upload\\video.mp4").subclip(0, 6).add_mask()
video = video.resize(size)

foto1 = (ImageClip("D:\\upload\\foto1.png").set_duration(3))
foto1 = foto1.resize(size)

foto2 = (ImageClip("D:\\upload\\foto2.png").set_duration(3))
foto2 = foto2.resize(size)

foto3 = (ImageClip("D:\\upload\\fotoend.jpg").set_duration(2))
foto3 = foto3.resize(size)

num = video.duration + 3

numfin = num + 3

# creating the video
videofinal = CompositeVideoClip([
    foto1,  # starts at t=0
    video.set_start(3),
    foto2.set_start(num),
    foto3.set_start(numfin)
])

background_audio_clip = AudioFileClip("D:\\upload\\audio.mp3").subclip(0, 3)
bg_music = concatenate_audioclips([background_audio_clip, video.audio])

videofinal = videofinal.set_audio(bg_music)

videofinal.write_videofile("D:\\upload\\final.mp4")