Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -6,6 +6,7 @@ import asyncio
|
|
6 |
from moviepy.editor import *
|
7 |
import edge_tts
|
8 |
import gradio as gr
|
|
|
9 |
|
10 |
# Configuraci贸n de Logs
|
11 |
logging.basicConfig(level=logging.INFO, format="%(asctime)s - %(levelname)s - %(message)s")
|
@@ -13,12 +14,13 @@ logging.basicConfig(level=logging.INFO, format="%(asctime)s - %(levelname)s - %(
|
|
13 |
# CONSTANTES DE ARCHIVOS
|
14 |
INTRO_VIDEO = "introvideo.mp4"
|
15 |
OUTRO_VIDEO = "outrovideo.mp4"
|
|
|
16 |
FX_SOUND = "fxsound.mp3"
|
17 |
WATERMARK = "watermark.png"
|
18 |
EJEMPLO_VIDEO = "ejemplo.mp4"
|
19 |
|
20 |
# Validar existencia de archivos
|
21 |
-
for file in [INTRO_VIDEO, OUTRO_VIDEO, FX_SOUND, WATERMARK, EJEMPLO_VIDEO]:
|
22 |
if not os.path.exists(file):
|
23 |
logging.error(f"Falta archivo necesario: {file}")
|
24 |
raise FileNotFoundError(f"Falta: {file}")
|
@@ -117,8 +119,17 @@ async def procesar_video(video_input, texto_tts, voz_seleccionada, metodo_corte,
|
|
117 |
# Combinar con intro/outro
|
118 |
intro = VideoFileClip(INTRO_VIDEO)
|
119 |
outro = VideoFileClip(OUTRO_VIDEO)
|
120 |
-
|
121 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
122 |
|
123 |
# Duraci贸n m谩xima para el TTS (despu茅s de la intro)
|
124 |
max_tts_time = video_editado_duration
|
@@ -126,17 +137,22 @@ async def procesar_video(video_input, texto_tts, voz_seleccionada, metodo_corte,
|
|
126 |
# Procesar TTS
|
127 |
tts_audio = await procesar_audio(texto_tts, voz_seleccionada, max_tts_time)
|
128 |
|
129 |
-
# Combinar audios
|
130 |
-
|
131 |
if audio_original:
|
132 |
-
|
133 |
-
|
134 |
|
135 |
-
|
|
|
|
|
|
|
|
|
|
|
136 |
|
137 |
# Renderizar video final
|
138 |
with tempfile.NamedTemporaryFile(suffix=".mp4", delete=False) as tmp:
|
139 |
-
video_final.
|
140 |
tmp.name,
|
141 |
codec="libx264",
|
142 |
audio_codec="aac",
|
|
|
6 |
from moviepy.editor import *
|
7 |
import edge_tts
|
8 |
import gradio as gr
|
9 |
+
from pydub import AudioSegment
|
10 |
|
11 |
# Configuraci贸n de Logs
|
12 |
logging.basicConfig(level=logging.INFO, format="%(asctime)s - %(levelname)s - %(message)s")
|
|
|
14 |
# CONSTANTES DE ARCHIVOS
|
15 |
INTRO_VIDEO = "introvideo.mp4"
|
16 |
OUTRO_VIDEO = "outrovideo.mp4"
|
17 |
+
MUSIC_BG = "musicafondo.mp3"
|
18 |
FX_SOUND = "fxsound.mp3"
|
19 |
WATERMARK = "watermark.png"
|
20 |
EJEMPLO_VIDEO = "ejemplo.mp4"
|
21 |
|
22 |
# Validar existencia de archivos
|
23 |
+
for file in [INTRO_VIDEO, OUTRO_VIDEO, MUSIC_BG, FX_SOUND, WATERMARK, EJEMPLO_VIDEO]:
|
24 |
if not os.path.exists(file):
|
25 |
logging.error(f"Falta archivo necesario: {file}")
|
26 |
raise FileNotFoundError(f"Falta: {file}")
|
|
|
119 |
# Combinar con intro/outro
|
120 |
intro = VideoFileClip(INTRO_VIDEO)
|
121 |
outro = VideoFileClip(OUTRO_VIDEO)
|
122 |
+
|
123 |
+
# M煤sica de fondo solo para el video editado
|
124 |
+
bg_music = AudioSegment.from_mp3(MUSIC_BG)
|
125 |
+
needed_ms = int(video_editado_duration * 1000)
|
126 |
+
repeticiones = needed_ms // len(bg_music) + 1
|
127 |
+
bg_music = bg_music * repeticiones
|
128 |
+
bg_music = bg_music[:needed_ms].fade_out(5000)
|
129 |
+
|
130 |
+
with tempfile.NamedTemporaryFile(delete=False, suffix=".mp3") as tmp_bg:
|
131 |
+
bg_music.export(tmp_bg.name, format="mp3")
|
132 |
+
bg_audio = AudioFileClip(tmp_bg.name).volumex(0.15)
|
133 |
|
134 |
# Duraci贸n m谩xima para el TTS (despu茅s de la intro)
|
135 |
max_tts_time = video_editado_duration
|
|
|
137 |
# Procesar TTS
|
138 |
tts_audio = await procesar_audio(texto_tts, voz_seleccionada, max_tts_time)
|
139 |
|
140 |
+
# Combinar audios para el video editado
|
141 |
+
audios_editado = [bg_audio]
|
142 |
if audio_original:
|
143 |
+
audios_editado.append(audio_original.set_duration(video_editado_duration))
|
144 |
+
audios_editado.append(tts_audio.set_start(0))
|
145 |
|
146 |
+
audio_editado = CompositeAudioClip(audios_editado).set_duration(video_editado_duration)
|
147 |
+
video_editado = video_editado.set_audio(audio_editado)
|
148 |
+
|
149 |
+
# Concatenar intro, video editado y outro
|
150 |
+
video_final = concatenate_videoclips([intro, video_editado, outro])
|
151 |
+
duracion_total = video_final.duration
|
152 |
|
153 |
# Renderizar video final
|
154 |
with tempfile.NamedTemporaryFile(suffix=".mp4", delete=False) as tmp:
|
155 |
+
video_final.write_videofile(
|
156 |
tmp.name,
|
157 |
codec="libx264",
|
158 |
audio_codec="aac",
|