Tu Nombre commited on
Commit
b4fcea4
·
1 Parent(s): f6cd07c

fix imagenes PIL preprocesado correcto

Browse files
Files changed (1) hide show
  1. cliente_template.py +28 -11
cliente_template.py CHANGED
@@ -121,21 +121,38 @@ async def pipeline():
121
  voz = AC("voz.mp3")
122
  if TIPO_VIDEO == "short":
123
  clips_lista = []
 
 
124
  for fp in fondos:
125
  try:
126
- dur_clip = voz.duration / max(len(fondos), 1)
127
- if fp.lower().endswith((".jpg",".jpeg",".png",".webp")):
128
- cc = IC(fp).set_duration(dur_clip)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
129
  else:
130
- cc = VC(fp).without_audio()
131
- cc = cc.loop(duration=dur_clip)
132
- if cc.w/cc.h > 1080/1920:
133
- cc = cc.resize(height=1920)
134
- else:
135
- cc = cc.resize(width=1080)
136
- cc = cc.crop(x_center=cc.w/2, y_center=cc.h/2, width=1080, height=1920)
137
  clips_lista.append(cc)
138
- except: pass
 
 
139
  clip = concatenate_videoclips(clips_lista, method="compose")
140
  clip = clip.crop(x_center=clip.w/2, width=1080, height=1920)
141
  else:
 
121
  voz = AC("voz.mp3")
122
  if TIPO_VIDEO == "short":
123
  clips_lista = []
124
+ dur_clip = voz.duration / max(len(fondos), 1)
125
+ log(f"Duracion por clip: {dur_clip:.1f}s")
126
  for fp in fondos:
127
  try:
128
+ es_img = fp.lower().endswith((".jpg",".jpeg",".png",".webp"))
129
+ if es_img:
130
+ from PIL import Image as PILImage
131
+ img = PILImage.open(fp).convert("RGB")
132
+ w, h = img.size
133
+ if w/h > 1080/1920:
134
+ new_h = 1920
135
+ new_w = int(w * (1920/h))
136
+ else:
137
+ new_w = 1080
138
+ new_h = int(h * (1080/w))
139
+ img = img.resize((new_w, new_h), PILImage.LANCZOS)
140
+ left = (new_w - 1080) // 2
141
+ top = (new_h - 1920) // 2
142
+ img = img.crop((left, top, left+1080, top+1920))
143
+ img.save(fp + "_r.jpg", "JPEG", quality=90)
144
+ cc = IC(fp + "_r.jpg").set_duration(dur_clip)
145
  else:
146
+ cc = VC(fp).without_audio().loop(duration=dur_clip)
147
+ if cc.w/cc.h > 1080/1920:
148
+ cc = cc.resize(height=1920)
149
+ else:
150
+ cc = cc.resize(width=1080)
151
+ cc = cc.crop(x_center=cc.w/2, y_center=cc.h/2, width=1080, height=1920)
 
152
  clips_lista.append(cc)
153
+ except Exception as e_c:
154
+ log(f"Error clip {fp}: {e_c}")
155
+ log(f"Clips OK: {len(clips_lista)}/{len(fondos)}")
156
  clip = concatenate_videoclips(clips_lista, method="compose")
157
  clip = clip.crop(x_center=clip.w/2, width=1080, height=1920)
158
  else: