SorovotPelo commited on
Commit
6cd26b2
verified
1 Parent(s): d4a56d8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -59
app.py CHANGED
@@ -1,70 +1,36 @@
1
  import gradio as gr
2
- import cv2
3
- import numpy as np
4
  import subprocess
5
- import threading
6
 
7
- def create_dummy_frame(width, height):
8
- # Crear un frame de ejemplo
9
- frame = np.random.randint(0, 256, (height, width, 3), dtype=np.uint8)
10
- return frame
 
 
11
 
12
- def start_streaming(service, stream_key):
13
- # Ocultar la clave de transmisi贸n
14
- hidden_key = '*' * len(stream_key)
15
-
16
- # Configurar el servicio RTMP
17
- if service == "YouTube":
18
- rtmp_url = f"rtmp://a.rtmp.youtube.com/live2/{stream_key}"
19
- elif service == "Twitch":
20
- rtmp_url = f"rtmp://live.twitch.tv/app/{stream_key}"
21
- else:
22
- return "Servicio no soportado"
23
 
24
- # Configurar la captura de pantalla simulada
25
- screen_width, screen_height = 1280, 720 # Tama帽o de ejemplo
26
 
27
- # Configurar FFmpeg para la transmisi贸n
28
- command = [
29
- 'ffmpeg',
30
- '-f', 'rawvideo',
31
- '-pix_fmt', 'bgr24',
32
- '-s', f"{screen_width}x{screen_height}",
33
- '-r', '30',
34
- '-i', '-',
35
- '-c:v', 'libx264',
36
- '-preset', 'ultrafast',
37
- '-f', 'flv',
38
- rtmp_url
39
- ]
40
 
41
- # Iniciar el proceso de FFmpeg
42
- process = subprocess.Popen(command, stdin=subprocess.PIPE)
43
 
44
- def stream_screen():
45
- while True:
46
- # Crear un frame de ejemplo
47
- frame = create_dummy_frame(screen_width, screen_height)
48
 
49
- # Enviar el frame a FFmpeg
50
- process.stdin.write(frame.tobytes())
51
 
52
- # Iniciar el streaming en un hilo separado
53
- threading.Thread(target=stream_stream, daemon=True).start()
54
 
55
- return f"Transmisi贸n simulada iniciada en {service} (Clave: {hidden_key})"
56
-
57
- # Crear la interfaz de Gradio
58
- iface = gr.Interface(
59
- fn=start_streaming,
60
- inputs=[
61
- gr.Dropdown(["YouTube", "Twitch"], label="Servicio de transmisi贸n"),
62
- gr.Textbox(type="password", label="Clave de transmisi贸n")
63
- ],
64
- outputs="text",
65
- title="Simulaci贸n de transmisi贸n en vivo",
66
- description="Selecciona tu servicio de transmisi贸n, ingresa tu clave y simula una transmisi贸n en vivo."
67
- )
68
-
69
- # Iniciar la interfaz de Gradio
70
- iface.launch()
 
1
  import gradio as gr
2
+ import os
 
3
  import subprocess
 
4
 
5
+ # Funci贸n para iniciar la transmisi贸n
6
+ def start_streaming(rtmp_server, stream_key):
7
+ # Comando FFmpeg para la transmisi贸n
8
+ command = f"ffmpeg -f x11grab -i :0.0 -c:v libx264 -b:v 1000k -f flv {rtmp_server}/{stream_key}"
9
+ process = subprocess.Popen(command, shell=True)
10
+ return "Transmisi贸n en vivo iniciada"
11
 
12
+ # Interfaz Gradio
13
+ 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
24
+ start_button = gr.Button("Iniciar Transmisi贸n")
25
 
26
+ # Mensaje de salida
27
+ output = gr.Textbox(label="Estado", interactive=False)
 
 
28
 
29
+ # L贸gica del bot贸n
30
+ start_button.click(start_streaming, inputs=[rtmp_server, stream_key], outputs=output)
31
 
32
+ return demo
 
33
 
34
+ # Ejecuta la interfaz
35
+ demo = build_interface()
36
+ demo.launch()