网站备案 几年,小程序开发外包如何约定质量,在人才网站做业务,商城网站制作报价朋友车载音乐需要MP3格式#xff0c;想要个批量转换工具
准备工作
brew install ffmpeg --HEAD或者官网下载安装ffmpeg并配置环境conda install ffmpeg 或者pip install ffmpeg-python
音频类型转换程序.py文件
exe文件在windows下打包#xff0c;dmg在macos下打包#…朋友车载音乐需要MP3格式想要个批量转换工具
准备工作
brew install ffmpeg --HEAD或者官网下载安装ffmpeg并配置环境conda install ffmpeg 或者pip install ffmpeg-python
音频类型转换程序.py文件
exe文件在windows下打包dmg在macos下打包需要更换文件路径\\为/
# windows
# 获取文件夹中所有的文件名
def getFiles(path):import osfilenames os.listdir(path)return filenamesdef trans_video_to_mp3(filePath,output_name,newTypemp3):from pydub import AudioSegment# 读取数据文件song AudioSegment.from_file(filePath)# 输出转换文件 song.export(output_name.str(newType), formatstr(newType))song None# 转换音频
def changeVideo(dataPath,newTypeFalse):print(-------Start------) import os# 如果是文件夹则执行以下操作if os.path.isdir(dataPath):outputDir r dataPath \\..\\ 输出 # 如果输出文件夹不存在则创建if not os.path.exists(outputDir):os.makedirs(outputDir) print(默认跳过.开头隐藏文件) # 遍历文件夹中所有的文件执行转换操作for file_name in getFiles(dataPath):if not file_name[0].:# 生成文件路径filePath r dataPath \\ file_nameprint(源文件路径, filePath)# 输出文件名 output_name r outputDir \\ file_nameprint(输出文件路径, output_name)# 将数据文件转换到输出文件trans_video_to_mp3(filePath, output_name,newType)# 如果是一个文件则直接转换else:print(单个文件输出到同级目录下)output_name os.path.splitext(dataPath)[0] # 将数据文件转换到输出文件夹print(输出文件路径为 , output_name.str(newType))trans_video_to_mp3(dataPath,output_name,newType) print(-----The End-----)if __name__ __main__: print(请将文件或目录地址输入控制台然后回车)path input(Enter your path: )print(音频要转换为什么格式?)newType input(Enter new type: )changeVideo(path, newType if newType else mp3)生成可执行文件
# 安装pipenv
pip install pipenv#建立虚拟环境
pipenv install
#进入虚拟环境上一步可省略,因为没有虚拟环境的话会自动建立一个
pipenv shell
# 随时查看安装的包
pip list
#安装模块
pip install pydub
#打包的模块也要安装否则会调用原有的库依旧会关联很多无用库
pip install pyinstaller
# 打包
pyinstaller -F .py文件路径 --distpath 输出文件夹
# 退出虚拟环境
exit
# 删除虚拟环境
pipenv ––rm注
可以转换常见格式如mp4、mp3、wav、flac等无法解码转换网易云QQ音乐下载的ncm、mgg等加密格式(um库被删了可以找找bushi)视频转换后只有音频 相关文章
【最新】windows电脑FFmpeg安装教程手把手详解解决pyinstaller打包exe文件过大的问题