mirror of
https://github.com/v0l/zap-stream-core.git
synced 2025-06-18 12:27:12 +00:00
fix: make HLS segment length match encoding params
This commit is contained in:
@ -19,7 +19,6 @@ impl HlsEgress {
|
|||||||
pub fn new<'a>(
|
pub fn new<'a>(
|
||||||
id: &Uuid,
|
id: &Uuid,
|
||||||
out_dir: &str,
|
out_dir: &str,
|
||||||
segment_length: f32,
|
|
||||||
encoders: impl Iterator<Item = (&'a VariantStream, &'a Encoder)>,
|
encoders: impl Iterator<Item = (&'a VariantStream, &'a Encoder)>,
|
||||||
segment_type: SegmentType,
|
segment_type: SegmentType,
|
||||||
) -> Result<Self> {
|
) -> Result<Self> {
|
||||||
@ -27,7 +26,6 @@ impl HlsEgress {
|
|||||||
mux: HlsMuxer::new(
|
mux: HlsMuxer::new(
|
||||||
id,
|
id,
|
||||||
PathBuf::from(out_dir).join(Self::PATH).to_str().unwrap(),
|
PathBuf::from(out_dir).join(Self::PATH).to_str().unwrap(),
|
||||||
segment_length,
|
|
||||||
encoders,
|
encoders,
|
||||||
segment_type,
|
segment_type,
|
||||||
)?,
|
)?,
|
||||||
|
@ -186,7 +186,6 @@ impl PartialSegmentInfo {
|
|||||||
impl HlsVariant {
|
impl HlsVariant {
|
||||||
pub fn new<'a>(
|
pub fn new<'a>(
|
||||||
out_dir: &'a str,
|
out_dir: &'a str,
|
||||||
segment_length: f32,
|
|
||||||
group: usize,
|
group: usize,
|
||||||
encoded_vars: impl Iterator<Item = (&'a VariantStream, &'a Encoder)>,
|
encoded_vars: impl Iterator<Item = (&'a VariantStream, &'a Encoder)>,
|
||||||
segment_type: SegmentType,
|
segment_type: SegmentType,
|
||||||
@ -217,6 +216,7 @@ impl HlsVariant {
|
|||||||
let mut streams = Vec::new();
|
let mut streams = Vec::new();
|
||||||
let mut ref_stream_index = -1;
|
let mut ref_stream_index = -1;
|
||||||
let mut has_video = false;
|
let mut has_video = false;
|
||||||
|
let mut seg_size = 1.0;
|
||||||
|
|
||||||
for (var, enc) in encoded_vars {
|
for (var, enc) in encoded_vars {
|
||||||
match var {
|
match var {
|
||||||
@ -231,6 +231,10 @@ impl HlsVariant {
|
|||||||
has_video = true;
|
has_video = true;
|
||||||
// Always use video stream as reference for segmentation
|
// Always use video stream as reference for segmentation
|
||||||
ref_stream_index = stream_idx as _;
|
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 {
|
VariantStream::Audio(a) => unsafe {
|
||||||
let stream = mux.add_stream_encoder(enc)?;
|
let stream = mux.add_stream_encoder(enc)?;
|
||||||
@ -269,7 +273,7 @@ impl HlsVariant {
|
|||||||
}
|
}
|
||||||
Ok(Self {
|
Ok(Self {
|
||||||
name: name.clone(),
|
name: name.clone(),
|
||||||
segment_length,
|
segment_length: seg_size,
|
||||||
segment_window: 30.0,
|
segment_window: 30.0,
|
||||||
mux,
|
mux,
|
||||||
streams,
|
streams,
|
||||||
@ -683,7 +687,6 @@ impl HlsMuxer {
|
|||||||
pub fn new<'a>(
|
pub fn new<'a>(
|
||||||
id: &Uuid,
|
id: &Uuid,
|
||||||
out_dir: &str,
|
out_dir: &str,
|
||||||
segment_length: f32,
|
|
||||||
encoders: impl Iterator<Item = (&'a VariantStream, &'a Encoder)>,
|
encoders: impl Iterator<Item = (&'a VariantStream, &'a Encoder)>,
|
||||||
segment_type: SegmentType,
|
segment_type: SegmentType,
|
||||||
) -> Result<Self> {
|
) -> Result<Self> {
|
||||||
@ -697,13 +700,7 @@ impl HlsMuxer {
|
|||||||
.sorted_by(|a, b| a.0.group_id().cmp(&b.0.group_id()))
|
.sorted_by(|a, b| a.0.group_id().cmp(&b.0.group_id()))
|
||||||
.chunk_by(|a| a.0.group_id())
|
.chunk_by(|a| a.0.group_id())
|
||||||
{
|
{
|
||||||
let var = HlsVariant::new(
|
let var = HlsVariant::new(base.to_str().unwrap(), k, group, segment_type)?;
|
||||||
base.to_str().unwrap(),
|
|
||||||
segment_length,
|
|
||||||
k,
|
|
||||||
group,
|
|
||||||
segment_type,
|
|
||||||
)?;
|
|
||||||
vars.push(var);
|
vars.push(var);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -707,7 +707,6 @@ impl PipelineRunner {
|
|||||||
let hls = HlsEgress::new(
|
let hls = HlsEgress::new(
|
||||||
&self.connection.id,
|
&self.connection.id,
|
||||||
&self.out_dir,
|
&self.out_dir,
|
||||||
6.0, // TODO: configure segment length
|
|
||||||
encoders,
|
encoders,
|
||||||
SegmentType::MPEGTS,
|
SegmentType::MPEGTS,
|
||||||
)?;
|
)?;
|
||||||
|
@ -571,6 +571,8 @@ impl Api {
|
|||||||
})
|
})
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
|
// TODO: past streams should include a history entry
|
||||||
|
|
||||||
Ok(HistoryResponse {
|
Ok(HistoryResponse {
|
||||||
items,
|
items,
|
||||||
page: 0,
|
page: 0,
|
||||||
|
Reference in New Issue
Block a user