Spaces:
Paused
Paused
Update stream_server.py
Browse files- stream_server.py +3 -5
stream_server.py
CHANGED
@@ -3,7 +3,6 @@ import subprocess
|
|
3 |
import pathlib
|
4 |
# from fastapi import HTTPException
|
5 |
import asyncio
|
6 |
-
import logging
|
7 |
|
8 |
# Define base directories
|
9 |
BASE_DIR = pathlib.Path('./videos').resolve()
|
@@ -102,7 +101,7 @@ async def add_video(video_name, output_path, audio_duration):
|
|
102 |
segment_duration = 3
|
103 |
full_segments = int(audio_duration // segment_duration)
|
104 |
remaining_duration = audio_duration % segment_duration
|
105 |
-
|
106 |
existing_segments = set()
|
107 |
if output_path:
|
108 |
with open(output_path, 'r') as m3u8_file:
|
@@ -117,7 +116,7 @@ async def add_video(video_name, output_path, audio_duration):
|
|
117 |
if new_segment_path not in existing_segments:
|
118 |
new_segments.append(new_segment_path)
|
119 |
|
120 |
-
|
121 |
with open(output_path, 'a') as m3u8_file:
|
122 |
for segment in new_segments:
|
123 |
m3u8_file.write(f"#EXTINF:{segment_duration:.3f},\n")
|
@@ -128,8 +127,7 @@ async def add_video(video_name, output_path, audio_duration):
|
|
128 |
if remaining_segment_path not in existing_segments:
|
129 |
m3u8_file.write(f"#EXTINF:{remaining_duration:.3f},\n")
|
130 |
m3u8_file.write(f"{remaining_segment_path}\n")
|
131 |
-
remaining_duration = 0
|
132 |
-
logging.info(f"Added remaining segment: {remaining_segment_path}")
|
133 |
|
134 |
# Add #EXT-X-ENDLIST only once after all segments have been added
|
135 |
if remaining_duration == 0:
|
|
|
3 |
import pathlib
|
4 |
# from fastapi import HTTPException
|
5 |
import asyncio
|
|
|
6 |
|
7 |
# Define base directories
|
8 |
BASE_DIR = pathlib.Path('./videos').resolve()
|
|
|
101 |
segment_duration = 3
|
102 |
full_segments = int(audio_duration // segment_duration)
|
103 |
remaining_duration = audio_duration % segment_duration
|
104 |
+
|
105 |
existing_segments = set()
|
106 |
if output_path:
|
107 |
with open(output_path, 'r') as m3u8_file:
|
|
|
116 |
if new_segment_path not in existing_segments:
|
117 |
new_segments.append(new_segment_path)
|
118 |
|
119 |
+
|
120 |
with open(output_path, 'a') as m3u8_file:
|
121 |
for segment in new_segments:
|
122 |
m3u8_file.write(f"#EXTINF:{segment_duration:.3f},\n")
|
|
|
127 |
if remaining_segment_path not in existing_segments:
|
128 |
m3u8_file.write(f"#EXTINF:{remaining_duration:.3f},\n")
|
129 |
m3u8_file.write(f"{remaining_segment_path}\n")
|
130 |
+
remaining_duration = 0
|
|
|
131 |
|
132 |
# Add #EXT-X-ENDLIST only once after all segments have been added
|
133 |
if remaining_duration == 0:
|