代码:
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)
分类:
python小程序
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 【译】Visual Studio 中新的强大生产力特性
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 【设计模式】告别冗长if-else语句:使用策略模式优化代码结构