Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,11 +1,28 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
import os
|
| 3 |
import subprocess
|
|
|
|
|
|
|
|
|
|
| 4 |
|
| 5 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
def start_streaming(rtmp_server, stream_key):
|
| 7 |
-
# Comando FFmpeg para
|
| 8 |
-
command = f"ffmpeg -
|
| 9 |
process = subprocess.Popen(command, shell=True)
|
| 10 |
return "Transmisi贸n en vivo iniciada"
|
| 11 |
|
|
@@ -14,10 +31,17 @@ def build_interface():
|
|
| 14 |
with gr.Blocks() as demo:
|
| 15 |
gr.Markdown("# Transmisi贸n en Vivo")
|
| 16 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
# Entrada para el servidor RTMP
|
| 18 |
rtmp_server = gr.Textbox(label="Servidor RTMP (YouTube, Twitch, etc.)", placeholder="Ingresa el servidor RTMP")
|
| 19 |
|
| 20 |
-
# Entrada para la clave de transmisi贸n
|
| 21 |
stream_key = gr.Textbox(label="Clave de transmisi贸n", placeholder="Ingresa tu clave de transmisi贸n", type="password")
|
| 22 |
|
| 23 |
# Bot贸n para iniciar la transmisi贸n
|
|
@@ -31,6 +55,8 @@ def build_interface():
|
|
| 31 |
|
| 32 |
return demo
|
| 33 |
|
| 34 |
-
#
|
| 35 |
demo = build_interface()
|
| 36 |
-
|
|
|
|
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
import os
|
| 3 |
import subprocess
|
| 4 |
+
from fastapi import FastAPI, Request
|
| 5 |
+
from starlette.responses import JSONResponse
|
| 6 |
+
import uvicorn
|
| 7 |
|
| 8 |
+
app = FastAPI()
|
| 9 |
+
|
| 10 |
+
# Ruta para recibir el stream de video
|
| 11 |
+
@app.post("/save_stream")
|
| 12 |
+
async def save_stream(request: Request):
|
| 13 |
+
# Recibe el stream de video y lo almacena o lo procesa en tiempo real con FFmpeg
|
| 14 |
+
body = await request.body()
|
| 15 |
+
with open("temp_stream.webm", "ab") as f:
|
| 16 |
+
f.write(body)
|
| 17 |
+
|
| 18 |
+
# Aqu铆 podr铆as procesar el archivo con FFmpeg en tiempo real para enviarlo al servidor RTMP
|
| 19 |
+
|
| 20 |
+
return JSONResponse({"status": "ok"})
|
| 21 |
+
|
| 22 |
+
# Funci贸n para iniciar la transmisi贸n (ejecutada al presionar el bot贸n en Gradio)
|
| 23 |
def start_streaming(rtmp_server, stream_key):
|
| 24 |
+
# Comando FFmpeg para procesar el archivo temporal y transmitirlo
|
| 25 |
+
command = f"ffmpeg -re -i temp_stream.webm -c:v libx264 -b:v 1000k -f flv {rtmp_server}/{stream_key}"
|
| 26 |
process = subprocess.Popen(command, shell=True)
|
| 27 |
return "Transmisi贸n en vivo iniciada"
|
| 28 |
|
|
|
|
| 31 |
with gr.Blocks() as demo:
|
| 32 |
gr.Markdown("# Transmisi贸n en Vivo")
|
| 33 |
|
| 34 |
+
# Insertar el script para capturar pantalla
|
| 35 |
+
gr.HTML("""
|
| 36 |
+
<script src="screen_capture.js"></script>
|
| 37 |
+
<video id="screenPreview" style="width:100%;"></video> <!-- Previsualizaci贸n de pantalla -->
|
| 38 |
+
<button onclick="startScreenCapture()">Compartir Pantalla</button>
|
| 39 |
+
""")
|
| 40 |
+
|
| 41 |
# Entrada para el servidor RTMP
|
| 42 |
rtmp_server = gr.Textbox(label="Servidor RTMP (YouTube, Twitch, etc.)", placeholder="Ingresa el servidor RTMP")
|
| 43 |
|
| 44 |
+
# Entrada para la clave de transmisi贸n (ocultada)
|
| 45 |
stream_key = gr.Textbox(label="Clave de transmisi贸n", placeholder="Ingresa tu clave de transmisi贸n", type="password")
|
| 46 |
|
| 47 |
# Bot贸n para iniciar la transmisi贸n
|
|
|
|
| 55 |
|
| 56 |
return demo
|
| 57 |
|
| 58 |
+
# Inicia Gradio y el backend de FastAPI
|
| 59 |
demo = build_interface()
|
| 60 |
+
|
| 61 |
+
if __name__ == "__main__":
|
| 62 |
+
uvicorn.run(app, host="0.0.0.0", port=7860)
|