|
from pydantic import BaseModel, Field, validator |
|
from typing import List, Dict |
|
|
|
|
|
|
|
transitions = [ |
|
"WaveRight_transparent.webm", |
|
"WaveLeft_transparent.webm", |
|
"WaveBlue_transparent.webm", |
|
"Wave_transparent.webm", |
|
"Swirl_transparent.webm", |
|
"Snow_transparent.webm", |
|
"Likes_transparent.webm", |
|
"Lightning_transparent.webm", |
|
"Happy_transparent.webm", |
|
"Fire_transparent.webm", |
|
"CurlingWave_transparent.webm", |
|
"Cloud_transparent.webm", |
|
] |
|
|
|
|
|
class Asset(BaseModel): |
|
type: str |
|
sequence: List[Dict] |
|
|
|
@validator("sequence") |
|
def check_duration(cls, sequence): |
|
for item in sequence: |
|
start = item.get("start", 0) |
|
end = item.get("end", 0) |
|
duration = (end - start) * 30 |
|
if duration <= 1: |
|
raise ValueError("Asset duration must be greater than 1 frame.") |
|
return sequence |
|
|
|
|
|
class Link(BaseModel): |
|
file_name: str |
|
link: str |
|
|
|
|
|
class Remotion(BaseModel): |
|
links: List[Link] = [] |
|
assets: List[Asset] = [] |
|
constants: Dict[str, int] = {"duration": 3840, "height": 1920, "width": 1080} |
|
scenes: int |
|
total_duration: int |
|
|
|
def generate_image_links(self): |
|
for i in range(self.scenes): |
|
image_file_name = f"image_{i}.png" |
|
image_link = f"https://image.lexica.art/full_webp/{i}.png" |
|
self.links.append(Link(file_name=image_file_name, link=image_link)) |
|
|
|
|
|
def concatenate_wav_files(input): |
|
|
|
output = None |
|
output_params = None |
|
output_file = '' |
|
try: |
|
|
|
output = wave.open(output_file, "wb") |
|
|
|
|
|
for input_file in input_files: |
|
with wave.open(input_file, "rb") as input_wav: |
|
|
|
if output_params is None: |
|
output_params = input_wav.getparams() |
|
output.setparams(output_params) |
|
|
|
else: |
|
if input_wav.getparams() != output_params: |
|
raise ValueError( |
|
"Input file parameters do not match output file parameters." |
|
) |
|
|
|
|
|
output.writeframes(input_wav.readframes(input_wav.getnframes())) |
|
finally: |
|
|
|
if output is not None: |
|
output.close() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|