From 7cd3b41eda101ea5b3e36d73436c68a5b5d4f030 Mon Sep 17 00:00:00 2001 From: Kostya Shishkov Date: Thu, 9 Jul 2020 10:44:05 +0200 Subject: [PATCH] switch seeking and end time to use NATimePoint --- src/main.rs | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/src/main.rs b/src/main.rs index 1be4e2a..79212fd 100644 --- a/src/main.rs +++ b/src/main.rs @@ -77,14 +77,14 @@ fn main() { println!("usage: nihav-tool [-noout] [-vn] [-an] input [lastpts]"); return; } - let mut lastpts: Option = None; + let mut lastpts = NATimePoint::None; let mut cur_arg: usize = 1; let mut noout = false; let mut decode_video = true; let mut decode_audio = true; let mut nmode = NumberMode::FrmPTS; let mut smode = FrameSkipMode::None; - let mut seek_time = 0u64; + let mut seek_time = NATimePoint::None; let mut vpfx: Option = None; let mut apfx: Option<&str> = None; let mut ignore_errors = false; @@ -107,7 +107,7 @@ fn main() { println!("seek time missing"); return; } - let ret = args[cur_arg].parse::(); + let ret = args[cur_arg].parse::(); if ret.is_err() { println!("wrong seek time"); return; @@ -139,7 +139,12 @@ fn main() { let name = args[cur_arg].as_str(); cur_arg += 1; if cur_arg < args.len() { - lastpts = Some(u64::from_str_radix(args[cur_arg].as_str(), 10).unwrap()); + let ret = args[cur_arg].parse::(); + if ret.is_err() { + println!("cannot parse end time"); + return; + } + lastpts = ret.unwrap(); } let path = Path::new(name); @@ -164,7 +169,7 @@ println!("trying demuxer {} on {}", dmx_name, name); br.seek(SeekFrom::Start(0)).unwrap(); let mut dmx = create_demuxer(dmx_fact, &mut br).unwrap(); - if seek_time > 0 { + if seek_time != NATimePoint::None { let ret = dmx.seek(seek_time); if ret.is_err() { println!(" seek error {:?}", ret.err().unwrap()); @@ -259,7 +264,7 @@ panic!("decoder {} not found", info.get_name()); }; } }, - Err(DecoderError::MissingReference) if seek_time > 0 => { + Err(DecoderError::MissingReference) if seek_time != NATimePoint::None => { println!("ignoring missing ref"); }, Err(reason) => { @@ -269,7 +274,7 @@ panic!("decoder {} not found", info.get_name()); } }, }; - if pkt.get_pts() != None && lastpts.is_some() && pkt.get_pts() >= lastpts { break; } + if pkt.get_pts() != None && lastpts != NATimePoint::None && !pkt.ts.less_than(lastpts) { break; } } } //panic!("end"); -- 2.39.5