moviepy

视频剪辑什么鬼?Python 带你高效创作短视频

佐手、 提交于 2020-11-18 23:56:04
近两年,抖音、快手将短视频推到风口浪尖上,要生产出高质量的视频,离不开视频剪辑这一环节;在全民剪片浪潮中,大众使用最多的剪辑软件如:Pr、FCPX、剪印、Vue 等。 视频剪辑过程中,Python 一些比较实用的技能,帮助我们更快地进行短视频的创作。 ! 1、 提取背景音乐和修改音量 先从抖音上下载视频文件,然后利用 moviepy 依赖库提取到背景音乐。 def get_audio_from_video(video_path): """ 从视频中提取音频 :param video: :return: """ file_path = './source/' + gene_random() + '.wav' video = VideoFileClip(video_path) audio = video.audio audio.write_audiofile(file_path) return file_path 一个短视频中,可能包含多个背景音乐,需要对背景音乐的音量进行调整。 def handle_bgm(bgm_path, coefficient): music = AudioFileClip(bgm_path) # 音量调整为原来音量的倍数 out_music = music.fx(afx.volumex, coefficient).fx(afx.audio_fadein, 0

Python批量合并处理B站视频

家住魔仙堡 提交于 2020-11-14 06:50:29
源程序可直接到博主github上下载: https://github.com/HuerFu/bilibiliVideoMerge   最近想学习后端,又不想花钱,怎么办呢?于是在手机端B站(哔哩哔哩)上面找到了满意的免费视频教程,但是手机端看起来很不方便啊。于是,我通过在手机端缓存下来后,导入到了电脑端,但是我后面了发现两个问题:   1.本来一集视频按理说一段吧,但是B站下载下来的视频并不是完整的一段,而是被分成了多段blv格式的视频,所以需要想办法把它们拼接成完整的一段视频!      2.视频数量太大,不可能一个一个去修改,得想办法批量处理!(我这里有120个视频文件夹,下图所示,没显示完)      基于上述两个问题,必须用一种方法快速解决!网上百度查了一些资料,觉得可行性很大,于是准备自己动手写代码来实现这一功能。人生苦短,我学Python!哈哈,就是Python没错了,话不多说,直接上自己用python写的批量合并并转换B站视频格式的源代码: # 批量合并特定文件夹下的视频文件,然后输出到指定文件夹下 # 主要是需要moviepy这个库 from moviepy.editor import * import os from natsort import natsorted import json # psutil是一个跨平台库能够轻松实现获取系统运行的进程和系统利用率

How To Resize a Video Clip in Python

拈花ヽ惹草 提交于 2020-06-24 11:38:25
问题 I want to resize a video clip in python 2.7. For example we give "movie.mp4" with 1080p quality The result should be "movie.mp4" with 360p quality I Think that there should be solutions with Moviepy. If you know a solution with it. I would be grateful if you answer me. 回答1: Here is how you resize a movie with moviepy: see the mpviepy doc here import moviepy.editor as mp clip = mp.VideoFileClip("movie.mp4") clip_resized = clip.resize(height=360) # make the height 360px ( According to moviePy

Moviepy's ImageSequenceClip() reads PNGs wrongly like 0, 10, 100 instead of traditional counting

为君一笑 提交于 2020-06-17 02:50:27
问题 So I have this for-loop that creates a photo of each earthquake and names them earthquake0, earthquake1, earthquake2, and so on. plt.savefig("exports\earthquake{0}.png".format(i)) To convert these images to GIF, I use this image_list='exports' my_clip = ImageSequenceClip(image_list, fps=0.75) my_clip.write_gif('eqph_gif.gif') However, ImageSequenceClip() reads the files like earthquake0.png, earthquake10.png, earthquake100.png. How do I make my code read the photos traditionally like 0, 1, 2,

Rotate an image around its x-axis

醉酒当歌 提交于 2020-05-28 06:09:47
问题 I need to rotate an image around its x-axis (or y-axis). I can easily create such an animation with avisynth, but now I need to implement that effect with Python's moviepy module. I can easily rotate an image with the following script but need some clues how to rotate it in 2D or 3D. from moviepy.editor import * clip = ImageClip('my_image.jpg') rotated_clip = (clip.add_mask() .fx(vfx.resize, width=300, height=300) .fx(vfx.rotate, lambda t: 90*t, expand=False) .set_duration(5)) final_clip =