Skip to content

Commit 39a3ccf

Browse files
committed
feat: add record segment for flv
1 parent 794e0d3 commit 39a3ccf

File tree

2 files changed

+24
-11
lines changed

2 files changed

+24
-11
lines changed

app/core/ffmpeg_builders/video/flv.py

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,26 @@
44
class FLVCommandBuilder(FFmpegCommandBuilder):
55
def build_command(self) -> list[str]:
66
command = self._get_basic_ffmpeg_command()
7-
additional_commands = [
8-
"-map", "0",
9-
"-c:v", "copy",
10-
"-c:a", "copy",
11-
"-bsf:a", "aac_adtstoasc",
12-
"-f", "flv",
13-
self.full_path,
14-
]
7+
if self.segment_record:
8+
additional_commands = [
9+
"-map", "0",
10+
"-c:v", "copy",
11+
"-c:a", "copy",
12+
"-bsf:a", "aac_adtstoasc",
13+
"-f", "segment",
14+
"-segment_time", str(self.segment_time),
15+
"-segment_format", "flv",
16+
"-reset_timestamps", "1",
17+
self.full_path
18+
]
19+
else:
20+
additional_commands = [
21+
"-map", "0",
22+
"-c:v", "copy",
23+
"-c:a", "copy",
24+
"-bsf:a", "aac_adtstoasc",
25+
"-f", "flv",
26+
self.full_path
27+
]
1528
command.extend(additional_commands)
1629
return command

app/core/stream_manager.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -127,9 +127,9 @@ def _get_output_dir(self, stream_info: StreamData) -> str:
127127
self.app.page.run_task(self.app.record_manager.persist_recordings)
128128
return output_dir
129129

130-
def _get_save_path(self, filename: str) -> str:
130+
def _get_save_path(self, filename: str, use_direct_download: bool = False) -> str:
131131
suffix = self.save_format
132-
suffix = "_%03d." + suffix if self.segment_record and self.save_format != "flv" else "." + suffix
132+
suffix = "_%03d." + suffix if self.segment_record and not use_direct_download else "." + suffix
133133
save_file_path = os.path.join(self.output_dir, filename + suffix).replace(" ", "_")
134134
return save_file_path.replace("\\", "/")
135135

@@ -207,7 +207,7 @@ async def start_recording(self, stream_info: StreamData):
207207
self.save_format, use_direct_download = self._get_record_format(stream_info)
208208
filename = self._get_filename(stream_info)
209209
self.output_dir = self._get_output_dir(stream_info)
210-
save_path = self._get_save_path(filename)
210+
save_path = self._get_save_path(filename, use_direct_download)
211211
logger.info(f"Save Path: {save_path}")
212212
self.recording.recording_dir = os.path.dirname(save_path)
213213
os.makedirs(self.recording.recording_dir, exist_ok=True)

0 commit comments

Comments
 (0)