diff --git a/Cargo.lock b/Cargo.lock index acc1ca5..18aca45 100755 --- a/Cargo.lock +++ b/Cargo.lock @@ -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", diff --git a/Cargo.toml b/Cargo.toml index dbe7e5b..8aa8081 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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"] } diff --git a/src/egress/hls.rs b/src/egress/hls.rs index 13460d0..8fc970b 100644 --- a/src/egress/hls.rs +++ b/src/egress/hls.rs @@ -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)?; diff --git a/src/pipeline/runner.rs b/src/pipeline/runner.rs index 2a43de9..8159e12 100644 --- a/src/pipeline/runner.rs +++ b/src/pipeline/runner.rs @@ -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 eg in self.egress.iter_mut() { - for pkt in packets.iter() { - eg.process_pkt(*pkt, &var.id())?; + for mut pkt in packets { + for eg in self.egress.iter_mut() { + eg.process_pkt(pkt, &var.id())?; } + av_packet_free(&mut pkt); } } } diff --git a/src/webhook.rs b/src/webhook.rs index 3c319b1..aa68684 100644 --- a/src/webhook.rs +++ b/src/webhook.rs @@ -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, - }),*/ + }), ], } }