Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ca95584

Browse files
committed
视频写入水印
1 parent 913f339 commit ca95584

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

pyfile/file_unique_hash.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
import datetime
22
import hashlib
33
import os
4+
import re
5+
6+
import moviepy.editor as mp
47

58

69
def get_file_hash(src_file):
@@ -26,6 +29,23 @@ def get_bytes_hash(src_file, Bytes=1024):
2629
return ret
2730

2831

32+
def water_mark(src_dir):
33+
video = mp.VideoFileClip(src_dir)
34+
35+
logo = (mp.ImageClip("watermark.png")
36+
.set_duration(video.duration) # 时长
37+
.resize(height=100) # 水印高度,等比缩放
38+
.margin(left=10, top=10, opacity=1) # 水印边距和透明度
39+
.set_pos(("left", "top"))) # 水印位置
40+
41+
result = mp.CompositeVideoClip([video, logo])
42+
43+
print("开始写入水印。。。")
44+
# mp4文件默认用libx264编码, 比特率单位bps
45+
result.write_videofile(re.sub(r'.{2}\.mp4', "666666.mp4", src_dir), codec="libx264", bitrate="10000000")
46+
print("写入完成")
47+
48+
2949
def traverse_file(src_dir):
3050
start = datetime.datetime.now()
3151
file_num = 0
@@ -34,6 +54,9 @@ def traverse_file(src_dir):
3454
for file in files:
3555
file_num = file_num + 1
3656
src_file = os.path.join(root, file)
57+
if re.search(r'11\.mp4$', file) is not None:
58+
water_mark(src_file)
59+
3760
print(
3861
file + "-->file_hash-->" + get_file_hash(src_file) + "-->bytes_hash-->" + get_bytes_hash(src_file))
3962

pyfile/watermark.png

25.5 KB
Loading

0 commit comments

Comments
 (0)