moviepy音视频剪辑:使用mask遮罩实现视频叠加透明效果

☞ ░ 前往老猿Python博客 https://blog.youkuaiyun.com/LaoYuanPython ░

一、引言

在《moviepy音视频剪辑:mask clip遮罩剪辑、遮片、蒙版的作用以及其包含的构成内容》中介绍:“mask遮罩是一种只有灰度值的像素构成的帧组成的剪辑,其作用就是在带mask的剪辑与其他剪辑合成时确认是否显示带mask剪辑的对应像素。”

本文实现一个使用mask遮罩剪辑实现叠加视频的透明效果。

二、程序实现

本案例实现一个可以在视频上面叠加一个旋转视频或旋转图片的通用方法,支持两个内容大小不同的视频叠加。为了支持叠加对象为图片,需要将图片转换成视频,为了尽可能突出图片的表达内容,在将图片转视频前将图片的背景色转换为黑色。
相关程序包括如下函数:

  1. ridPicBackground:去掉图片背景色,被convertPicToVideo调用
  2. convertPicToVideo:将图片转成视频,被videoOverlyObjMask调用</
使用Mask遮罩实现视频叠加透明效果 - 用Python和MoviePy进行音视频剪辑 你可以根据自己的需求修改遮罩的形状和透明度来实现不同的效果。使用MoviePy库,你还可以添加文字、图片等元素,以及进行更多的音视频剪辑操作。在视频编辑中,叠加透明效果是一种常见的技术,它可以将两个视频叠加在一起,并通过透明度来控制它们之间的可见性。在本文中,我们将使用Python编程语言以及MoviePy库来实现这一效果。现在,我们可以创建一个遮罩(mask)来控制叠加效果的透明度。在这个例子中,我们将使用多边形来创建一个简单的遮罩。现在,我们可以将遮罩应用到第二个视频上,并将其叠加在第一个视频上。 阅读详情

相关推荐

moviepy音视频剪辑:使用mask遮罩剪辑实现叠加透明效果详解

本文介绍了通过moviepy设置mask遮罩的剪辑和另外的剪辑叠加后实现上层剪辑和下层剪辑叠加后,上层剪辑背景色部分被下层剪辑内容所呈现替代的方案。通过该实现案例的介绍,可以理解遮罩剪辑的作用,并在多个剪辑制作特效中使用该方法制作视频特效。

老猿Python 6463

使用音视频剪辑技术实现遮罩剪辑叠加透明效果

需要注意的是,上述代码中,logo.to_mask()将Logo图片转化为ImageClip的遮罩(mask)形式,invert()将其颜色反转,使得透明部分为黑色、非透明部分为白色。最后,我们使用CompositeVideoClip类将视频和Logo组合在一起,得到了遮罩剪辑叠加透明效果的视频文件,并可以通过write_videofile方法保存在本地。选取一张PNG格式的Logo图片,并使用GIMP等工具将透明部分设置为白色,非透明部分设置为黑色,然后保存为alpha通道透明的PNG图片。

. 842

使用mask遮罩实现视频透明叠加效果

我们在这里创建了两个遮罩,一个是完全透明的黑色遮罩,一个是完全不透明的白色遮罩。接下来,我们可以使用VideoClip函数将原始视频和遮罩对象合并,从而生成一个新的视频对象。接下来,我们需要创建遮罩mask。在音视频剪辑中,我们经常需要实现视频的叠加效果,让两个或多个视频同时播放,但同时又保留原有视频的内容。接下来,我们需要准备两个视频,一个是底部的视频,一个是需要叠加在底部视频上的视频。我们可以使用subclip函数来截取想要叠加的视频的部分时间段,并使用resize函数调整大小以适应底部视频。

qq_37934722的博客 718

《OpenCV-Python初学者疑难问题集》专栏目录

本专栏为笔者《OpenCV-Python图形图像处理》的伴生专栏,是笔者对OpenCV-Python图形图像处理学习中遇到的一些问题个人感悟的整合,相关资料基本上都是老猿反复研究的成果,有助于OpenCV-Python初学者比较深入地理解OpenCV。 ...

老猿Python 3965

实现视频叠加时上层剪辑透明部分不遮挡下层内容的两种方案 Python

以上代码中,我们首先读取两个视频,然后逐帧处理它们。然后,我们对两个视频的RGB通道进行透明度合成,并将结果的透明度通道设置为视频1的透明度通道。最后,我们将图像转换回BGR格式,并将处理后的帧写入输出视频。在视频编辑和图像处理中,有时我们需要将两个视频叠加在一起,但希望上层视频的透明部分不遮挡下层视频的内容。方法将视频2叠加在视频1上,并设置背景色为黑色以确保透明部分不遮挡下层内容。这种方案通过使用图像处理库,如OpenCV和NumPy,来处理视频的透明度信息,并将两个视频按照透明度进行合成。

. 715

moviepy音视频剪辑:使用mask遮罩实现视频叠加透明效果.rar

moviepy音视频剪辑:使用mask遮罩实现视频叠加透明效果.rar

moviepy音视频剪辑:使用mask遮罩剪辑实现叠加透明效果详解.rar

moviepy音视频剪辑:使用mask遮罩剪辑实现叠加透明效果详解.rar

南邮-软件设计实验(C++版)

南邮软件设计 A档 一、分数统计 课题内容:   设计一个分数统计程序。包括学生信息的输入输出以及排序。通过该课题全面熟悉数组、字符串、文件的使用,掌握程序设计的基本方法及友好界面的设计。 课题要求: (1)输入某班级学生的姓名、分数; (2)对(1)的分数进行降幂排列并输出; (3)具有输入输出界面。 示例代码: #include<bits/stdc++.h> using...

Dainelcw 1万+

相机标定-张正友棋盘格标定法

(X,Y,Z)为在世界坐标系下一点的物理坐标 ( u , v ) 为该点对应的在像素坐标系下的像素坐标 引入齐次坐标的原因:引入齐次坐标的目的是为了升维,将坐标从二维坐标变为三维坐标。 2.相机成像过程 相机成像系统中,共包含四个坐标系:世界坐标系、相机坐标系、图像坐标系、像素坐标系。 (1)世界坐标系(,,) 描述目标在真实世界中的位置引入的参考坐标系。 (2)相机坐标系(,,) ...

qq_41275123的博客 1万+

osgEarth添加线特征

部分关键代码: osgEarth::Annotation::FeatureNode* pathNode = 0; osgEarth::Symbology::Geometry* path = new osgEarth::Symbology::LineString(); Track*track = dynamic_cast<Track*>(entity->getProperty(PS_TRACK)); if (track == nullptr) { return; } st.

wb175208的专栏 2968

abb机器人指令手册_ABB机器人配置圆形输送链跟踪

更多内容请点击上方ABB机器人实战技巧关注也可点击公众号下方往期经典浏览更多内容转载请先后台留言,大家一起支持原创,推动机器人使用和发展本公众号对各类ABB机器人应用,仿真,毕业设计提供技术支持,详细后台留言本公众号诚挚希望与各机器人培训机构,机器人使用单元合作,提供技术支持,详细后台留言1. 通常的机器人输送链跟踪,均为直线输送链跟踪,例如下图2. 有些情况,输送链为圆形,例如...

weixin_39849894的博客 2044

在AVP28335(兼容德州仪器TMS320-28335) 上实现ModbusSlaveRTU-485源码及注释。

今天先把题目先给出来, 在近两天会把源码 (含详细注释 )及部署、测试结果给出来, 希望能给大家帮助。(全免费 我有点缺德,断了别人的一个财路)。

FOOLCODE的专栏 642

【PG高可用】一 PostgreSQL高可用方案repmgr部署(非常详细)

repmgr安装部署

DBA之路的博客 7054

Open3D 使用RANSAC分割平面【2026最新版】

使用RANSAC从点云中分割平面,用segement_plane函数。博客长期更新,本文最新更新时间为:2026年2月28日。

点云侠的博客 37万+

蓝牙模块HM-10手册

蓝牙模块HM-10手册,该手册对蓝牙模块HM-10进行了详细的介绍和使用方法以及一些AT指令。

老版QQ原生表情gif动态

这是老版的QQ表情,不过全是动态的的,Windows照片查看器是不会动的,可以右击用浏览器打开查看,再说一遍是老版的,只是分享给宁愿用老版也要动态的人。

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

Statistics and Machine Learning Toolbox

Statistics and Machine Learning Toolbox(带书签),MATLAB统计学习工具

上一篇: OpenCV图像运算+Moviepy实现视频旋转叠加
下一篇: 2020年程序员节杂记:老骥明知桑榆晚,不用扬鞭自奋蹄
LaoYuanPython
LaoYuanPython 2020年博客之星Top3 2020年博客之星Top3 领域专家: Python技术领域 领域专家: Python技术领域
博客等级 码龄8年 15万+粉丝 1324原创
评论 12
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

LaoYuanPython

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值