-
Notifications
You must be signed in to change notification settings - Fork 138
/
视频特殊处理.py
153 lines (121 loc) · 3.32 KB
/
视频特殊处理.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
#!/usr/bin/env python
# encoding: utf-8
"""
@version: v1.0
@author: xag
@license: Apache Licence
@contact: [email protected]
@site: http://www.xingag.top
@software: PyCharm
@file: file_utils.py
@time: 2020-06-15 09:35
@description:公众号:AirPython
"""
import hashlib
from moviepy.editor import *
def get_file_md5(file_path):
"""
获取文件的MD5值
:param file_path:
:return:
"""
with open(file_path, 'rb') as file:
temp_md5 = hashlib.md5()
temp_md5.update(file.read())
hash_code = str(temp_md5.hexdigest()).lower()
return hash_code
def modify_file_md5(file_path):
"""
修改文件的md5值
:param file_path:
:return:
"""
with open(file_path, 'a') as file:
file.write("####&&&&")
def get_file_md5_2(file_path):
"""
分段读取,获取文件的md5值
:param file_path:
:return:
"""
with open(file_path, 'rb') as file:
md5_obj = hashlib.md5()
while True:
buffer = file.read(8096)
if not buffer:
break
md5_obj.update(buffer)
hash_code = md5_obj.hexdigest()
md5 = str(hash_code).lower()
return md5
def handle_frame(image_frame):
"""
处理图片帧
:param image_frame:图片帧
:return:
"""
image_frame_result = image_frame * 1.2
# 如果颜色值超过255,直接设置为255
image_frame_result[image_frame_result > 255] = 255
return image_frame_result
def increase_video_brightness(file_path):
"""
增加视频整体亮度
:param file_path:源视频路径
:return:
"""
video = VideoFileClip(file_path)
result = video.fl_image(handle_frame)
file_path_new = "/Users/xingag/Desktop/new.mp4"
result.write_videofile(file_path_new)
def increase_video_brightness2(file_path):
"""
增加视频整体亮度2
:param file_path:源视频路径
:return:
"""
# 调整系数值
coefficient_value = 1.2
video = VideoFileClip(file_path)
file_path_new = "/Users/xingag/Desktop/new.mp4"
video.fx(vfx.colorx, coefficient_value).write_videofile(file_path_new)
def decrease_video_brightness(file_path):
"""
降低亮度
:param file_path:
:return:
"""
# 调整系数值
coefficient_value = 0.8
video = VideoFileClip(file_path)
file_path_new = "/Users/xingag/Desktop/new.mp4"
video.fx(vfx.colorx, coefficient_value).write_videofile(file_path_new)
def change_video_bhd(file_path):
"""
黑白处理
:param file_path:
:return:
"""
video = VideoFileClip(file_path)
file_path_new = "/Users/xingag/Desktop/new.mp4"
video.fx(vfx.blackwhite).write_videofile(file_path_new)
def change_video_todo(file_path):
"""
先获取图片帧,单张进行处理,然后合成
:param file_path:
:return:
"""
pass
if __name__ == "__main__":
file_path = r'/Users/xingag/Desktop/1.mp4'
# print(get_file_md5_2(file_path))
# modify_file_md5(file_path)
# print(get_file_md5_2(file_path))
# 2、增加亮度
# increase_video_brightness(file_path)
# increase_video_brightness2(file_path)
# 降低亮度
# decrease_video_brightness(file_path)
# 3、饱和度
change_video_bhd(file_path)
# 注意:更多复杂的操作可以参考之前的文章