From 5fc7da4bfd76ea45d016ca6eef6431afb5858899 Mon Sep 17 00:00:00 2001 From: ThisBirchWood Date: Wed, 15 Jan 2025 15:06:10 +0000 Subject: [PATCH] Converts UDP stream to HLS stream with FFMPEG --- core/stream_generator.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 core/stream_generator.py diff --git a/core/stream_generator.py b/core/stream_generator.py new file mode 100644 index 0000000..482144f --- /dev/null +++ b/core/stream_generator.py @@ -0,0 +1,12 @@ +from subprocess import Popen, PIPE + +def generate_stream(STREAM_PATH, STREAM_NAME): + """Function to run FFmpeg to convert the stream and create HLS""" + # FFmpeg command to receive the stream and convert to HLS + command = [ + 'ffmpeg', '-i', 'udp://127.0.0.1:1935/live', '-c:v', 'libx264', '-preset', 'veryfast', + '-c:a', 'aac', '-ar', '44100', '-ac', '2', '-f', 'hls', '-hls_time', '4', '-hls_list_size', '5', + '-hls_segment_filename', f'{STREAM_PATH}/{STREAM_NAME}%03d.ts', f"{STREAM_PATH}/{STREAM_NAME}.m3u8" + ] + + Popen(command, stdout=PIPE, stderr=PIPE) \ No newline at end of file