Support for upgraded moviepy

This commit is contained in:
2024-03-02 15:19:30 +01:00
parent 6b6b18507a
commit 455514e475
13 changed files with 87 additions and 68 deletions

View File

@@ -4,9 +4,8 @@ import shutil
import time
import gradio as gr
import moviepy.editor as mp
from moviepy.video.fx.crop import crop
from moviepy.video.fx.resize import resize
import moviepy as mp
import moviepy.video.fx as vfx
from . import BaseBackgroundEngine
@@ -47,14 +46,16 @@ class VideoBackgroundEngine(BaseBackgroundEngine):
"The background video is shorter than the video to be generated."
)
start = random.uniform(0, background_max_start)
clip = background.subclip(start, start + self.ctx.duration)
clip = background.with_subclip(start, start + self.ctx.duration)
self.ctx.credits += f"\n{self.background_video.data['credits']}"
clip = resize(clip, width=self.ctx.width, height=self.ctx.height)
w, h = clip.size
if w > h:
clip = crop(clip, width=self.ctx.width, height=self.ctx.height, x_center=w / 2, y_center=h / 2)
resolution: float = w / h
canvas_resolution: float = self.ctx.width / self.ctx.height
if resolution > canvas_resolution:
clip = clip.with_effects([vfx.Resize(height=self.ctx.height)])
else:
clip = crop(clip, width=self.ctx.width, height=self.ctx.height, x_center=w / 2, y_center=h / 2)
clip = clip.with_effects([vfx.Resize(width=self.ctx.width)])
clip = clip.with_position(("center", "center"))
self.ctx.index_0.append(clip)
@classmethod