zoukankan      html  css  js  c++  java
  • 有趣的python- 为视频加水印

    #!/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()
    
    
  • 相关阅读:
    HDU 4975 A simple Gaussian elimination problem.
    HDU 4888 Redraw Beautiful Drawings
    ZOJ 3795 Grouping
    HDU 4971 A simple brute force problem.
    ERROR: unable to bind listening socket for address ’127
    linux命令
    有关nginx的配置文件 之server
    CentOS LNMP环境搭建 各版本
    PHP扩展安装方法
    Nginx如何配置虚拟主机?
  • 原文地址:https://www.cnblogs.com/sunxiuwen/p/13664239.html
Copyright © 2011-2022 走看看