aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKostya Shishkov <kostya.shishkov@gmail.com>2021-11-17 18:40:51 +0100
committerKostya Shishkov <kostya.shishkov@gmail.com>2021-11-17 18:40:51 +0100
commit5ec8115fa8878cba1649346e52e65f5414f64b75 (patch)
treedf2433d9edb254bcfb52a59c478bc15ba70a4ee5
parent00b4c46f1c906a978dfac94bc569a6d3f4a429f5 (diff)
downloadnihav-encoder-5ec8115fa8878cba1649346e52e65f5414f64b75.tar.gz
add verbose option
-rw-r--r--src/demux.rs4
-rw-r--r--src/main.rs43
2 files changed, 44 insertions, 3 deletions
diff --git a/src/demux.rs b/src/demux.rs
index dbc1447..73ed14f 100644
--- a/src/demux.rs
+++ b/src/demux.rs
@@ -146,13 +146,13 @@ impl<'a> DemuxerObject<'a> {
_ => false,
}
}
- /*pub fn get_duration(&self) -> u64 {
+ pub fn get_duration(&self) -> u64 {
match *self {
DemuxerObject::Normal(ref dmx) => dmx.get_duration(),
DemuxerObject::Raw(ref dmx, _, _) => dmx.get_duration(),
_ => 0,
}
- }*/
+ }
pub fn get_num_streams(&self) -> usize {
match *self {
DemuxerObject::None => 0,
diff --git a/src/main.rs b/src/main.rs
index d0b8d4b..fdab843 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -4,7 +4,7 @@ extern crate nihav_registry;
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::*;
@@ -17,11 +17,28 @@ use nihav_core::soundcvt::*;
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.");
@@ -82,6 +99,7 @@ struct Transcoder {
no_audio: bool,
start: NATimePoint,
end: NATimePoint,
+ verbose: bool,
}
macro_rules! parse_and_apply_options {
@@ -931,6 +949,7 @@ fn main() {
return;
}
},
+ "--verbose" | "-v" => transcoder.verbose = true,
_ => {
if args[arg_idx].starts_with("--istream") {
let opt0 = &args[arg_idx];
@@ -998,6 +1017,9 @@ fn main() {
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();
@@ -1078,6 +1100,8 @@ println!("stream {} - {} {}", i, s, info.get_name());
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; }
@@ -1088,6 +1112,20 @@ println!("stream {} - {} {}", i, s, info.get_name());
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) => {
@@ -1162,6 +1200,9 @@ println!("stream {} - {} {}", i, s, info.get_name());
_ => {},
};
}
+ if transcoder.verbose {
+ println!();
+ }
let ret = mux.end();
if ret.is_err() {