Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit f03f93f

Browse files
committed
提交代码
1 parent 3d07b0d commit f03f93f

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

‎xianhuan/README.md‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ Python技术 公众号文章代码库
1010

1111
## 实例代码
1212

13+
[几行代码迅速提取音频,YYDS!](https://github.com/JustDoPython/python-examples/tree/master/xianhuan/extractaudio):几行代码迅速提取音频,YYDS!
14+
1315
[一行代码,生成和读取二维码!](https://github.com/JustDoPython/python-examples/tree/master/xianhuan/qrcode):一行代码,生成和读取二维码!
1416

1517
[用 Python 写最简单的摸鱼监控进程,你会吗?](https://github.com/JustDoPython/python-examples/tree/master/xianhuan/monitor):用 Python 写最简单的摸鱼监控进程,你会吗?

‎xianhuan/extractaudio/demo.py‎

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#!/usr/bin/env python3
2+
# -*- coding: utf-8 -*-
3+
"""
4+
@author: 闲欢
5+
"""
6+
#!/user/bin/env python
7+
# coding=utf-8
8+
9+
from ffmpy import FFmpeg
10+
import os
11+
import uuid
12+
13+
14+
def extract(video_path: str, tmp_dir: str, ext: str):
15+
file_name = '.'.join(os.path.basename(video_path).split('.')[0:-1])
16+
print('文件名:{},提取音频'.format(file_name))
17+
return run_ffmpeg(video_path, os.path.join(tmp_dir, '{}.{}'.format(uuid.uuid4(), ext)), ext)
18+
19+
def run_ffmpeg(video_path: str, audio_path: str, format: str):
20+
ff = FFmpeg(inputs={video_path: None},
21+
outputs={audio_path: '-f {} -vn'.format(format)})
22+
ff.run()
23+
return audio_path
24+
25+
if __name__ == '__main__':
26+
print(extract('C:/个人/视频/aaa.mp4', 'C:/个人/视频', 'wav'))

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /