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 35e6b16

Browse files
add blog
1 parent b9359b4 commit 35e6b16

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed

‎doudou/2022-04-25-ffmpeg/app.py‎

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# coding:utf-8
2+
3+
import ffmpeg
4+
5+
"""
6+
path = 'main.mp4'
7+
## 获取视频信息
8+
probe = ffmpeg.probe(path)
9+
video_stream = next((stream for stream in probe['streams'] if stream['codec_type'] == 'video'), None)
10+
width = int(video_stream['width'])
11+
height = int(video_stream['height'])
12+
print(width, height)
13+
print(video_stream)
14+
15+
## 视频镜像
16+
ffmpeg.input(path).hflip().output('output.mp4').run()
17+
ffmpeg.input(path).vflip().output('output.mp4').run()
18+
19+
## 添加底板
20+
main = ffmpeg.input(path)
21+
logo = ffmpeg.input('logo.png')
22+
ffmpeg.filter([logo, main], 'overlay', 0, 500).output('out.mp4').run()
23+
24+
## 添加水印
25+
main = ffmpeg.input(path)
26+
logo = ffmpeg.input('logo.png')
27+
ffmpeg.filter([main, logo], 'overlay', 0, 500).output('out.mp4').run()
28+
29+
## 视频截取
30+
ffmpeg.input(path).trim(start_frame=10, end_frame=20).output('out3.mp4').run()
31+
32+
## 视频拼接
33+
base = ffmpeg.input(path)
34+
ffmpeg.concat(
35+
base.trim(start_frame=10, end_frame=20),
36+
base.trim(start_frame=30, end_frame=40),
37+
base.trim(start_frame=50, end_frame=60)
38+
).output('out3.mp4').run()
39+
"""

‎doudou/README.md‎

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

99
## 实例代码
1010

11+
[ffmpeg](https://github.com/JustDoPython/python-examples/tree/master/doudou/2022-04-25-ffmpeg)
12+
1113
[视频号视频下载](https://github.com/JustDoPython/python-examples/tree/master/doudou/2022-03-23-channel)
1214

1315
[用 Python 在 Excel 中画画](https://github.com/JustDoPython/python-examples/tree/master/doudou/2021-12-31-img-excel)

0 commit comments

Comments
(0)

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