parse hls args from cmd args

This commit is contained in:
Muaz Ahmad 2023-10-25 15:00:59 +05:00
parent 0d4dbdc780
commit 5c323970a3

View file

@ -9,11 +9,11 @@ use std::sync::mpsc;
use std::thread;
use std::time::Duration;
fn init() -> Result<[mpsc::Receiver<Box<dyn std::error::Error + Send + Sync>>; 4], Box<dyn std::error::Error>>{
fn init(args: util::HLSArgs) -> Result<[mpsc::Receiver<Box<dyn std::error::Error + Send + Sync>>; 4], Box<dyn std::error::Error>>{
let (v_out, a_out, metadata, demux_err_recv) = demux::spawn()?;
let (raw_v_out, raw_a_out, decode_err_recv) = decode::spawn(v_out, a_out, metadata.clone())?;
let (enc_v_out, enc_a_out, encode_err_recv) = encode::spawn(raw_v_out, raw_a_out, metadata.clone(), util::VideoCodec::AV1, util::AudioCodec::OPUS)?;
let muxer_err_recv = muxer::spawn(enc_v_out, enc_a_out, metadata.clone(), util::HLSArgs{segment_time: 4, segment_prepend: String::from("/vid/tmp/"), max_segments: 4})?;
let muxer_err_recv = muxer::spawn(enc_v_out, enc_a_out, metadata.clone(), args)?;
return Ok([demux_err_recv, decode_err_recv, encode_err_recv, muxer_err_recv]);
}
@ -42,8 +42,18 @@ fn process(error_handles: [mpsc::Receiver<Box<dyn std::error::Error + Send + Syn
}
}
fn parse_args() -> util::HLSArgs {
let mut args = std::env::args();
args.next();
util::HLSArgs {
segment_time: args.next().expect("no time interval").parse().expect("not int"),
segment_prepend: args.next().expect("no prepend"),
max_segments: args.next().expect("no max list size").parse().expect("not int"),
}
}
fn main() {
let error_handles = match init() {
let error_handles = match init(parse_args()) {
Ok(x) => x,
Err(err) => {dbg!(err); exit(1);}
};