Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions app/core/media/ffmpeg_builders/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,17 @@ def _get_basic_ffmpeg_command(self) -> list[str]:
# FFmpeg 8 rejects container/extension mismatches in strict mode.
hls_input_options = ["-extension_picky", "0"]

# -reconnect* are HTTP-protocol *input* options: they only take effect
# before -i. Placing them after -i (output options area) made ffmpeg
# silently drop them, so automatic reconnection never worked. They are
# only valid for http(s) inputs. The boolean flags need explicit
# values — two adjacent bare flags make ffmpeg try to parse the next
# option name as the value ("Unable to parse ... as boolean") and the
# whole command fails to start.
reconnect_options = []
if self.record_url.startswith(("http://", "https://")):
reconnect_options = ["-reconnect_delay_max", "60", "-reconnect_streamed", "1", "-reconnect_at_eof", "1"]

# fmt: off
command = [
"ffmpeg",
Expand All @@ -98,13 +109,11 @@ def _get_basic_ffmpeg_command(self) -> list[str]:
"-fflags", "+discardcorrupt+igndts",
"-re",
*hls_input_options,
*reconnect_options,
"-i", self.record_url,
"-bufsize", config["bufsize"],
"-sn",
"-dn",
"-reconnect_delay_max", "60",
"-reconnect_streamed",
"-reconnect_at_eof",
"-max_muxing_queue_size", config["max_muxing_queue_size"],
"-correct_ts_overflow", "1",
"-avoid_negative_ts", "1",
Expand Down
34 changes: 22 additions & 12 deletions app/core/recording/record_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,8 +255,13 @@ async def periodic_check():
else:
logger.info("Periodic live check task already running globally, skipping initialization")

async def check_if_live(self, recording: Recording):
"""Check if the live stream is available, fetch stream data and update is_live status."""
async def check_if_live(self, recording: Recording, manual_start: bool = False):
"""Check if the live stream is available, fetch stream data and update is_live status.

``manual_start`` is set when the user explicitly starts a recording from
the card button: it bypasses the per-room "only notify, don't record"
setting so a manual click really starts ffmpeg (issue #504).
"""

recording.manually_stopped = False
if recording.is_recording or recording.stopping_in_progress:
Expand Down Expand Up @@ -389,7 +394,7 @@ async def check_if_live(self, recording: Recording):
BackgroundService.get_instance().add_task(msg_manager.push_messages_sync, msg_title, push_content)
recording.notified_live_start = True

if not recording.only_notify_no_record:
if not recording.only_notify_no_record or manual_start:
recording.status_info = RecordingStatus.PREPARING_RECORDING
recording.loop_time_seconds = self.loop_time_seconds
self.start_update(recording)
Expand All @@ -412,15 +417,20 @@ async def check_if_live(self, recording: Recording):
asyncio.create_task(recorder.end_message_push())

recording.status_info = RecordingStatus.MONITORING
title = f"{stream_info.anchor_name or recording.streamer_name} - {self._[recording.quality]}"
if recording.streamer_name == self._["live_room"] or f"[{self._['is_live']}]" in recording.display_title:
recording.update(
{
"streamer_name": stream_info.anchor_name,
"title": title,
"display_title": title,
}
)
# Only auto-fill the streamer name while it still holds the default
# placeholder; a user-provided custom name must never be overwritten
# by the platform anchor name (issue #500).
is_default_name = recording.streamer_name == self._["live_room"]
if is_default_name and stream_info.anchor_name:
name_for_title = stream_info.anchor_name
else:
name_for_title = recording.streamer_name
title = f"{name_for_title} - {self._[recording.quality]}"
if is_default_name or f"[{self._['is_live']}]" in recording.display_title:
updates = {"title": title, "display_title": title}
if is_default_name and stream_info.anchor_name:
updates["streamer_name"] = stream_info.anchor_name
recording.update(updates)
self.services.run_coro(self.persist_recordings())

recording.is_checking = False
Expand Down
7 changes: 5 additions & 2 deletions app/ui/components/business/recording_card.py
Original file line number Diff line number Diff line change
Expand Up @@ -320,9 +320,12 @@ async def on_toggle_recording(self, recording: Recording):
await self.app.snack_bar.show_snack_bar(self._["stop_record_tip"])
else:
if recording.monitor_status:
await self.app.record_manager.check_if_live(recording)
# manual_start bypasses the "only notify, don't record"
# room setting so the click really launches ffmpeg; the
# previous extra start_update() call only flipped the
# is_recording flag and produced a fake recording (#504).
await self.app.record_manager.check_if_live(recording, manual_start=True)
if recording.is_live:
self.app.record_manager.start_update(recording)
await self.app.snack_bar.show_snack_bar(self._["pre_record_tip"], bgcolor=ft.Colors.PRIMARY)
else:
await self.app.snack_bar.show_snack_bar(self._["is_not_live_tip"])
Expand Down
Loading