"""
利用ffmpeg快速提取视频的音频文件
"""
# 参考"https://www.cnblogs.com/CodeAndMoe/p/13360011.html window安装ffmpeg并且设置环境变量 https://zhuanlan.zhihu.com/p/118362010"
import os
def main(v_path): #v_path表示视频所在路径 生成后的MP3音频文件会在该视频文件目录中
#ffmpeg_path 这个路径是bin目录下的ffmpeg的路径标签:__,视频,ffmpeg,python,cmd,音频文件,path From: https://www.cnblogs.com/Lhptest/p/18181124
ffmpeg_path = r"J:\PC_path\idm_download\ffmpeg-master-latest-win64-gpl-shared\ffmpeg-master-latest-win64-gpl-shared\bin\ffmpeg" # ffmpeg设置好环境变量后的ffmpeg目录
audio_path = v_path.split('.')[0] + ".mp3"
# 拼接好运行ffmpeg的命令行语句
# cmd = ffmpeg_path + " -f concat -safe 0 -i " + file_txt_path + " -c copy " + result_file_path
cmd = ffmpeg_path + f" -i {v_path} -q:a 0 -map a {audio_path}"
print(cmd)
# 调用cmd命令行执行ffmpeg拼接视频
os.popen(cmd)
if __name__ == '__main__':
path = "H:\视频\电影2\【lol电影天堂www.loldytt.com】S探夏洛克.HD1280超清特效中英双字.mp4"
main(path)