Upload 4 files
Browse files- .gitattributes +2 -0
- app.py +83 -0
- ffmpeg +3 -0
- iarec.mp4 +3 -0
- requirements.txt +6 -0
.gitattributes
CHANGED
|
@@ -33,3 +33,5 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
| 33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
|
|
|
| 33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
| 36 |
+
ffmpeg filter=lfs diff=lfs merge=lfs -text
|
| 37 |
+
iarec.mp4 filter=lfs diff=lfs merge=lfs -text
|
app.py
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import time
|
| 3 |
+
import subprocess
|
| 4 |
+
from multiprocessing import Process
|
| 5 |
+
import uvicorn
|
| 6 |
+
from fastapi import FastAPI, Response
|
| 7 |
+
|
| 8 |
+
app = FastAPI()
|
| 9 |
+
|
| 10 |
+
# Archivo de video y rutas de salida
|
| 11 |
+
video_file = "iarec.mp4"
|
| 12 |
+
hls_output = "stream.m3u8"
|
| 13 |
+
hls_segment_prefix = "stream"
|
| 14 |
+
|
| 15 |
+
# Comando FFmpeg para transmitir video en HLS (en loop continuo)
|
| 16 |
+
ffmpeg_command = [
|
| 17 |
+
'./ffmpeg',
|
| 18 |
+
'-re',
|
| 19 |
+
'-stream_loop', '-1', # Repetir el video en loop
|
| 20 |
+
'-i', video_file,
|
| 21 |
+
'-vf', 'fps=24',
|
| 22 |
+
'-c:v', 'libx264',
|
| 23 |
+
'-c:a', 'libfdk_aac',
|
| 24 |
+
'-profile:a', 'aac_he_v2',
|
| 25 |
+
'-crf', '28',
|
| 26 |
+
'-b:a', '32k',
|
| 27 |
+
'-preset', 'fast',
|
| 28 |
+
'-f', 'hls',
|
| 29 |
+
'-hls_time', '15', # Duraci贸n de cada segmento en segundos
|
| 30 |
+
'-hls_list_size', '15', # N煤mero de segmentos en la lista de reproducci贸n
|
| 31 |
+
'-hls_flags', 'append_list+omit_endlist', # A帽adir a la lista sin eliminar los antiguos
|
| 32 |
+
'-hls_segment_filename', f'{hls_segment_prefix}%03d.ts', # Nombre de archivo de los segmentos
|
| 33 |
+
hls_output
|
| 34 |
+
]
|
| 35 |
+
|
| 36 |
+
def make_ffmpeg_executable():
|
| 37 |
+
try:
|
| 38 |
+
subprocess.run(["chmod", "+x", "./ffmpeg"], check=True)
|
| 39 |
+
except subprocess.CalledProcessError as e:
|
| 40 |
+
print(f"Error al cambiar permisos de FFmpeg: {e}")
|
| 41 |
+
|
| 42 |
+
def stream_video():
|
| 43 |
+
try:
|
| 44 |
+
process = subprocess.Popen(ffmpeg_command)
|
| 45 |
+
process.wait()
|
| 46 |
+
except Exception as e:
|
| 47 |
+
print(f"Error al ejecutar FFmpeg: {e}")
|
| 48 |
+
|
| 49 |
+
@app.on_event("startup")
|
| 50 |
+
async def startup_event():
|
| 51 |
+
make_ffmpeg_executable() # Asegurarse de que FFmpeg sea ejecutable
|
| 52 |
+
# Espera activa para verificar que el archivo M3U8 est茅 generado
|
| 53 |
+
while not os.path.exists(hls_output):
|
| 54 |
+
print("Esperando a que se genere el archivo M3U8...")
|
| 55 |
+
time.sleep(1)
|
| 56 |
+
print("Archivo M3U8 generado. Servidor listo para recibir solicitudes.")
|
| 57 |
+
|
| 58 |
+
@app.get("/")
|
| 59 |
+
async def read_root():
|
| 60 |
+
return {"message": "Training IA"}
|
| 61 |
+
|
| 62 |
+
@app.get("/stream.m3u8")
|
| 63 |
+
def get_m3u8():
|
| 64 |
+
with open(hls_output, "rb") as f:
|
| 65 |
+
m3u8_content = f.read()
|
| 66 |
+
return Response(content=m3u8_content, media_type="application/vnd.apple.mpegurl")
|
| 67 |
+
|
| 68 |
+
@app.get("/stream{segment}.ts")
|
| 69 |
+
def get_segment(segment: int):
|
| 70 |
+
segment_file = f"{hls_segment_prefix}{segment:03d}.ts"
|
| 71 |
+
if os.path.exists(segment_file):
|
| 72 |
+
with open(segment_file, "rb") as f:
|
| 73 |
+
segment_content = f.read()
|
| 74 |
+
return Response(content=segment_content, media_type="video/mp2t")
|
| 75 |
+
else:
|
| 76 |
+
return Response(status_code=404, content="Segment not found")
|
| 77 |
+
|
| 78 |
+
if __name__ == "__main__":
|
| 79 |
+
# Asegurarse de que FFmpeg sea ejecutable antes de iniciar el proceso
|
| 80 |
+
make_ffmpeg_executable()
|
| 81 |
+
video_process = Process(target=stream_video)
|
| 82 |
+
video_process.start()
|
| 83 |
+
uvicorn.run(app, host="0.0.0.0", port=7860)
|
ffmpeg
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:1d6d9c33e7a0ccb8a4774efbbe690697ecf3c8134abc1b34d6072499d478d7c8
|
| 3 |
+
size 67504768
|
iarec.mp4
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:441b77a361f0fc5e0a6f8f307c6fbdb9754c8a2d973a687b46386a0436c2fc54
|
| 3 |
+
size 2580072870
|
requirements.txt
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
fastapi==0.79.0
|
| 2 |
+
uvicorn==0.18.3
|
| 3 |
+
requests==2.28.1
|
| 4 |
+
ffmpeg-python==0.2.0
|
| 5 |
+
py7zr
|
| 6 |
+
jdk4py
|