Spaces:
Sleeping
Sleeping
Cristobal commited on
Commit ·
77cd82b
1
Parent(s): ec835b2
reencodear video al subir - arregla grabaciones pantalla
Browse files
app.py
CHANGED
|
@@ -242,12 +242,25 @@ async def ep_guion(request: Request):
|
|
| 242 |
@app.post("/subir-material")
|
| 243 |
async def ep_material(file: UploadFile = File(...)):
|
| 244 |
try:
|
| 245 |
-
import subprocess as _sp
|
| 246 |
ext = file.filename.split(".")[-1].lower()
|
| 247 |
idx = len(ESTADO['archivos'])
|
| 248 |
-
|
| 249 |
-
|
| 250 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 251 |
ESTADO["archivos"].append(nombre)
|
| 252 |
return {"ok": True, "total": len(ESTADO["archivos"]), "nombre": nombre}
|
| 253 |
except Exception as e:
|
|
|
|
| 242 |
@app.post("/subir-material")
|
| 243 |
async def ep_material(file: UploadFile = File(...)):
|
| 244 |
try:
|
| 245 |
+
import subprocess as _sp, os as _os
|
| 246 |
ext = file.filename.split(".")[-1].lower()
|
| 247 |
idx = len(ESTADO['archivos'])
|
| 248 |
+
if ext in ("mp4","mov","webm","avi","mkv","m4v"):
|
| 249 |
+
crudo = f"crudo_{idx}.{ext}"
|
| 250 |
+
with open(crudo,"wb") as f:
|
| 251 |
+
f.write(await file.read())
|
| 252 |
+
nombre = f"media_{idx}.mp4"
|
| 253 |
+
# Re-encodear a h264 estandar y fps fijo (arregla grabaciones de pantalla y formatos raros)
|
| 254 |
+
r = _sp.run(["ffmpeg","-y","-i",crudo,"-r","30","-c:v","libx264","-preset","ultrafast","-pix_fmt","yuv420p","-an",nombre], capture_output=True)
|
| 255 |
+
if _os.path.exists(nombre) and _os.path.getsize(nombre) > 1000:
|
| 256 |
+
try: _os.remove(crudo)
|
| 257 |
+
except: pass
|
| 258 |
+
else:
|
| 259 |
+
nombre = crudo
|
| 260 |
+
else:
|
| 261 |
+
nombre = f"media_{idx}.{ext}"
|
| 262 |
+
with open(nombre,"wb") as f:
|
| 263 |
+
f.write(await file.read())
|
| 264 |
ESTADO["archivos"].append(nombre)
|
| 265 |
return {"ok": True, "total": len(ESTADO["archivos"]), "nombre": nombre}
|
| 266 |
except Exception as e:
|