SorovotPelo commited on
Commit
f1e9883
verified
1 Parent(s): 6af7d49

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -14
app.py CHANGED
@@ -7,35 +7,36 @@ from fastapi import FastAPI, Response
7
 
8
  app = FastAPI()
9
 
10
- # Archivo de audio y rutas de salida
11
- audio_file = "test.mp3"
12
- hls_output = "stream.m3u8"
13
- hls_segment_prefix = "stream"
14
 
15
- # Comando FFmpeg para transmitir audio en HLS
16
  ffmpeg_command = [
17
  'ffmpeg',
18
  '-re',
19
- '-i', audio_file,
 
 
20
  '-c:a', 'aac',
21
  '-b:a', '128k',
22
  '-f', 'hls',
23
- '-live_start_index', '-1',
24
  '-hls_time', '10',
25
  '-hls_list_size', '0',
26
  '-hls_flags', 'delete_segments',
27
- '-hls_segment_filename', f'{hls_segment_prefix}%d.ts', # Nombre para los segmentos
28
  hls_output
29
  ]
30
 
31
- def stream_audio():
32
  # Ejecuta el comando FFmpeg para iniciar la transmisi贸n
33
  process = subprocess.Popen(ffmpeg_command)
34
  process.wait()
35
 
36
- def start_audio_streaming():
37
- audio_process = Process(target=stream_audio)
38
- audio_process.start()
39
 
40
  @app.on_event("startup")
41
  async def startup_event():
@@ -47,7 +48,7 @@ async def startup_event():
47
 
48
  @app.get("/")
49
  async def read_root():
50
- return {"message": "Servidor de Radio M3U8 Activo"}
51
 
52
  @app.get("/stream.m3u8")
53
  def get_m3u8():
@@ -68,5 +69,5 @@ def get_segment(segment: int):
68
  return Response(status_code=404, content="Segment not found")
69
 
70
  if __name__ == "__main__":
71
- start_audio_streaming()
72
  uvicorn.run(app, host="0.0.0.0", port=7860)
 
7
 
8
  app = FastAPI()
9
 
10
+ # Archivo de video y rutas de salida
11
+ video_file = "/app/simpsons.mp4"
12
+ hls_output = "/app/stream.m3u8"
13
+ hls_segment_prefix = "/app/stream"
14
 
15
+ # Comando FFmpeg para transmitir video en HLS
16
  ffmpeg_command = [
17
  'ffmpeg',
18
  '-re',
19
+ '-i', video_file,
20
+ '-c:v', 'libx264',
21
+ '-crf', '23',
22
  '-c:a', 'aac',
23
  '-b:a', '128k',
24
  '-f', 'hls',
 
25
  '-hls_time', '10',
26
  '-hls_list_size', '0',
27
  '-hls_flags', 'delete_segments',
28
+ '-hls_segment_filename', f'{hls_segment_prefix}%d.ts',
29
  hls_output
30
  ]
31
 
32
+ def stream_video():
33
  # Ejecuta el comando FFmpeg para iniciar la transmisi贸n
34
  process = subprocess.Popen(ffmpeg_command)
35
  process.wait()
36
 
37
+ def start_video_streaming():
38
+ video_process = Process(target=stream_video)
39
+ video_process.start()
40
 
41
  @app.on_event("startup")
42
  async def startup_event():
 
48
 
49
  @app.get("/")
50
  async def read_root():
51
+ return {"message": "Servidor de Video M3U8 Activo"}
52
 
53
  @app.get("/stream.m3u8")
54
  def get_m3u8():
 
69
  return Response(status_code=404, content="Segment not found")
70
 
71
  if __name__ == "__main__":
72
+ start_video_streaming()
73
  uvicorn.run(app, host="0.0.0.0", port=7860)