Update main.py
Browse files
main.py
CHANGED
|
@@ -5,10 +5,10 @@ from typing import List, Optional
|
|
| 5 |
import os
|
| 6 |
import asyncio
|
| 7 |
import uuid
|
| 8 |
-
import aiohttp
|
| 9 |
import re
|
| 10 |
-
from urllib.parse import urlparse
|
| 11 |
import shutil
|
|
|
|
|
|
|
| 12 |
import aiofiles
|
| 13 |
|
| 14 |
# Create FastAPI app
|
|
@@ -82,19 +82,12 @@ async def create_slideshow(image_paths, audio_path, output_path, duration, zoom=
|
|
| 82 |
|
| 83 |
# Add zoom effect if requested
|
| 84 |
if zoom:
|
| 85 |
-
for
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
# Create video filter chain
|
| 93 |
-
filter_complex = ""
|
| 94 |
-
for i in range(len(image_paths)):
|
| 95 |
-
filter_complex += f"[v{i}]"
|
| 96 |
-
filter_complex += f"concat=n={len(image_paths)}:v=1:a=0[outv]"
|
| 97 |
-
cmd.extend(["-filter_complex", filter_complex, "-map", "[outv]", "-map", "1:a"])
|
| 98 |
|
| 99 |
cmd.extend([
|
| 100 |
"-c:v", "libx264",
|
|
@@ -119,10 +112,10 @@ async def create_slideshow(image_paths, audio_path, output_path, duration, zoom=
|
|
| 119 |
|
| 120 |
if process.returncode != 0:
|
| 121 |
print(f"FFmpeg error: {stderr.decode()}")
|
| 122 |
-
|
| 123 |
-
|
| 124 |
-
|
| 125 |
-
|
| 126 |
if os.path.exists(concat_file):
|
| 127 |
os.remove(concat_file)
|
| 128 |
return False
|
|
|
|
| 5 |
import os
|
| 6 |
import asyncio
|
| 7 |
import uuid
|
|
|
|
| 8 |
import re
|
|
|
|
| 9 |
import shutil
|
| 10 |
+
# Install these packages using pip if needed
|
| 11 |
+
import aiohttp
|
| 12 |
import aiofiles
|
| 13 |
|
| 14 |
# Create FastAPI app
|
|
|
|
| 82 |
|
| 83 |
# Add zoom effect if requested
|
| 84 |
if zoom:
|
| 85 |
+
# Create a single zooming filter for all images instead of individual filters
|
| 86 |
+
zoom_filter = (
|
| 87 |
+
f"[0:v]scale=1920:1080,zoompan=z='min(1.1,1+(on/{duration*25}/8))':"
|
| 88 |
+
f"d={duration*25}:s=1920x1080:fps=25[outv]"
|
| 89 |
+
)
|
| 90 |
+
cmd.extend(["-filter_complex", zoom_filter, "-map", "[outv]", "-map", "1:a"])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 91 |
|
| 92 |
cmd.extend([
|
| 93 |
"-c:v", "libx264",
|
|
|
|
| 112 |
|
| 113 |
if process.returncode != 0:
|
| 114 |
print(f"FFmpeg error: {stderr.decode()}")
|
| 115 |
+
_, stderr = await process.communicate()
|
| 116 |
+
|
| 117 |
+
if os.path.exists(concat_file):
|
| 118 |
+
os.remove(concat_file)
|
| 119 |
if os.path.exists(concat_file):
|
| 120 |
os.remove(concat_file)
|
| 121 |
return False
|