有趣的python- 為視訊加水印
阿新 • • 發佈:2020-09-14
#!/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()