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()
    
    
  • 相关阅读:
    安装Visual Studio的插件AnkhSvn
    从零开始安装 Ambari (1) -- 安装前的准备工作
    centos7 安装 mysql
    hortonworks docker 安装
    Kafka connect
    KONG -- 图形化管理(Kong Dashboard)
    KONG -- 配置 service 并添加 key-auth
    KONG 安装 (在 CentOS 7 中)
    kylin cube 构建过程
    sqoop 安装与命令
  • 原文地址:https://www.cnblogs.com/sunxiuwen/p/13664239.html
Copyright © 2011-2022 走看看