当前位置:   article > 正文

Python + Moviepy编辑视频_python import moviepy.editor as mp

python import moviepy.editor as mp

安装moviepy:

pip install moviepy==1.0.0
  • 1

1.视频加水印

import moviepy.editor as mp

# 待加水印的视频
src = r'D:\Users\PC3\Desktop\t\1.mp4'
# 加好水印的存储目标文件
dst = r'D:\Users\PC3\Desktop\t\2.mp4'
#  水印地址
logo_png = r'D:\Users\PC3\Desktop\t\logo.png'

video = mp.VideoFileClip(src)

logo = (mp.ImageClip(logo_png)
          .set_duration(video.duration)  # 水印持续时间
          .resize(height=100)  # 水印的高度,会等比缩放
          .margin(right=0, top=0, opacity=100)  # 水印边距和透明度
          .set_pos(("left","top")))  # 水印的位置

final = mp.CompositeVideoClip([video, logo])

# mp4文件默认用libx264编码, 比特率单位bps
final.write_videofile(dst, codec="libx264", bitrate="10000000")
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21

2. 视频固定位置加色块

from moviepy.editor import *
# 待加水印的视频
src = r'D:\Users\PC3\Desktop\t\1.mp4'
# 加好水印的存储目标文件
dst = r'D:\Users\PC3\Desktop\t\2.mp4'

video = VideoFileClip(src)
mask = (ColorClip((300,100),(225,225,225))
        .set_position((0,5))
        .set_duration(video.duration))
CompositeVideoClip([video,mask]).write_videofile(dst)
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/菜鸟追梦旅行/article/detail/80446
推荐阅读
相关标签
  

闽ICP备14008679号