代码:
import subprocess def replace_audio_with_ffmpeg(video_path, audio_path, output_path): # 构建ffmpeg命令 command = [ 'ffmpeg', '-i', video_path, # 输入视频文件 '-an', # 禁用输入视频的音频 '-i', audio_path, # 输入新的音频文件 '-c:v', 'copy', # 复制视频流 '-c:a', 'aac', # 使用AAC编码音频 '-strict', '-2', # 允许使用实验性编码器 '-y', # 覆盖输出文件 output_path # 输出文件 ] # 执行命令 try: subprocess.run(command, check=True) print(f"Video with new audio saved to {output_path}") except subprocess.CalledProcessError as e: print(f"An error occurred: {e}") if __name__ == "__main__": file_name = r"C:\caijian\美洲豹\原" # 旧视频文件路径 video_path = r'%s\01毛发知识与Psystem基础.mp4'% file_name # 新音频文件路径 audio_path = r'%s\zh-cn-1.m4a'% file_name # 输出视频文件路径 output_path = r'%s_new.mp4'% video_path replace_audio_with_ffmpeg(video_path, audio_path, output_path)
标签:__,成新,替换成,video,output,视频文件,path,audio From: https://www.cnblogs.com/jingzaixin/p/18447478