随笔 - 633,  文章 - 0,  评论 - 13,  阅读 - 48万
< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

代码:

复制代码
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)
复制代码

 

posted on   大话人生  阅读(50)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 【译】Visual Studio 中新的强大生产力特性
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 【设计模式】告别冗长if-else语句:使用策略模式优化代码结构
点击右上角即可分享
微信分享提示