#!/usr/bin/env python
# _*_ coding:utf-8 _*_
# DevVersion: Python3.6.8
# Date: 2020-09-13 21:59
# Author: SunXiuWen
# PyCharm|moviepy_test
import os
import threading
import moviepy.editor as mp
# 本地視頻位置
def get_video_list(file_path):
dirs = os.listdir(file_path)
video_list = []
for i in dirs:
if i.endswith('mp4'):
# path = os.path.join(file_path, os.sep, i)
path = file_path + r'/' + i
print(path)
video_list.append(path)
return video_list, dirs
def dis_video(args, kw):
# 創建對象
video = mp.VideoFileClip(args)
# 准備log圖片
logo = (
mp.ImageClip(r"E:\head.jpg") # 圖片必須是rgb解析成3個值才行,不然報錯
.set_duration(video.duration) # 水印持續時間
.resize(height=100) # 水印的高度,會等比縮放
# .margin(left=0, right=0, top=0, opacity=1.0) # 水印的邊距與透明度
.set_pos(('left', 'center'))) # 水印的位置
final = mp.CompositeVideoClip([video, logo])
# 文件存放的路勁及文件名 mp4文件默認用libx264編碼,比特率單位bps
final.write_videofile(f"E:/save_video/{kw}")
def main():
path_ = r'E:/video_dir'
v_list, d_list = get_video_list(path_)
video_list_dir_list = zip(v_list, d_list)
for j in video_list_dir_list:
print(j)
dis_video(*j)
# t = threading.Thread(target=dis_video, args=j)
# t.start()
if __name__ == '__main__':
main()