From e2ca18d1207d9d28f8d2b6fe2011d594e4ace92c Mon Sep 17 00:00:00 2001 From: buenosairesam Date: Fri, 10 Apr 2026 02:56:04 -0300 Subject: [PATCH] improved livedelay --- cht/ui/mpv.py | 8 ++++++-- media/client/src/backends/subprocess.rs | 2 +- media/server/src/session.rs | 3 +++ 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/cht/ui/mpv.py b/cht/ui/mpv.py index 78e7049..80e7060 100644 --- a/cht/ui/mpv.py +++ b/cht/ui/mpv.py @@ -103,8 +103,12 @@ class Player: def load_live(self, url): """Load a live stream URL with low-latency options.""" self._player["cache"] = "no" - self._player["demuxer-max-bytes"] = "512KiB" - self._player["audio-buffer"] = 0.2 + self._player["demuxer-max-bytes"] = "256KiB" + self._player["demuxer-readahead-secs"] = 0 + self._player["audio-buffer"] = 0.1 + self._player["untimed"] = True + self._player["video-latency-hacks"] = True + self._player["interpolation"] = False log.info("mpv load_live: %s", url) self._player.loadfile(str(url), mode="replace") diff --git a/media/client/src/backends/subprocess.rs b/media/client/src/backends/subprocess.rs index 8b5450d..12bc605 100644 --- a/media/client/src/backends/subprocess.rs +++ b/media/client/src/backends/subprocess.rs @@ -158,7 +158,7 @@ fn spawn_ffmpeg(cfg: &SubprocessConfig) -> Result { "-init_hw_device".into(), format!("drm=drm:{}", cfg.device), "-init_hw_device".into(), "vaapi=va@drm".into(), // Video input (kmsgrab) - "-thread_queue_size".into(), "64".into(), + "-thread_queue_size".into(), "512".into(), "-device".into(), cfg.device.clone(), "-f".into(), "kmsgrab".into(), "-framerate".into(), cfg.fps.to_string(), diff --git a/media/server/src/session.rs b/media/server/src/session.rs index 6e4d522..39b4119 100644 --- a/media/server/src/session.rs +++ b/media/server/src/session.rs @@ -63,6 +63,8 @@ impl Session { let mut child = Command::new("ffmpeg") .args([ + "-fflags", "nobuffer", + "-flags", "low_delay", "-f", "h264", "-framerate", &fps.to_string(), "-i", "pipe:0", @@ -75,6 +77,7 @@ impl Session { // UDP relay for live display "-c:v", "copy", "-f", "mpegts", + "-flush_packets", "1", RELAY_URL, "-hide_banner", "-loglevel", "warning", ])