-
2021-05-17 15:13:14
moviepy vfx,当前版本:2.0.0.dev2,非特殊说明即在原视频上进行变化
目录
moviepy.video.fx.accel_decel 变速
moviepy.video.fx.blackwhite 黑白特效
moviepy.video.fx.even_size 尺寸均匀(剪裁视频像素为偶数)
moviepy.video.fx.fadein\fadeout 淡入淡出
moviepy.video.fx.freeze_region\freeze 冷冻特效
moviepy.video.fx.gamma_corr 视频剪辑的伽玛校正
moviepy.video.fx.headblur 局部模糊特效
moviepy.video.fx.invert_colors 色彩反转
moviepy.video.fx.lum_contrast 亮度、对比度调整
moviepy.video.fx.make_loopable 结尾逐渐淡入使自己可循环
moviepy.video.fx.mask_and\mask_or\mask_color遮罩
moviepy.video.fx.mirror_x\mirror_y镜像
moviepy.video.fx.painting 油画特效
moviepy.video.fx.time_mirror(倒放)time_symmetrize(正播倒播自动合成)
vfx调用方法
from moviepy.editor import VideoFileClip, vfx video = VideoFileClip('demo.mp4', audio=False).subclip(0, 3) factor = 2 # 倍速播放倍数 final_duration = 1 # 倍速播放持续时间 ,可以为空表使全部 # 方式一 newclip = (video .fx(vfx.speedx, factor , final_duration) ) # 方式二 newclip = vfx.speedx(video, factor, final_duration) newclip.preview()
moviepy.video.fx.accel_decel 变速
def accel_decel(clip, new_duration=None, abruptness=1.0, soonness=1.0): """ new_duration:最后视频时长,默认是clip原时长 abruptness:加速时间,(>-1 and <0)加速降速(0)无影响(>0)降速加速 soonness:加速持续时间,(0<soonness < inf) """ pass
moviepy.video.fx.blackwhite 黑白特效
def blackwhite(clip, RGB=None, preserve_luminosity=True): """ RGB:可选"CRT_phosphor",一组特殊值:[0.2125, 0.7154, 0.0721] preserve_luminosity:是否保持亮度,即preserve_luminosity是否与RGB的和保持为1 """ pass
moviepy.video.fx.blink 闪烁特效
def blink(clip, d_on, d_off): """ 仅在composite clips中生效 d_on:每d_on秒显示 d_off:没s_off秒消失 (返回一个新剪辑(clip),不在原剪辑上操作) """ pass
moviepy.video.fx.colorx 色彩增幅
def colorx(clip, factor): """ factor:增幅系数 """ pass
moviepy.video.fx.crop 裁剪
def crop(clip, x1=None, y1=None, x2=None, y2=None, width=None, height=None, x_center=None, y_center=None,): """ 可以任意参数值组合完成裁剪... x1、y1表示裁剪区域的左上角坐标 x2、y2表示裁剪区域的右下角坐标 width、height表示裁剪区域宽度、高度 x_center、y_center表示裁剪区域中心坐标 (所有的坐标都以像素为单位,值为浮点数) """ pass
moviepy.video.fx.even_size 尺寸均匀(剪裁视频像素为偶数)
def even_size(clip): """ Crops the clip to make dimensions even. """ pass
moviepy.video.fx.fadein\fadeout 淡入淡出
def fadein(clip, duration, initial_color=None): """ duration:变化时长 initial_color:初始颜色(介于0和1之间的数字) """ pass def fadeout(clip, duration, final_color=None): """ duration:变化时长 final_color:终止颜色(介于0和1之间的数字) """ pass
moviepy.video.fx.freeze_region\freeze 冷冻特效
# 局部冷冻特效 def freeze_region(clip, t=0, region=None, outside_region=None, mask=None): """ t:冻结时刻 region:冻结区域 outside_region:非冻结区域 mask: """ pass # 冷冻特效 def freeze(clip, t=0, freeze_duration=None, total_duration=None, padding_end=0): """ t: freeze_duration:冻结持续时间 total_duration:总持续时间 padding_end: """ pass
moviepy.video.fx.gamma_corr 视频剪辑的伽玛校正
def gamma_corr(clip, gamma): """ gamma:CRT的影像亮度呈现线性 """ pass
moviepy.video.fx.headblur 局部模糊特效
def headblur(clip, fx, fy, r_zone, r_blur=None): """ fx、fy:模糊原点坐标 r_zone:模糊半径 r_blur:模糊强度 """ pass
moviepy.video.fx.invert_colors 色彩反转
def invert_colors(clip): pass
moviepy.video.fx.loop 循环
def loop(clip, n=None, duration=None): """ n:循环次数 duration:持续时间 """ pass
moviepy.video.fx.lum_contrast 亮度、对比度调整
def lum_contrast(clip, lum=0, contrast=0, contrast_thr=127): """ lum:亮度 contrast:对比度 contrast_thr: """ pass
moviepy.video.fx.make_loopable 结尾逐渐淡入使自己可循环
def make_loopable(clip, cross): """ cross:淡入持续时间 """
moviepy.video.fx.margin 页边距
def margin( clip, mar=None, left=0, right=0, top=0, bottom=0, color=(0, 0, 0), opacity=1.0 ): """ mar:外边框的宽度像素,mar指定了有效值,left、right、top、bottom设定不起作用 left,right,top,bottom:边框左、右、顶和底的宽度 color:边框颜色 opacity:边框透明度,0完全透明,1完全不透明 """ pass
moviepy.video.fx.mask_and\mask_or\mask_color遮罩
def mask_and(clip, other_clip): """ other_clip: """ pass def mask_or(clip, other_clip): """ other_clip: """ pass def mask_color(clip, color=None, thr=0, s=1): """ color: thr: s: """ pass
moviepy.video.fx.mirror_x\mirror_y镜像
def mirror_x(clip, apply_to="mask"): pass def mirror_y(clip, apply_to="mask"): pass
moviepy.video.fx.painting 油画特效
def painting(clip, saturation=1.4, black=0.006): """ saturation: black: """ pass
moviepy.video.fx.resize 缩放
def resize(clip, newsize=None, height=None, width=None, apply_to_mask=True): pass
moviepy.video.fx.rotate 旋转
def rotate(clip, angle, unit="deg", resample="bicubic", expand=True): pass
moviepy.video.fx.scroll 滚动
def scroll( clip, w=None, h=None, x_speed=0, y_speed=0, x_start=0, y_start=0, apply_to="mask" ): pass
moviepy.video.fx.speedx 倍速
def speedx(clip, factor=None, final_duration=None): pass
moviepy.video.fx.supersample
def supersample(clip, d, nframes): """ d: nframes: """ pass
moviepy.video.fx.time_mirror(倒放)time_symmetrize(正播倒播自动合成)
def time_mirror(self): pass def time_symmetrize(clip): pass
更多相关内容 -
Python视频编辑库MoviePy的使用
2020-12-20 14:03:01moviepy官网: https://pypi.org/project/moviepy/ 是一个用于视频编辑的Python库:切割、连接、标题插入、视频合成、非线性编辑,视频处理和定制效果的创建。 Github: https://github.com/Zulko/moviepy MoviePy ... -
moviepy,一个Python写的视频处理库-python开发
2021-06-18 17:56:17moviepy,一个Python写的视频处理库。包括常见的视频切割,拼接,插入标题等,甚至可以做一些非线编辑,特效等等。可以读取和写入所有最常见的音频和视频格式,包括GIF。 MoviePy MoviePy(完整文档)是一个用于视频... -
moviepy音视频开发:audio_fadein、fadeout实现声音淡入淡出.rar
2021-09-16 22:20:45moviepy音视频开发:audio_fadein、fadeout实现声音淡入淡出.rar -
moviepy音视频剪辑:使用mask遮罩剪辑实现叠加透明效果详解.rar
2021-09-16 22:25:19moviepy音视频剪辑:使用mask遮罩剪辑实现叠加透明效果详解.rar -
moviepy音视频开发:音频拼接函数concatenate_audioclips介绍.rar
2021-09-16 22:20:49moviepy音视频开发:音频拼接函数concatenate_audioclips介绍.rar -
moviepy
2020-12-04 03:28:55MoviePy MoviePy (fulldocumentation) is a Pythonlibrary for video editing: cutting, concatenations, title insertions, videocompositing (a.k.a. non-linear editing), video processing, and creation ofcu.....MoviePy
MoviePy (full
documentation
) is a Python
library for video editing: cutting, concatenations, title insertions, video
compositing (a.k.a. non-linear editing), video processing, and creation of
custom effects. See the
gallery
for some examples of use.
MoviePy can read and write all the most common audio and video formats,
including GIF, and runs on Windows/Mac/Linux, with Python 2.7+ and 3 (or only
Python 3.4+ from v.1.0). Here it is in action in an IPython notebook:
Example
In this example we open a video file, select the subclip between t=50s and
t=60s, add a title at the center of the screen, and write the result to a new
file:
from moviepy.editor import *
video = VideoFileClip("myHolidays.mp4").subclip(50,60)
# Make the text. Many more options are available.
txt_clip = ( TextClip("My Holidays 2013",fontsize=70,color='white')
.set_position('center')
.set_duration(10) )
result = CompositeVideoClip([video, txt_clip]) # Overlay text on video
result.write_videofile("myHolidays_edited.webm",fps=25) # Many options...
Installation
MoviePy depends on the Python modules
Numpy
,
imageio
,
Decorator
, and
tqdm
, which will be automatically
installed during MoviePy's installation. The software FFMPEG should be
automatically downloaded/installed (by imageio) during your first use of
MoviePy (installation will take a few seconds). If you want to use a specific
version of FFMPEG, follow the instructions in
config_defaults.py
. In case of
trouble, provide feedback.
Installation by hand:
download the sources, either from
PyPI
or, if you want the development
version, from
GitHub
, unzip everything
into one folder, open a terminal and type:
$ (sudo) python setup.py install
Installation with pip:
if you have
pip
installed, just type this in a
terminal:
$ (sudo) pip install moviepy
If you have neither
setuptools
nor
ez_setup
installed, the command above
will fail. In this case type this before installing:
$ (sudo) pip install ez_setup
Optional but useful dependencies
You can install
moviepy
with all dependencies via:
$ (sudo) pip install moviepy[optional]
ImageMagick
is not strictly
required, but needed if you want to incorporate texts. It can also be used as
a backend for GIFs, though you can also create GIFs with MoviePy without
ImageMagick.
Once you have installed ImageMagick, it will be automatically detected by
MoviePy,
except on Windows!
Windows users, before installing MoviePy by
hand, need to edit
moviepy/config_defaults.py
to provide the path to the
ImageMagick binary, which is called convert. It should look like this:
IMAGEMAGICK_BINARY = "C:\\Program Files\\ImageMagick_VERSION\\convert.exe"
PyGame
is needed for video and sound
previews (not relevant if you intend to work with MoviePy on a server but
essential for advanced video editing by hand).
For advanced image processing, you will need one or several of the following
packages:
The Python Imaging Library (PIL) or, even better, its branch
Pillow
.
Scipy
(for tracking, segmenting, etc.) can be used to resize video clips if PIL and OpenCV are not installed.
Scikit Image
may be needed for some advanced image manipulation.
OpenCV 2.4.6
or a more recent version (one that provides the package
cv2
) may be needed for some advanced image manipulation.
Once you have installed it, ImageMagick will be automatically detected by
MoviePy, (except for windows users and Ubuntu 16.04LTS users).
For Windows users, before installing MoviePy by hand, go into the
moviepy/config_defaults.py
file and provide the path to the ImageMagick
binary called
magick
. It should look like this:
IMAGEMAGICK_BINARY = "C:\\Program Files\\ImageMagick_VERSION\\magick.exe"
If you are using an older version of ImageMagick, keep in mind the name of the
executable is not
magick.exe
but
convert.exe
. In that case, the
IMAGEMAGICK_BINARY property should be
C:\\Program
Files\\ImageMagick_VERSION\\convert.exe
For Ubuntu 16.04LTS users, after installing MoviePy on the terminal,
IMAGEMAGICK will not be detected by moviepy. This bug can be fixed. Modify the
file in this directory: /etc/ImageMagick-6/policy.xml, comment out the
statement
.
PyGame
is needed for video and sound
previews (useless if you intend to work with MoviePy on a server but really
essential for advanced video editing
by hand
).
For instance, using the method
clip.resize
requires that at least one of
Scipy, PIL, Pillow or OpenCV is installed.
Documentation
Running build_docs has additional dependencies that require installation.
$ (sudo) pip install moviepy[docs]
The documentation can be generated and viewed via:
$ python setup.py build_docs
You can pass additional arguments to the documentation build, such as clean
build:
$ python setup.py build_docs -E
More information is available from the
Sphinx
documentation.
New in 1.0.0: Progress bars and messages with Proglog
Non-backwards-compatible changes were introduced in 0.2.3.6 to manage progress
bars and messages using
Proglog
, which enables to display nice progress bars in the console
as well as in a Jupyter notebook or any user interface, like a website.
To display notebook friendly progress bars, first install IPyWidgets:
sudo pip install ipywidgets
sudo jupyter nbextension enable --py --sys-prefix widgetsnbextension
Then at the beginning of your notebook enter:
import proglog
proglog.notebook()
Have a look at the Proglog project page for more options.
Running Tests
The testing suite can be executed via:
$ python setup.py test
Running the test suite in this manner will install the testing dependencies.
If you opt to run the test suite manually, you can install the dependencies
via:
$ (sudo) pip install moviepy[test]
Contribute
MoviePy is open-source software originally written by
Zulko
and released under the MIT licence. The
project is hosted on
GitHub
, where
everyone is welcome to contribute, ask for help or simply give feedback.
Please read our
Contributing
Guidelines
for
more information about how to contribute!
You can also discuss the project on
Reddit
or
Gitter
. These are preferred over GitHub
issues for usage questions and examples.
We have a list of labels used in our
Label
Wiki
. The 'Pull Requests'
labels are well defined, and all PRs should fall under exactly one of these.
The 'Issues' labels are less precise, and may not be a complete list.
Maintainers
Zulko
(owner)
?tburrows13?
(https://github.com/tburrows13)
?earney?
(https://github.com/earney)
Kay
?kerstin?
(https://github.com/kerstin)
?mbeacom?
(https://github.com/mbeacom)
-
moviepy音视频剪辑:TextClip.list(font)和search搜索字体报错
2021-09-16 22:25:17UnicodeDecodeError:utf-8 codec cannott decode byte 问题 -
moviepy_matplotlib:关于 matplotlib 的问题
2021-07-10 12:51:15我将使用 Matplotlib 的动画模块编写视频与使用我的库 MoviePy 而不是 Animation.save() 编写相同的 Matplotlib 视频进行了比较。 有关详细信息和结果,请参见。 事实证明,MoviePy 生成的动画质量更好... -
MoviePy
2020-12-10 10:58:52软件简介MoviePy 是一个用于视频编辑的Python库:剪切,连接,标题插入,视频合成(也称为非线性编辑),视频处理和创建自定义效果。MoviePy 可以读写所有最常见的音频和视频格式,包括 GIF,并可以在Windows / Mac / ...软件简介
MoviePy 是一个用于视频编辑的Python库:剪切,连接,标题插入,视频合成(也称为非线性编辑),视频处理和创建自定义效果。
MoviePy 可以读写所有最常见的音频和视频格式,包括 GIF,并可以在Windows / Mac / Linux上运行,使用Python
2.7+和3.在IPython笔记本中。
例如:我们打开一个视频文件,在t = 50s和t = 60s之间选择子剪辑,在屏幕中心添加一个标题,并将结果写入一个新文件:
from moviepy.editor import *
video = VideoFileClip("myHolidays.mp4").subclip(50,60)
# Make the text. Many more options are available.
txt_clip = ( TextClip("My Holidays 2013",fontsize=70,color='white')
.set_position('center')
.set_duration(10) )
result = CompositeVideoClip([video, txt_clip]) # Overlay text on video
result.write_videofile("myHolidays_edited.webm",fps=25) # Many options...
-
moviepy音视频剪辑基类VideoClip的write_gif方法
2021-09-16 22:20:45opt、fuzz、dispose、colors、loop等参数的作用.rar -
使用moviepy将视频转换成音频.py
2021-08-11 16:19:25几行代码实现视频转音频 -
moviepy音视频剪辑:mask clip遮罩剪辑、遮片、蒙版的作用以及其包含的构成内容.rar
2021-09-16 22:25:16moviepy音视频剪辑:mask clip遮罩剪辑、遮片、蒙版的作用以及其包含的构成内容.rar -
ImageMagick7.0.8 win64 16安装包下载。使用moviepy抛ImageMagick异常问题解决
2022-06-17 06:49:12ImageMagick-7.0.8-56-Q16-x64-dll.rar是ImageMagick7.0.8的windows 64位操作系统的安装程序,解压执行即可安装。 使用ImageMagick的创建,编辑,撰写,或转换位图图像。它可以读取和写入各种格式(超过200种)的... -
deep-bgremove:使用Deeplabv3和MoviePy生成蒙版的Pytorch工具,用于从图像中移除背景(但保留人物)。...
2021-05-04 19:03:27MoviePy用于处理和I / O,它接受多种格式。 如果Cuda在系统上可用,则将使用它(您将要使用它,因为生成输出可能非常慢,尤其是对于大型视频而言)。 可以将遮罩电影放到After Effects之类的工具中,并用作Alpha... -
moviepy:使用Python进行视频编辑
2021-02-04 08:42:09moviepy:使用Python进行视频编辑 -
VideoEditor:简短的python.exe,用于通过moviepy和tkinter GUI编辑视频
2021-03-07 07:42:36简短的python.exe,用于通过moviepy和tkinter GUI编辑视频 当前唯一的活动文件是gui_basics.py 打开一个窗口,所有按钮都执行某些功能,其中一些功能当前会打印到终端上 视频帧都是相同的,因为它们仅引用正在重用... -
moviepy音视频开发:音频文件存取类AudioFileClip属性和方法介绍.rar
2021-09-16 22:20:36moviepy音视频开发:音频文件存取类AudioFileClip属性和方法介绍.rar -
moviepy音视频剪辑:视频剪辑基类VideoClip的属性及方法详解.rar
2021-09-16 22:20:43moviepy音视频剪辑:视频剪辑基类VideoClip的属性及方法详解.rar -
moviepy音视频开发:音频合成类AudioArrayClip介绍.rar
2021-09-16 22:20:48moviepy音视频开发:音频合成类AudioArrayClip介绍.rar -
moviepy音视频开发:音频合成类CompositeAudioClip介绍.rar
2021-09-16 22:20:48moviepy音视频开发:音频合成类CompositeAudioClip介绍.rar -
Moviepy音视频剪辑:视频添加雪花飘落特效.rar
2021-09-16 22:20:37Moviepy音视频剪辑:视频添加雪花飘落特效.rar -
python使用moviepy模块对视频进行操作-附件资源
2021-03-02 15:07:52python使用moviepy模块对视频进行操作-附件资源 -
moviepy音视频剪辑:追踪人脸打马赛克的三种实现方式.rar
2021-09-16 22:20:44moviepy音视频剪辑:追踪人脸打马赛克的三种实现方式.rar -
moviepy音视频剪辑:使用mask遮罩实现视频叠加透明效果.rar
2021-09-16 22:25:20moviepy音视频剪辑:使用mask遮罩实现视频叠加透明效果.rar -
moviepy音视频剪辑基类VideoClip的write_videofile方法
2021-09-16 22:20:46codec、bitrate、preset、audio_bitrate、audio_nbytes等参数的作用.rar -
在Python中使用moviepy进行视频剪辑时输出文件报错 ‘NoneType’ object has no attribute ‘stdout’问题
2020-12-20 19:07:40movipy输出文件时报错 ‘NoneType’ object has no attribute ‘stdout’问题,经确认是moviepy版本本身的bug,一般情况下不会触发,可能是执行AudioFileClip.close()时报错。 经查阅《github/Zulko/moviepy》有该... -
python moviepy 的用法,看这篇就能入门
2022-02-16 17:09:10python 中的视频处理模块,有一个叫做 moviepy,今天我们就来唠唠它。 模块安装使用如下命令即可 pip install moviepy 接下来完成第一个 Demo,为后续学习提高信心,截取视频中的一段。python 中的视频处理模块,有一个叫做 moviepy,今天我们就来唠唠它。
模块安装使用如下命令即可
pip install moviepy
接下来完成第一个 Demo,为后续学习提高信心,截取视频中的一段。
截取视频
下述代码重点使用的是
subclip
方法,但需要提前声明一个VideoFileClip
对象,VideoFileClip
类的构造函数在代码后进行说明。from moviepy.editor import * import time clip = VideoFileClip('./1644974996.mp4').subclip(10, 20) new_file = str(int(time.time())) + '_subclip.mp4' clip.write_videofile(new_file)
代码运行结果如下所示:
subclip(t_start,t_end)
方法中的时间参数可以用(t_start=10)
,以秒的时间来表示,也可以用(t_start=(1,20))
,以1分20秒的形式来表示,还可以(t_start=(0,1,20))
或者(t_start=(00:01:20))
, 以小时: 分钟: 秒的形式表示,t_end
的默认值就是视频的长度VideoFileClip
类的构造函数如下所示:__init__(self, filename, has_mask=False, audio=True, audio_buffersize=200000, target_resolution=None, resize_algorithm='bicubic', audio_fps=44100, audio_nbytes=2, verbose=False, fps_source='tbr')
其中只有
filename
为必填项,其余都为选填内容。filename
:视频文件名,一般常见格式都支持;has_mask
:是否包含遮罩;audio
:是否加载音频;audio_buffersize
:音频缓冲区大小;target_resolution
:加载后需要变换到的分辨率;resize_algorithm
:调整分辨率的算法,默认是bicubic
,可以设置为bilinear
,fast_bilinear
;audio_fps
:声音的采样频率;audio_nbytes
:采样的位数;verbose
:是否输出处理信息。
subclip(t1,t2)
方法的含义为截取t1到t2时间段内的片段。
write_videofile()
方法用于视频输出。提取A视频的音频,注入到B视频中
from moviepy.editor import * # 读取2个视频文件 videoclip_a = VideoFileClip("1644974996.mp4") videoclip_b = VideoFileClip("1644974998.mp4") # 提取A视频文件的音频部分 audio_a = videoclip_a.audio # 给B设置音频,注意视频最终合成的大小会依据长的为准 videoclip_c = videoclip_b.set_audio(audio_a) # 输出新的视频文件 videoclip_c.write_videofile("videoclip_c.mp4")
使用
VideoFileClip
对象的audio
属性,可以获取视频的音频部分,然后调用set_audio()
方法对文件进行音频设置,这里要注意一点,合成的音频和视频等于长度长的。去掉视频声音
from moviepy.editor import * video = VideoFileClip('1644974996.mp4') video = video.without_audio() video.write_videofile('cc.mp4')
without_audio()
方法见名知意 - 去除声音。获取视频信息
视频的分辨率和时间可以直接通过属性读取
from moviepy.editor import * video = VideoFileClip('1644974996.mp4') print(dir(video)) print(video.size) # 获取分辨率 print(video.duration) # 获取视频总时长
获取文件大小就比较简单了,使用
os
模块的os.path.getsize()
方法即可,得到的是字节大小。from moviepy.editor import * video = VideoFileClip('1644974996.mp4') size = os.path.getsize('1644974996.mp4') print(size)
设置视频倍速播放
读取视频,调用
speedx()
方法,其中设置要加速到的倍数。from moviepy.editor import * clip = VideoFileClip('./1644974996.mp4') video_1 = clip.speedx(2) video_1.write_videofile('sss.mp4')
截取视频封面
很多时候我们需要生成视频的封面,直接使用下述几行代码,即可实现。
from moviepy.editor import * clip = VideoFileClip('./1644974996.mp4') clip.save_frame("frame.jpg") # 保存第1帧 clip.save_frame("frame.png", t=2) # 保存2s时刻的那1帧
提取视频中的音频内容
如果想要把目标视频中的某段音频截取出来,可以使用如下代码
from moviepy.editor import * clip = VideoFileClip('./1644974996.mp4').subclip(10, 20) audioclip1 = clip.audio # 从视频对象中提取音频 audioclip1.write_audiofile('a.mp3') # 写入音频文件
截取视频中的一段,将其保存为 gif
from moviepy.editor import * clip = VideoFileClip('./1644974996.mp4').subclip(10, 20) # clip.write_gif('demo.gif',fps=15) # 生成之后的文件大 clip.write_gif('demo.gif',fps=5) # 生成之后的文件小
写在后面
到这里,相信你能顺着这个思路去学习 moviepy 更多的高级用法啦。
记录时间
2022年度 Flag,写作的 562 / 1024 篇。
可以关注我,点赞我、评论我、收藏我啦。更多精彩
👇👇👇扫码加入【78技术人】~ Python 事业部👇👇👇