From: Kostya Shishkov Date: Mon, 18 Oct 2021 16:57:40 +0000 (+0200) Subject: support scale options X-Git-Url: https://git.nihav.org/?a=commitdiff_plain;ds=inline;h=df37d3b1df616e2b0a13d49bf0a9fb639a1efe27;p=nihav-encoder.git support scale options --- diff --git a/src/main.rs b/src/main.rs index d677791..0a36cc8 100644 --- a/src/main.rs +++ b/src/main.rs @@ -74,6 +74,7 @@ struct Transcoder { mux_opts: Vec, istr_opts: Vec, ostr_opts: Vec, + scale_opts: Vec<(String, String)>, decoders: Vec, Box, Box)>>, encoders: Vec, no_video: bool, @@ -405,6 +406,20 @@ impl Transcoder { } true } + fn parse_scale_options(&mut self, opts: &str) -> bool { + for opt in opts.split(',') { + let oval: Vec<_> = opt.split('=').collect(); + if oval.len() == 1 { + self.scale_opts.push((oval[0].to_string(), "".to_string())); + } else if oval.len() == 2 { + self.scale_opts.push((oval[0].to_string(), oval[1].to_string())); + } else { + println!("unrecognized option '{}'", opt); + return false; + } + } + true + } fn apply_decoder_options(&self, dec: &mut dyn NADecoder, str_id: u32) { if let Some(str_idx) = self.istr_opts.iter().position(|str| str.id == str_id) { let dec_opts = dec.get_supported_options(); @@ -456,7 +471,7 @@ impl Transcoder { OutputConvert::None } else { let ofmt = ScaleInfo { fmt: dvinfo.format, width: dvinfo.width, height: dvinfo.height }; - let ret = NAScale::new(ofmt, ofmt); + let ret = NAScale::new_with_options(ofmt, ofmt, &self.scale_opts); if ret.is_err() { println!("cannot create scaler"); return false; @@ -607,7 +622,7 @@ println!("stream {} ({}) can't be handled", istr.id, istr.get_info().get_name()) } } -fn encode_frame(dst_id: u32, encoder: &mut Box, cvt: &mut OutputConvert, frm: NAFrameRef) -> bool { +fn encode_frame(dst_id: u32, encoder: &mut Box, cvt: &mut OutputConvert, frm: NAFrameRef, scale_opts: &[(String, String)]) -> bool { let buf = frm.get_buffer(); let cbuf = match cvt { OutputConvert::None => buf, @@ -616,7 +631,7 @@ fn encode_frame(dst_id: u32, encoder: &mut Box, cvt: &mut OutputC let last_ifmt = scaler.get_in_fmt(); if cur_ifmt != last_ifmt { let ofmt = scaler.get_out_fmt(); - let ret = NAScale::new(cur_ifmt, ofmt); + let ret = NAScale::new_with_options(cur_ifmt, ofmt, scale_opts); if ret.is_err() { println!("error re-initialising scaler for {} -> {}", cur_ifmt, ofmt); return false; @@ -671,6 +686,7 @@ fn main() { println!(" --input inputfile - set input file"); println!(" --input-format fmt - force input format"); println!(" --demuxer-options options - set input demuxer options"); + println!(" --scale-options options - set scaler options"); println!(" --output outputfile - set output file"); println!(" --output-format fmt - force output format"); println!(" --muxer-options options - set output muxer options"); @@ -821,6 +837,13 @@ fn main() { return; } }, + "--scale-options" => { + next_arg!(args, arg_idx); + if !transcoder.parse_scale_options(&args[arg_idx]) { + println!("invalid scale option syntax"); + return; + } + }, "--no-video" | "-vn" => { transcoder.no_video = true; }, @@ -1032,7 +1055,7 @@ println!("stream {} - {} {}", i, s, info.get_name()); let frm = ret.unwrap(); reorderer.add_frame(frm); while let Some(frm) = reorderer.get_frame() { - if !encode_frame(dst_id, encoder, cvt, frm) { + if !encode_frame(dst_id, encoder, cvt, frm, &transcoder.scale_opts) { break; } while let Ok(Some(pkt)) = encoder.get_packet() { @@ -1052,7 +1075,7 @@ println!("stream {} - {} {}", i, s, info.get_name()); if let OutputMode::Encode(dst_id, ref mut encoder, ref mut cvt) = transcoder.encoders[src_id] { if let Some((_, _, ref mut reorderer)) = transcoder.decoders[src_id] { while let Some(frm) = reorderer.get_last_frames() { - if !encode_frame(dst_id, encoder, cvt, frm) { + if !encode_frame(dst_id, encoder, cvt, frm, &transcoder.scale_opts) { break; } while let Ok(Some(pkt)) = encoder.get_packet() {