Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -20,7 +20,6 @@ def get_audio_duration(audio_path):
|
|
| 20 |
return None
|
| 21 |
|
| 22 |
def generate_video(audio_path, image_path):
|
| 23 |
-
# Validación básica
|
| 24 |
if not os.path.isfile(audio_path) or not os.path.isfile(image_path):
|
| 25 |
return "❌ Missing or invalid input files."
|
| 26 |
|
|
@@ -28,28 +27,27 @@ def generate_video(audio_path, image_path):
|
|
| 28 |
if not duration:
|
| 29 |
return "❌ Could not get audio duration. Check your audio file."
|
| 30 |
|
| 31 |
-
|
| 32 |
-
output_filename = os.path.join(TEMP_DIR, f"output_{uuid.uuid4().hex[:8]}.mp4")
|
| 33 |
|
| 34 |
try:
|
| 35 |
cmd = [
|
| 36 |
"ffmpeg", "-y",
|
| 37 |
"-loop", "1", "-framerate", "1", "-i", image_path,
|
| 38 |
"-i", audio_path,
|
|
|
|
| 39 |
"-c:v", "libx264", "-preset", "ultrafast", "-tune", "stillimage",
|
| 40 |
"-c:a", "aac", "-b:a", "192k",
|
| 41 |
"-t", str(duration),
|
| 42 |
-
"-
|
| 43 |
output_filename
|
| 44 |
]
|
| 45 |
|
| 46 |
result = subprocess.run(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True)
|
| 47 |
|
| 48 |
-
# Verificamos que el archivo exista y tenga tamaño
|
| 49 |
if os.path.exists(output_filename) and os.path.getsize(output_filename) > 0:
|
| 50 |
return output_filename
|
| 51 |
else:
|
| 52 |
-
print("FFmpeg
|
| 53 |
return "❌ Something went wrong while generating the video."
|
| 54 |
|
| 55 |
except Exception as e:
|
|
|
|
| 20 |
return None
|
| 21 |
|
| 22 |
def generate_video(audio_path, image_path):
|
|
|
|
| 23 |
if not os.path.isfile(audio_path) or not os.path.isfile(image_path):
|
| 24 |
return "❌ Missing or invalid input files."
|
| 25 |
|
|
|
|
| 27 |
if not duration:
|
| 28 |
return "❌ Could not get audio duration. Check your audio file."
|
| 29 |
|
| 30 |
+
output_filename = os.path.join("temp_videos", f"output_{uuid.uuid4().hex[:8]}.mp4")
|
|
|
|
| 31 |
|
| 32 |
try:
|
| 33 |
cmd = [
|
| 34 |
"ffmpeg", "-y",
|
| 35 |
"-loop", "1", "-framerate", "1", "-i", image_path,
|
| 36 |
"-i", audio_path,
|
| 37 |
+
"-vf", "scale=trunc(iw/2)*2:trunc(ih/2)*2", # 👈 FIX AQUI
|
| 38 |
"-c:v", "libx264", "-preset", "ultrafast", "-tune", "stillimage",
|
| 39 |
"-c:a", "aac", "-b:a", "192k",
|
| 40 |
"-t", str(duration),
|
| 41 |
+
"-pix_fmt", "yuv420p", "-r", "1",
|
| 42 |
output_filename
|
| 43 |
]
|
| 44 |
|
| 45 |
result = subprocess.run(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True)
|
| 46 |
|
|
|
|
| 47 |
if os.path.exists(output_filename) and os.path.getsize(output_filename) > 0:
|
| 48 |
return output_filename
|
| 49 |
else:
|
| 50 |
+
print("FFmpeg ERROR:", result.stderr)
|
| 51 |
return "❌ Something went wrong while generating the video."
|
| 52 |
|
| 53 |
except Exception as e:
|