fix: hls output fix

This commit is contained in:
2024-11-13 18:41:45 +00:00
parent 0b8742bd25
commit e2c96005cf
5 changed files with 28 additions and 20 deletions

2
Cargo.lock generated
View File

@ -563,7 +563,7 @@ dependencies = [
[[package]]
name = "ffmpeg-rs-raw"
version = "0.1.0"
source = "git+https://git.v0l.io/Kieran/ffmpeg-rs-raw.git?rev=6d443a24bcbe53c0a02a9dce3e41d22815229585#6d443a24bcbe53c0a02a9dce3e41d22815229585"
source = "git+https://git.v0l.io/Kieran/ffmpeg-rs-raw.git?rev=dc778d12a994f47236cb168b6145a2a563dba1ab#dc778d12a994f47236cb168b6145a2a563dba1ab"
dependencies = [
"anyhow",
"ffmpeg-sys-the-third",

View File

@ -9,7 +9,7 @@ srt = ["dep:srt-tokio"]
test-source = ["dep:resvg", "dep:usvg", "dep:tiny-skia", "dep:fontdue", "dep:ringbuf"]
[dependencies]
ffmpeg-rs-raw = { git = "https://git.v0l.io/Kieran/ffmpeg-rs-raw.git", rev = "6d443a24bcbe53c0a02a9dce3e41d22815229585" }
ffmpeg-rs-raw = { git = "https://git.v0l.io/Kieran/ffmpeg-rs-raw.git", rev = "dc778d12a994f47236cb168b6145a2a563dba1ab" }
tokio = { version = "1.36.0", features = ["rt", "rt-multi-thread", "macros"] }
anyhow = { version = "^1.0.91", features = ["backtrace"] }

View File

@ -56,7 +56,7 @@ impl HlsEgress {
let mut opts = HashMap::new();
opts.insert(
"hls_segment_filename".to_string(),
base.join("%v/live.m3u8").to_string_lossy().to_string(),
format!("{}/%v/%05d.ts", base.display()),
);
opts.insert("master_pl_name".to_string(), "live.m3u8".to_string());
opts.insert("master_pl_publish_rate".to_string(), "10".to_string());
@ -65,7 +65,11 @@ impl HlsEgress {
let muxer = unsafe {
let mut m = Muxer::builder()
.with_output_path(base.to_str().unwrap(), Some("hls"), Some(opts))?
.with_output_path(
base.join("%v/live.m3u8").to_str().unwrap(),
Some("hls"),
Some(opts),
)?
.build()?;
for e in encoded {
m.add_stream_encoder(e)?;

View File

@ -109,6 +109,13 @@ impl PipelineRunner {
.iter()
.filter(|v| v.src_index() == src_index as usize);
for var in pkt_vars {
let enc = if let Some(enc) = self.encoders.get_mut(&var.id()) {
enc
} else {
//warn!("Frame had nowhere to go in {} :/", var.id());
continue;
};
let frame = match var {
VariantStream::Video(v) => {
if let Some(s) = self.scalers.get_mut(&v.id()) {
@ -119,7 +126,9 @@ impl PipelineRunner {
}
VariantStream::Audio(a) => {
if let Some(r) = self.resampler.get_mut(&a.id()) {
r.process_frame(frame)?
let frame_size = (*enc.codec_context()).frame_size;
// TODO: resample audio fifo
r.process_frame(frame, frame_size)?
} else {
frame
}
@ -127,18 +136,13 @@ impl PipelineRunner {
_ => frame,
};
let packets = if let Some(enc) = self.encoders.get_mut(&var.id()) {
enc.encode_frame(frame)?
} else {
//warn!("Frame had nowhere to go in {} :/", var.id());
continue;
};
let packets = enc.encode_frame(frame)?;
// pass new packets to egress
for mut pkt in packets {
for eg in self.egress.iter_mut() {
for pkt in packets.iter() {
eg.process_pkt(*pkt, &var.id())?;
eg.process_pkt(pkt, &var.id())?;
}
av_packet_free(&mut pkt);
}
}
}

View File

@ -74,7 +74,7 @@ impl Webhook {
codec: 86018,
channels: 2,
sample_rate: 48_000,
sample_fmt: "flt".to_owned(),
sample_fmt: "fltp".to_owned(),
}));
}
@ -83,16 +83,16 @@ impl Webhook {
id: Uuid::new_v4(),
variants: vars,
egress: vec![
EgressType::Recorder(EgressConfig {
/*EgressType::Recorder(EgressConfig {
name: "REC".to_owned(),
out_dir: self.config.output_dir.clone(),
variants: var_ids,
}),
/*EgressType::HLS(EgressConfig {
}),*/
EgressType::HLS(EgressConfig {
name: "HLS".to_owned(),
out_dir: self.config.output_dir.clone(),
variants: var_ids,
}),*/
}),
],
}
}