extern crate nihav_allstuff;
use std::fs::File;
-use std::io::BufReader;
+use std::io::{BufReader, Write};
use nihav_core::io::byteio::{FileReader, ByteReader};
use nihav_core::frame::*;
use nihav_core::options::*;
use nihav_registry::detect;
use nihav_registry::register;
use std::env;
+use std::time::{Duration, Instant};
mod demux;
use crate::demux::*;
mod null;
+fn format_time(ms: u64) -> String {
+ let s = ms / 1000;
+ let ds = (ms % 1000) / 100;
+ let (min, s) = (s / 60, s % 60);
+ let (h, min) = (min / 60, min % 60);
+ if h == 0 {
+ if min == 0 {
+ format!("{}.{}", s, ds)
+ } else {
+ format!("{}:{:02}.{}", min, s, ds)
+ }
+ } else {
+ format!("{}:{:02}:{:02}.{}", h, min, s, ds)
+ }
+}
+
fn print_options(name: &str, options: &[NAOptionDefinition]) {
if options.is_empty() {
println!("No custom options.");
no_audio: bool,
start: NATimePoint,
end: NATimePoint,
+ verbose: bool,
}
macro_rules! parse_and_apply_options {
return;
}
},
+ "--verbose" | "-v" => transcoder.verbose = true,
_ => {
if args[arg_idx].starts_with("--istream") {
let opt0 = &args[arg_idx];
println!("cannot find demuxer for '{}'", transcoder.input_name.as_str());
return;
}
+ let duration = dmx.get_duration();
+ let duration_string = if duration != 0 { format_time(duration) } else { String::new() };
+
parse_and_apply_options!(dmx, &transcoder.demux_opts, "input");
for i in 0..dmx.get_num_streams() {
let s = dmx.get_stream(i).unwrap();
println!(" #{}: {} {}", ostr.get_num(), ostr, ostr.get_info().get_name());
}
+ let mut time = Instant::now();
+ let show_interval = Duration::from_millis(100);
'main_loop: loop {
let pktres = dmx.get_frame();
if let Err(DemuxerError::EOF) = pktres { break; }
let mut pkt = pktres.unwrap();
if transcoder.start != NATimePoint::None && pkt.ts.less_than(transcoder.start) { continue; }
let src_id = pkt.get_stream().get_num();
+ if transcoder.verbose && time.elapsed() >= show_interval {
+ if let Some(pts) = pkt.get_pts() {
+ let cur_time = format_time(NATimeInfo::ts_to_time(pts, 1000, pkt.ts.tb_num, pkt.ts.tb_den));
+ print!(" {}", cur_time);
+ } else {
+ print!(" ???");
+ }
+ if !duration_string.is_empty() {
+ print!(" / {}", duration_string);
+ }
+ print!("\r");
+ std::io::stdout().flush().unwrap();
+ time = Instant::now();
+ }
match transcoder.encoders[src_id] {
OutputMode::Drop => {},
OutputMode::Copy(dst_id) => {
_ => {},
};
}
+ if transcoder.verbose {
+ println!();
+ }
let ret = mux.end();
if ret.is_err() {