-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1b483fc
commit 324d43c
Showing
7 changed files
with
110 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
use indicatif::HumanDuration; | ||
use log::{info, log_enabled, Level}; | ||
use std::time::{Duration, Instant}; | ||
|
||
/// Struct that info logs progress messages on a stream action like encoding. | ||
#[derive(Debug)] | ||
pub struct ProgressLogger { | ||
target: &'static str, | ||
start: Instant, | ||
log_count: u32, | ||
} | ||
|
||
impl ProgressLogger { | ||
pub fn new(target: &'static str, start: Instant) -> Self { | ||
Self { | ||
target, | ||
start, | ||
log_count: 0, | ||
} | ||
} | ||
|
||
/// Update and potentially log progress on a stream action. | ||
/// * `total` total duration of the stream | ||
/// * `complete` the duration that has been completed at this time | ||
/// * `fps` frames per second | ||
pub fn update(&mut self, total: Duration, completed: Duration, fps: f32) { | ||
if log_enabled!(Level::Info) && completed > Duration::ZERO { | ||
let done = completed.as_secs_f64() / total.as_secs_f64(); | ||
|
||
let elapsed = self.start.elapsed(); | ||
|
||
let before_count = self.log_count; | ||
while elapsed > self.next_log() { | ||
self.log_count += 1; | ||
} | ||
if before_count == self.log_count { | ||
return; | ||
} | ||
|
||
let eta = Duration::from_secs_f64(elapsed.as_secs_f64() / done) - elapsed; | ||
info!( | ||
target: self.target, | ||
"{:.0}%, {fps} fps, eta {}", | ||
done * 100.0, | ||
HumanDuration(eta) | ||
); | ||
} | ||
} | ||
|
||
/// First log after >=16s, then >=32s etc | ||
fn next_log(&self) -> Duration { | ||
Duration::from_secs(2_u64.pow(self.log_count + 4)) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ mod console_ext; | |
mod ffmpeg; | ||
mod ffprobe; | ||
mod float; | ||
mod log; | ||
mod process; | ||
mod sample; | ||
mod temporary; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters