From a046dc5801fac5945da2f72e85f1a37204bee59a Mon Sep 17 00:00:00 2001 From: Kieran Date: Mon, 16 Jun 2025 13:30:41 +0100 Subject: [PATCH] fix: make HLS segment length match encoding params --- crates/core/src/egress/hls.rs | 2 -- crates/core/src/mux/hls.rs | 17 +++++++---------- crates/core/src/pipeline/runner.rs | 1 - crates/zap-stream/src/api.rs | 2 ++ 4 files changed, 9 insertions(+), 13 deletions(-) diff --git a/crates/core/src/egress/hls.rs b/crates/core/src/egress/hls.rs index 613f5cc..23fcc8e 100644 --- a/crates/core/src/egress/hls.rs +++ b/crates/core/src/egress/hls.rs @@ -19,7 +19,6 @@ impl HlsEgress { pub fn new<'a>( id: &Uuid, out_dir: &str, - segment_length: f32, encoders: impl Iterator, segment_type: SegmentType, ) -> Result { @@ -27,7 +26,6 @@ impl HlsEgress { mux: HlsMuxer::new( id, PathBuf::from(out_dir).join(Self::PATH).to_str().unwrap(), - segment_length, encoders, segment_type, )?, diff --git a/crates/core/src/mux/hls.rs b/crates/core/src/mux/hls.rs index 8a83b5e..52c7b73 100644 --- a/crates/core/src/mux/hls.rs +++ b/crates/core/src/mux/hls.rs @@ -186,7 +186,6 @@ impl PartialSegmentInfo { impl HlsVariant { pub fn new<'a>( out_dir: &'a str, - segment_length: f32, group: usize, encoded_vars: impl Iterator, segment_type: SegmentType, @@ -217,6 +216,7 @@ impl HlsVariant { let mut streams = Vec::new(); let mut ref_stream_index = -1; let mut has_video = false; + let mut seg_size = 1.0; for (var, enc) in encoded_vars { match var { @@ -231,6 +231,10 @@ impl HlsVariant { has_video = true; // Always use video stream as reference for segmentation ref_stream_index = stream_idx as _; + let v_seg = v.keyframe_interval as f32 / v.fps; + if v_seg > seg_size { + seg_size = v_seg; + } }, VariantStream::Audio(a) => unsafe { let stream = mux.add_stream_encoder(enc)?; @@ -269,7 +273,7 @@ impl HlsVariant { } Ok(Self { name: name.clone(), - segment_length, + segment_length: seg_size, segment_window: 30.0, mux, streams, @@ -683,7 +687,6 @@ impl HlsMuxer { pub fn new<'a>( id: &Uuid, out_dir: &str, - segment_length: f32, encoders: impl Iterator, segment_type: SegmentType, ) -> Result { @@ -697,13 +700,7 @@ impl HlsMuxer { .sorted_by(|a, b| a.0.group_id().cmp(&b.0.group_id())) .chunk_by(|a| a.0.group_id()) { - let var = HlsVariant::new( - base.to_str().unwrap(), - segment_length, - k, - group, - segment_type, - )?; + let var = HlsVariant::new(base.to_str().unwrap(), k, group, segment_type)?; vars.push(var); } diff --git a/crates/core/src/pipeline/runner.rs b/crates/core/src/pipeline/runner.rs index 59da94d..e71d575 100644 --- a/crates/core/src/pipeline/runner.rs +++ b/crates/core/src/pipeline/runner.rs @@ -707,7 +707,6 @@ impl PipelineRunner { let hls = HlsEgress::new( &self.connection.id, &self.out_dir, - 6.0, // TODO: configure segment length encoders, SegmentType::MPEGTS, )?; diff --git a/crates/zap-stream/src/api.rs b/crates/zap-stream/src/api.rs index 2c36838..9826400 100644 --- a/crates/zap-stream/src/api.rs +++ b/crates/zap-stream/src/api.rs @@ -571,6 +571,8 @@ impl Api { }) .collect(); + // TODO: past streams should include a history entry + Ok(HistoryResponse { items, page: 0,