gnosticdev commited on
Commit
2b31c2c
verified
1 Parent(s): 94a5398

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +36 -44
app.py CHANGED
@@ -24,9 +24,9 @@ for file in [INTRO_VIDEO, OUTRO_VIDEO, MUSIC_BG, EJEMPLO_VIDEO]:
24
 
25
  # Configuraci贸n de chunks
26
  CHUNK_SIZE = 60 # 1 minuto por chunk
27
- SEGMENT_DURATION = 18 # Duraci贸n de cada segmento
28
- OVERLAP = 2 # Segundos a eliminar entre segmentos
29
- TRANSITION_DURATION = 1 # Duraci贸n de la transici贸n slide
30
 
31
  def eliminar_archivo_tiempo(ruta, delay=1800):
32
  def eliminar():
@@ -67,16 +67,21 @@ def crear_musica_fondo(duracion_total):
67
  bg_music.export(tmp_bg.name, format="mp3")
68
  return AudioFileClip(tmp_bg.name).volumex(0.15), tmp_bg.name
69
 
70
- def create_slide_transition(clip1, clip2, duration=1):
71
- """Crea transici贸n slide entre dos clips"""
 
 
 
 
 
72
  transition = CompositeVideoClip([
73
- clip1.fx(vfx.fadeout, duration).set_end(clip1.duration),
74
- clip2.fx(vfx.fadein, duration)
75
- .set_start(clip1.duration - duration)
76
- .set_position(lambda t: ('center', 720 + (-720*(t/duration))))
77
- ], size=(1280, 720))
78
 
79
- return transition.set_duration(clip1.duration + duration)
80
 
81
  async def procesar_video(video_input, texto_tts, voz_seleccionada):
82
  temp_files = []
@@ -86,7 +91,7 @@ async def procesar_video(video_input, texto_tts, voz_seleccionada):
86
  video_original = VideoFileClip(video_input, target_resolution=(720, 1280))
87
  duracion_video = video_original.duration
88
 
89
- # Generar TTS y m煤sica de fondo para todo el video
90
  tts_audio, tts_path = await generar_tts(texto_tts, voz_seleccionada, duracion_video)
91
  bg_audio, bg_path = crear_musica_fondo(duracion_video)
92
  temp_files.extend([tts_path, bg_path])
@@ -99,44 +104,31 @@ async def procesar_video(video_input, texto_tts, voz_seleccionada):
99
  audios.append(tts_audio.set_start(0).volumex(0.85))
100
  audio_final = CompositeAudioClip(audios).set_duration(duracion_video)
101
 
102
- # Dividir video en segmentos CON manejo de overlap original
103
  segments = []
104
  current_time = 0
105
  while current_time < duracion_video:
106
  end_time = current_time + SEGMENT_DURATION
107
  if end_time > duracion_video:
108
- break # Terminar si ya no hay suficiente tiempo
109
-
110
- # Extraer segmento eliminando 2 segundos al final
111
- full_segment = video_original.subclip(current_time, end_time)
112
- if segments and full_segment.duration >= OVERLAP:
113
- full_segment = full_segment.subclip(0, full_segment.duration - OVERLAP)
114
-
115
- segments.append(full_segment)
116
- current_time += (SEGMENT_DURATION - OVERLAP)
117
 
118
- # Asegurar que haya al menos un segmento
119
- if not segments:
120
- logging.warning("Video demasiado corto, devolviendo el video original.")
121
- video_final = video_original.set_audio(audio_final)
122
- else:
123
- # Aplicar transiciones slide entre segmentos
124
- clips = []
125
- for i in range(len(segments)):
126
- if i == 0:
127
- clips.append(segments[i])
128
- else:
129
- transition = create_slide_transition(
130
- clips[-1],
131
- segments[i],
132
- duration=TRANSITION_DURATION
133
- )
134
- clips.pop()
135
- clips.append(transition)
136
- clips.append(segments[i])
137
-
138
- video_final = concatenate_videoclips(clips, method="compose")
139
- video_final = video_final.set_audio(audio_final)
140
 
141
  # Agregar intro y outro
142
  intro = VideoFileClip(INTRO_VIDEO, target_resolution=(720, 1280))
 
24
 
25
  # Configuraci贸n de chunks
26
  CHUNK_SIZE = 60 # 1 minuto por chunk
27
+ SEGMENT_DURATION = 18 # Duraci贸n base de cada segmento
28
+ TRANSITION_DURATION = 1.5 # Duraci贸n del efecto slide (ahora m谩s visible)
29
+ OVERLAP = TRANSITION_DURATION # El overlap ahora es igual a la duraci贸n de la transici贸n
30
 
31
  def eliminar_archivo_tiempo(ruta, delay=1800):
32
  def eliminar():
 
67
  bg_music.export(tmp_bg.name, format="mp3")
68
  return AudioFileClip(tmp_bg.name).volumex(0.15), tmp_bg.name
69
 
70
+ def create_slide_transition(clip1, clip2, duration=TRANSITION_DURATION):
71
+ """Transici贸n slide con movimiento m谩s pronunciado"""
72
+ # Tomar la 煤ltima parte del clip1 y la primera parte del clip2
73
+ part1 = clip1.subclip(clip1.duration - duration)
74
+ part2 = clip2.subclip(0, duration)
75
+
76
+ # Crear animaci贸n de deslizamiento
77
  transition = CompositeVideoClip([
78
+ part1.fx(vfx.fadeout, duration),
79
+ part2.fx(vfx.fadein, duration).set_position(
80
+ lambda t: ('center', 720 - (720 * (t/duration))) # Movimiento desde abajo
81
+ )
82
+ ], size=(1280, 720)).set_duration(duration)
83
 
84
+ return transition
85
 
86
  async def procesar_video(video_input, texto_tts, voz_seleccionada):
87
  temp_files = []
 
91
  video_original = VideoFileClip(video_input, target_resolution=(720, 1280))
92
  duracion_video = video_original.duration
93
 
94
+ # Generar TTS y m煤sica de fondo
95
  tts_audio, tts_path = await generar_tts(texto_tts, voz_seleccionada, duracion_video)
96
  bg_audio, bg_path = crear_musica_fondo(duracion_video)
97
  temp_files.extend([tts_path, bg_path])
 
104
  audios.append(tts_audio.set_start(0).volumex(0.85))
105
  audio_final = CompositeAudioClip(audios).set_duration(duracion_video)
106
 
107
+ # Dividir video en segmentos con superposici贸n controlada
108
  segments = []
109
  current_time = 0
110
  while current_time < duracion_video:
111
  end_time = current_time + SEGMENT_DURATION
112
  if end_time > duracion_video:
113
+ end_time = duracion_video
114
+ segment = video_original.subclip(current_time, end_time)
115
+ segments.append(segment)
116
+ current_time += (SEGMENT_DURATION - OVERLAP) # Avance considerando el overlap
 
 
 
 
 
117
 
118
+ # Construir video con transiciones
119
+ clips = []
120
+ for i in range(len(segments)):
121
+ if i == 0:
122
+ clips.append(segments[i])
123
+ else:
124
+ # Crear transici贸n entre el final del clip anterior y el inicio del actual
125
+ transition = create_slide_transition(clips[-1], segments[i])
126
+ clips.pop()
127
+ clips.append(transition)
128
+ clips.append(segments[i].subclip(TRANSITION_DURATION)) # Eliminar parte ya usada en transici贸n
129
+
130
+ # Combinar todo
131
+ video_final = concatenate_videoclips(clips, method="compose").set_audio(audio_final)
 
 
 
 
 
 
 
 
132
 
133
  # Agregar intro y outro
134
  intro = VideoFileClip(INTRO_VIDEO, target_resolution=(720, 1280))