python中的媒体转换器命令行程序。
converter-cli的Python项目详细描述
转换器cli
python中的媒体转换器命令行程序。
目的
这是用于转换媒体文件的自定义python(3)cli
我这样做是为了方便将我的媒体文件转换为不同的 格式、比特率和其他不需要记住的ffmpeg语法 每个案子。
它并没有覆盖所有的ffmpeg选项(我只是想要一些),但是可以添加它们。
安装
即插即用:
$ pip3 install converter-cli
如果你想玩弄代码,我建议你先创建一个虚拟环境(python3):
$ mkvirtualenv --python=/usr/local/bin/python3 converter-cli
然后:
$ git clone https://github.com/patillacode/converter-cli.git
$ cd converter-cli
$ pip install -r requirements-dev.txt
$ python setup.py develop
单元测试
$ py.test tests
用法
我们的想法是让cli向您询问工作所需的信息,
你唯一应该知道的是如果你感兴趣的是转换音频
您应该使用audio
命令:
$ converter-cli audio
如果你有兴趣转换视频文件,那么
使用命令video
:
$ converter-cli video
完整的命令列表如下:
Usage:
converter-cli hello
converter-cli audio
converter-cli audio [-m | --multiple] [--verbose] [-n | --no-confirm]
converter-cli video
converter-cli video [-m | --multiple] [--verbose] [-n | --no-confirm]
converter-cli -h | --help
converter-cli -v | --version
Options:
-h --help Show this screen.
-v --version Show version.
-m --multiple Convert all files within a given folder
-n --no-confirm Avoid user confirmation before converting
--verbose Redirect converting process to stdout
默认情况下,cli将用于转换一个文件,但是-m
/--multiple
选项将允许您同时执行多个文件:
$ converter-cli video -m
此外,默认情况下,cli将隐藏ffmpeg命令的输出,以支持更可读的自定义行,
除非指定了--verbose
选项:
$ converter-cli audio --verbose
示例
将.wav音频文件转换为.mp3文件:
$ converter-cli audio
您将看到以下内容:
Please choose an option:
1) Convert to .mp3 (320k)
2) Convert to .wav
Enter option number:
在本例中插入选项号1
,将显示:
Enter path to source file:
在这里,我们将输入类似/path/to/file/music.wav
的内容并按回车键。
Enter path to destination folder (Enter for same folder as source):
注意,如果单击enter而不指定任何路径,则输出文件将
与源文件在同一目录中/path/to/file/
接下来会发生的事情是(除非给出了--no-confirm option
):
WARNING
Output file will be called the same as the original
with the proper extension (.mp4, .mp3, ...) which
may cause an overwrite - YOU HAVE BEEN WARNED
You are about to convert file /path/to/file/music.wav into a .mp3 file to be saved in folder /path/to/file/
Please confirm action above [y/n]:
我添加了带有警告消息的确认过程,让用户可以选择查看将要发生的事情, 我可能会在将来添加一个选项来绕过这个问题。
您可以按enter键,或者键入y
并按enter键,任何其他操作都将停止进程。
一旦接受,将显示:
Converting source /path/to/file/music.wav into output /path/to/file/music.mp3 ...
(っ◕‿◕)っ Conversion completed ⊂(´・◡・⊂ )∘˚
如您所见,cli要求用户提供所有所需的数据,并向用户提供正在发生的事情的显式消息。 其余的命令都有相同的流程,只需阅读它所要求的:)
演示
依赖关系
贡献
请随时报告任何错误或提交功能请求。
也欢迎拉取请求。