MCPcopy Create free account
hub / github.com/Proryanator/encoder-benchmark / watch_encode_progress

Function watch_encode_progress

engine/src/progressbar.rs:30–160  ·  view source on GitHub ↗
(
    total_frames: u64,
    detect_overload: bool,
    target_fps: u32,
    verbose: bool,
    stats_period: c_float,
    ctrl_channel: &Result<Receiver<()>, Error>,
)

Source from the content-addressed store, hash-verified

28}
29
30pub fn watch_encode_progress(
31 total_frames: u64,
32 detect_overload: bool,
33 target_fps: u32,
34 verbose: bool,
35 stats_period: c_float,
36 ctrl_channel: &Result<Receiver<()>, Error>,
37) -> TrialResult {
38 // set this flag every second to see real-time fps statistics and other information
39 let mut can_log_verbose = true;
40 let verbose_log_interval = time::Duration::from_secs(1);
41 let mut log_verbose_timer = SystemTime::now();
42
43 static FRAME: AtomicUsize = AtomicUsize::new(0);
44 static PREVIOUS_FRAME: AtomicUsize = AtomicUsize::new(0);
45
46 // keep track of all fps metrics to calculate on later on
47 let mut trial_result = TrialResult::default();
48 let bar = ProgressBar::new(total_frames);
49 set_bar_style(&bar, "green");
50 bar.tick();
51
52 // time it takes for the encoder to need to process the target # of frames
53 let overload_time = time::Duration::from_secs(5);
54 let allowed_ffmpeg_downtime = time::Duration::from_secs(10);
55
56 let mut checking_overload = false;
57 let mut first_overload_detected = SystemTime::now();
58
59 let mut ffmpeg_error_check_time = SystemTime::now();
60 let mut checking_ffmpeg_error = false;
61
62 // how many milliseconds has passed since the last frame stat
63 let interval_adjustment = (1.0 / stats_period) as usize;
64
65 let stat_listener = start_listening_to_ffmpeg_stats(verbose, &FRAME, &PREVIOUS_FRAME);
66
67 let mut last_frame = 0;
68
69 loop {
70 if log_verbose_timer.elapsed().unwrap() > verbose_log_interval {
71 log_verbose_timer = SystemTime::now();
72 can_log_verbose = true;
73 }
74
75 // important to not get stuck in this thread
76 exit_on_ctrl_c(&ctrl_channel);
77
78 // takes into account the stat update period to properly adjust the calculated FPS
79 let calculated_fps = ((FRAME.load(Ordering::Relaxed)
80 - PREVIOUS_FRAME.load(Ordering::Relaxed))
81 * interval_adjustment) as u16;
82
83 if verbose && can_log_verbose {
84 println!("V: Calculated fps: {}", calculated_fps);
85 }
86
87 // only record fps counts that are close to 1/4 of the target; any lower is noise

Callers 2

run_overload_benchmarkFunction · 0.85
calc_vmaf_scoreFunction · 0.85

Calls 3

set_bar_styleFunction · 0.85
exit_on_ctrl_cFunction · 0.85

Tested by

no test coverage detected