python 澶氭瑙嗛娣峰壀浠g爜


import os
from moviepy.editor import VideoFileClip
 
def mix_clips(input_video_paths, output_path, transition_duration=2):
    """
    澶氭瑙嗛娣峰壀鍑芥暟锛屽彲浠ユ寚瀹氳繃娓℃椂闀裤
    :param input_video_paths: 杈撳叆瑙嗛璺緞鍒楄〃銆
    :param output_path: 杈撳嚭瑙嗛鏂囦欢璺緞銆
    :param transition_duration: 杩囨浮鎸佺画鏃堕棿锛岄粯璁や负2绉掋
    """
    clips = [VideoFileClip(video_path) for video_path in input_video_paths]
    first_clip = clips[0]
    clips = [first_clip] + [clips[-1].fx(vfx.crossfadein, transition_duration)] + \
            [clips[i].fx(vfx.crossfadeout, transition_duration).set_start(clips[i-1].duration) for i in range(1, len(clips))]
    final_clip = concatenate_videoclips(clips)
    final_clip.write_videofile(output_path)
 
# 浣跨敤绀轰緥
input_videos = ['video1.mp4', 'video2.mp4', 'video3.mp4']  # 杈撳叆瑙嗛鏂囦欢鍒楄〃
output_video = 'output.mp4'  # 杈撳嚭瑙嗛鏂囦欢
mix_clips(input_videos, output_video)



杩欐浠g爜浣跨敤浜唌oviepy搴撴潵瀹炵幇澶氭瑙嗛鐨勬贩鍓紝骞朵笖鍦ㄥ悇娈佃棰戜箣闂村姞涓婁簡浜ゅ弶娣″叆娣″嚭鏁堟灉銆備綘鍙互閫氳繃璋冩暣transition_duration鍙傛暟鏉ヨ缃繃娓$殑鏃堕暱銆傝繖涓嚱鏁板彲浠ュ鐞嗕换鎰忔暟閲忕殑瑙嗛鏂囦欢锛屽彧闇瑕佸皢瀹冧滑鐨勮矾寰勪綔涓轰竴涓垪琛ㄤ紶閫掔粰input_video_paths鍙傛暟銆

浠ヤ笂灏辨槸python 澶氭瑙嗛娣峰壀浠g爜鐨勮缁嗗唴瀹癸紝鏇村淇℃伅璇峰叧娉∣D浜戝叾瀹冪浉鍏虫枃绔狅紒



鏈枃URL锛http://www.odweb.cn/news_show.html?id=301