moviepy

Django - Trying to create a GIF from uploaded video

余生长醉 提交于 2020-04-18 03:49:27
问题 I have a model class representing a video file. It has also a GIF field. I want to create also a GIF file of each video file. Before saving, I fill the gif field with the content of video field in the save() method like this: class Video(models.Model): created = models.DateTimeField(auto_now_add=True) text = models.CharField(max_length=100, blank=True) image = models.ImageField(upload_to='Images/',blank=True) video = models.FileField(upload_to='Videos/',blank=True) gif = models.FileField

Django - Trying to create a GIF from uploaded video

只愿长相守 提交于 2020-04-18 03:49:23
问题 I have a model class representing a video file. It has also a GIF field. I want to create also a GIF file of each video file. Before saving, I fill the gif field with the content of video field in the save() method like this: class Video(models.Model): created = models.DateTimeField(auto_now_add=True) text = models.CharField(max_length=100, blank=True) image = models.ImageField(upload_to='Images/',blank=True) video = models.FileField(upload_to='Videos/',blank=True) gif = models.FileField

Create a GIF from Video using Django Signals and MoviePy

醉酒当歌 提交于 2020-04-18 03:48:11
问题 I wanted to apply Django's Signals to the following model: class Video(models.Model): created = models.DateTimeField(auto_now_add=True) text = models.CharField(max_length=100, blank=True) image = models.ImageField(upload_to='Images/',blank=True) video = models.FileField(upload_to='Videos/',blank=True) gif = models.FileField(upload_to = 'Videos/', blank = True) class Meta: ordering = ('created', ) The reason why I use signals: Whenever a Video object gets created, we get notified and then we

Python玩转各种多媒体,视频、音频到图片

爷,独闯天下 提交于 2020-04-10 15:33:45
Python玩转各种多媒体,视频、音频到图片 我们经常会遇到一些对于多媒体文件修改的操作,像是对视频文件的操作:视频剪辑、字幕编辑、分离音频、视频音频混流等。又比如对音频文件的操作:音频剪辑,音频格式转换。再比如我们最常用的图片文件,格式转换、各个属性的编辑等。因为多媒体文件的操作众多,本文选取一些极具代表性的操作,以代码的形式实现各个操作。 一、图片操作 操作图片的模块有许多,其中比较常用的两个就是 Pillow 和 opencv ,两个模块各有优势。其中 opencv 是计算机视觉处理的开源模块,应用的范围更加广泛,从图像处理到视频处理,再到物体检测等。而 pillow 相比直线就单纯的多,其大多数操作都是围绕图像而展开的。 1.1、格式转换 图片格式有多种多样,最直观的感受就是图片后缀。而格式之间的差异不仅仅是后缀的差异,最为明显的就是 png 格式图片,同其它图片有着最为直观的区别。下面我们就看看在Python中如何转换格式,我们先安装 pillow 模块: pip install pillow 然后看看如何导入模块以及如何读取图像: from PIL import Image # 读取图像 img = Image . open ( 'ycjc.jpg' ) # 显示图像 img . show ( ) 我们有了上面的基础操作之后,就可以开始进行格式转换了

使用 Python 和百度语音识别生成视频字幕

喜欢而已 提交于 2020-04-07 07:34:23
文章目录 从视频中提取音频 根据静音对音频分段 使用百度语音识别 获取 Access Token 使用 Raw 数据进行合成 生成字幕 总结 从视频中提取音频 安装 moviepy pip install moviepy 相关代码: audio_file = work_path + '\\out.wav' video = VideoFileClip(video_file) video.audio.write_audiofile(audio_file,ffmpeg_params=['-ar','16000','-ac','1']) 根据静音对音频分段 使用音频库 pydub,安装: pip install pydub 第一种方法: # 这里silence_thresh是认定小于-70dBFS以下的为silence,发现小于 sound.dBFS * 1.3 部分超过 700毫秒,就进行拆分。这样子分割成一段一段的。 sounds = split_on_silence(sound, min_silence_len = 500, silence_thresh= sound.dBFS * 1.3) sec = 0 for i in range(len(sounds)): s = len(sounds[i]) sec += s print('split duration is ', sec)

Moviepy zooming effects need tweaking

99封情书 提交于 2020-03-18 15:42:42
问题 I would like to zoom a clip to a certain dimension, then stop further zooming. In other words, the clip stop further increasing its size after reaching a certain size, and its better if the clip start zooming from much smaller of its original size, and to a bigger version. I am using moviepy module. With the following code I can progressively zoom a clip, but having a hard time figuring out how to grow a clip from small to big, creating an animated effect. Any feedback you provide is greatly

Moviepy zooming effects need tweaking

|▌冷眼眸甩不掉的悲伤 提交于 2020-03-18 15:40:08
问题 I would like to zoom a clip to a certain dimension, then stop further zooming. In other words, the clip stop further increasing its size after reaching a certain size, and its better if the clip start zooming from much smaller of its original size, and to a bigger version. I am using moviepy module. With the following code I can progressively zoom a clip, but having a hard time figuring out how to grow a clip from small to big, creating an animated effect. Any feedback you provide is greatly

Moviepy: no audio in written videofile when running on heroku

本秂侑毒 提交于 2020-01-24 01:10:18
问题 I am making videos with moviepy. Created locally, the final videofile has audio. When I run the same code on heroku, the final video has no audio. First, I thought not using the /tmp directory on heroku might be the issue. I also followed advice to add audio parameters to write_videofile . Both didn't solve the problem. I am using the heroku ffmpeg buildpack. #Make soundtrack soundtrack = AudioFileClip('https://storage.googleapis.com/ABC/music.mp3') soundtrack = soundtrack.set_duration(final

How to correctly refer to fig and ax with moviepy animation

爱⌒轻易说出口 提交于 2020-01-21 12:10:10
问题 data_dict = {'x': {(0, 0): 3760.448435678077, (0, 12): 4851.68102541007, (0, 2226): 5297.61518907981, (0, 2479): 4812.134249142693, (0, 2724): 4756.5295525777465, (0, 3724): 3760.448435678077, (0, 4598): 4763.265306122449, (0, 4599): 5155.102040816327, (0, 4600): 5191.836734693878, (1, 0): 3822.238314568112, (1, 12): 4856.1910324326145, (1, 2226): 5304.678983022428, (1, 2479): 4815.435125468252, (1, 2724): 4761.889691080804, (1, 3724): 3768.2889580569245, (1, 4598): 4768.908833716798, (1,

Python 带你高效创作短视频

纵饮孤独 提交于 2020-01-09 13:05:07
【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>> 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.5).fx( afx.audio_fadeout, 1) # 保存背景音乐 out_music.write_audiofile('./source/output.wav') 2、