None,
}
+#[allow(clippy::large_enum_variant)]
enum OutputMode {
Drop,
Copy(u32),
}
#[derive(Default)]
+#[allow(clippy::type_complexity)]
struct Transcoder {
input_name: String,
input_fmt: Option<String>,
mux_opts: Vec<OptionArgs>,
istr_opts: Vec<InputStreamOptions>,
ostr_opts: Vec<OutputStreamOptions>,
+ scale_opts: Vec<(String, String)>,
decoders: Vec<Option<(Box<NADecoderSupport>, Box<dyn NADecoder>, Box<dyn FrameReorderer>)>>,
encoders: Vec<OutputMode>,
no_video: bool,
for opt in $in_opts.iter() {
let mut found = false;
for opt_def in opt_def.iter() {
- if opt.name == opt_def.name {
+ let mut matches = opt.name == opt_def.name;
+ if !matches && opt.name.starts_with("no") {
+ let (_, name) = opt.name.split_at(2);
+ matches = name == opt_def.name;
+ }
+ if matches {
let arg = if let Some(ref str) = opt.value { Some(str) } else { None };
let ret = opt_def.parse(&opt.name, arg);
- if ret.is_err() {
- println!("invalid option {} for {}", opt.name, $name);
- } else {
- let (val, _) = ret.unwrap();
+ if let Ok((val, _)) = ret {
opts.push(val);
+ } else {
+ println!("invalid option {} for {}", opt.name, $name);
}
found = true;
}
}
true
}
- fn apply_decoder_options(&self, dec: &mut NADecoder, str_id: u32) {
+ 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();
if dec_opts.is_empty() { return; }
if let Some(str_idx) = self.ostr_opts.iter().position(|str| str.id == out_id) {
let oopts = &mut self.ostr_opts[str_idx];
if oopts.enc_name.as_str() == "copy" && (cname == "any" || istr.get_info().get_name() == cname) {
- out_sm.add_stream_ref(istr.clone());
+ out_sm.add_stream_ref(istr);
self.encoders.push(OutputMode::Copy(out_id));
} else if cname == "any" || oopts.enc_name.as_str() == cname {
let enc_create = enc_reg.find_encoder(oopts.enc_name.as_str());
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;
println!("encoder {} is not supported by output (expected {})", istr.id, istr.get_info().get_name());
return false;
}
+ } else if cname == "any" || istr.get_info().get_name() == cname {
+ out_sm.add_stream_ref(istr);
+ self.encoders.push(OutputMode::Copy(out_id));
} else {
- if cname == "any" || istr.get_info().get_name() == cname {
- out_sm.add_stream_ref(istr.clone());
- self.encoders.push(OutputMode::Copy(out_id));
- } else {
println!("stream {} ({}) can't be handled", istr.id, istr.get_info().get_name());
// todo autoselect encoder?
- return false;
- }
+ return false;
}
true
}
}
}
-fn encode_frame(dst_id: u32, encoder: &mut Box<NAEncoder>, cvt: &mut OutputConvert, frm: NAFrameRef) -> bool {
+fn encode_frame(dst_id: u32, encoder: &mut Box<dyn NAEncoder>, cvt: &mut OutputConvert, frm: NAFrameRef, scale_opts: &[(String, String)]) -> bool {
let buf = frm.get_buffer();
let cbuf = match cvt {
OutputConvert::None => buf,
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;
}
}
+#[allow(clippy::single_match)]
fn main() {
let args: Vec<_> = env::args().collect();
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");
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;
},
return;
}
- if transcoder.input_name.len() == 0 {
+ if transcoder.input_name.is_empty() {
println!("no input name provided");
return;
}
- if transcoder.output_name.len() == 0 {
+ if transcoder.output_name.is_empty() {
println!("no output name provided");
return;
}
let dmx_name = if let Some(ref str) = transcoder.input_fmt {
str.as_str()
+ } else if let Some((dmx_name, score)) = detect::detect_format(transcoder.input_name.as_str(), &mut br) {
+ println!("detected {} with score {:?}", dmx_name, score);
+ dmx_name
} else {
- if let Some((dmx_name, score)) = detect::detect_format(transcoder.input_name.as_str(), &mut br) {
- println!("detected {} with score {:?}", dmx_name, score);
- dmx_name
- } else {
- println!("cannot detect input format");
- return;
- }
+ println!("cannot detect input format");
+ return;
};
let ret = dmx_reg.find_demuxer(dmx_name);
if ret.is_none() {
let output_fmt = if let Some(ref str) = transcoder.output_fmt {
str
+ } else if let Some(str) = detect::detect_format_by_name(transcoder.output_name.as_str()) {
+ str
} else {
- if let Some(str) = detect::detect_format_by_name(transcoder.output_name.as_str()) {
- str
- } else {
- println!("Cannot guess muxer for output");
- return;
- }
+ println!("Cannot guess muxer for output");
+ return;
};
let ret = mux_reg.find_muxer(output_fmt);
let ofmt = output_fmt.to_string();
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() {
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() {