Spaces:
Paused
Paused
Update stream_server.py
Browse files- stream_server.py +4 -4
stream_server.py
CHANGED
@@ -99,6 +99,7 @@ async def add_video(video_name, output_path, audio_duration):
|
|
99 |
|
100 |
video_names.append(video_name)
|
101 |
segment_duration = 3
|
|
|
102 |
full_segments = int(audio_duration // segment_duration)
|
103 |
remaining_duration = audio_duration % segment_duration
|
104 |
|
@@ -115,6 +116,7 @@ async def add_video(video_name, output_path, audio_duration):
|
|
115 |
new_segment_path = f"/live_stream/video_stream{i}.ts"
|
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:
|
@@ -127,10 +129,10 @@ async def add_video(video_name, output_path, audio_duration):
|
|
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 |
-
|
131 |
|
132 |
# Add #EXT-X-ENDLIST only once after all segments have been added
|
133 |
-
if
|
134 |
with open(output_path, 'a') as m3u8_file:
|
135 |
m3u8_file.write("#EXT-X-ENDLIST\n")
|
136 |
|
@@ -198,8 +200,6 @@ def generate_m3u8(video_duration, output_path,segment_duration=3):
|
|
198 |
m3u8_content += f"#EXT-X-TARGETDURATION:{segment_duration}\n"
|
199 |
m3u8_content += "#EXT-X-VERSION:4\n"
|
200 |
m3u8_content += "#EXT-X-MEDIA-SEQUENCE:1\n"
|
201 |
-
# m3u8_content += f"#EXTINF:{segment_duration:.6f},\n"
|
202 |
-
# m3u8_content += f"/live_stream/video_stream{i + 1}.ts\n"
|
203 |
|
204 |
# # Calculate the number of full segments and the remaining duration
|
205 |
|
|
|
99 |
|
100 |
video_names.append(video_name)
|
101 |
segment_duration = 3
|
102 |
+
total_processed_duration = 0
|
103 |
full_segments = int(audio_duration // segment_duration)
|
104 |
remaining_duration = audio_duration % segment_duration
|
105 |
|
|
|
116 |
new_segment_path = f"/live_stream/video_stream{i}.ts"
|
117 |
if new_segment_path not in existing_segments:
|
118 |
new_segments.append(new_segment_path)
|
119 |
+
total_processed_duration += segment_duration
|
120 |
|
121 |
|
122 |
with open(output_path, 'a') as m3u8_file:
|
|
|
129 |
if remaining_segment_path not in existing_segments:
|
130 |
m3u8_file.write(f"#EXTINF:{remaining_duration:.3f},\n")
|
131 |
m3u8_file.write(f"{remaining_segment_path}\n")
|
132 |
+
total_processed_duration += remaining_duration
|
133 |
|
134 |
# Add #EXT-X-ENDLIST only once after all segments have been added
|
135 |
+
if total_processed_duration == video_duration:
|
136 |
with open(output_path, 'a') as m3u8_file:
|
137 |
m3u8_file.write("#EXT-X-ENDLIST\n")
|
138 |
|
|
|
200 |
m3u8_content += f"#EXT-X-TARGETDURATION:{segment_duration}\n"
|
201 |
m3u8_content += "#EXT-X-VERSION:4\n"
|
202 |
m3u8_content += "#EXT-X-MEDIA-SEQUENCE:1\n"
|
|
|
|
|
203 |
|
204 |
# # Calculate the number of full segments and the remaining duration
|
205 |
|