feat(video2x): added time remaining and processing speed to the progress bar

Signed-off-by: k4yt3x <i@k4yt3x.com>
This commit is contained in:
k4yt3x 2024-11-06 00:00:00 +00:00
parent 33b7c53e16
commit 05b275dd82
No known key found for this signature in database
2 changed files with 53 additions and 10 deletions

View File

@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased] ## [Unreleased]
### Added
- Time remaining, and processing speed to the status bar.
### Fixed ### Fixed
- Stream mapping for cases where the video stream is not the first stream in the input file (#1217). - Stream mapping for cases where the video stream is not the first stream in the input file (#1217).
@ -23,7 +27,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Fixed ### Fixed
- Wide character string paths support on Windows systems without UTF-8 suppoprt enabled (#1201). - Wide character string paths support on Windows systems without UTF-8 support enabled (#1201).
### Changed ### Changed

View File

@ -318,7 +318,15 @@ void process_video_thread(
#ifdef _WIN32 #ifdef _WIN32
int wmain(int argc, wchar_t *argv[]) { int wmain(int argc, wchar_t *argv[]) {
// Set console output code page to UTF-8
SetConsoleOutputCP(CP_UTF8); SetConsoleOutputCP(CP_UTF8);
// Enable ANSI escape codes
HANDLE console_handle = GetStdHandle(STD_OUTPUT_HANDLE);
DWORD console_mode = 0;
GetConsoleMode(console_handle, &console_mode);
console_mode |= ENABLE_VIRTUAL_TERMINAL_PROCESSING;
SetConsoleMode(console_handle, console_mode);
#else #else
int main(int argc, char **argv) { int main(int argc, char **argv) {
#endif #endif
@ -593,7 +601,7 @@ int main(int argc, char **argv) {
&encoder_config, &encoder_config,
&proc_ctx &proc_ctx
); );
spdlog::info("Press SPACE to pause/resume, 'q' to abort."); spdlog::info("Press [space] to pause/resume, [q] to abort.");
// Setup timer // Setup timer
Timer timer; Timer timer;
@ -633,18 +641,23 @@ int main(int argc, char **argv) {
std::lock_guard<std::mutex> lock(proc_ctx_mutex); std::lock_guard<std::mutex> lock(proc_ctx_mutex);
proc_ctx.pause = !proc_ctx.pause; proc_ctx.pause = !proc_ctx.pause;
if (proc_ctx.pause) { if (proc_ctx.pause) {
putchar('\n'); std::cout
spdlog::info("Processing paused. Press SPACE to resume, 'q' to abort."); << "\r\033[KProcessing paused; press [space] to resume, [q] to abort.";
std::cout.flush();
timer.pause(); timer.pause();
} else { } else {
spdlog::info("Resuming processing..."); std::cout << "\r\033[KProcessing resumed.";
std::cout.flush();
timer.resume(); timer.resume();
} }
newline_required = true;
} }
} else if (ch == 'q' || ch == 'Q') { } else if (ch == 'q' || ch == 'Q') {
// Abort processing // Abort processing
putchar('\n'); if (newline_required) {
spdlog::info("Aborting processing..."); putchar('\n');
}
spdlog::warn("Aborting gracefully; press Ctrl+C to terminate forcefully.");
{ {
std::lock_guard<std::mutex> lock(proc_ctx_mutex); std::lock_guard<std::mutex> lock(proc_ctx_mutex);
proc_ctx.abort = true; proc_ctx.abort = true;
@ -667,9 +680,35 @@ int main(int argc, char **argv) {
double percentage = total_frames > 0 ? static_cast<double>(processed_frames) * double percentage = total_frames > 0 ? static_cast<double>(processed_frames) *
100.0 / static_cast<double>(total_frames) 100.0 / static_cast<double>(total_frames)
: 0.0; : 0.0;
int64_t time_elapsed = timer.get_elapsed_time() / 1000; int time_elapsed = static_cast<int>(timer.get_elapsed_time() / 1000);
std::cout << "\rProcessing frame " << processed_frames << "/" << total_frames
<< " (" << percentage << "%); time elapsed: " << time_elapsed << "s"; // Calculate hours, minutes, and seconds elapsed
int hours_elapsed = time_elapsed / 3600;
int minutes_elapsed = (time_elapsed % 3600) / 60;
int seconds_elapsed = time_elapsed % 60;
// Calculate estimated time remaining
int64_t frames_remaining = total_frames - processed_frames;
double processing_rate = static_cast<double>(processed_frames) / time_elapsed;
int time_remaining =
static_cast<int>(static_cast<double>(frames_remaining) / processing_rate);
time_remaining = std::max<int>(time_remaining, 0);
// Calculate hours, minutes, and seconds remaining
int hours_remaining = time_remaining / 3600;
int minutes_remaining = (time_remaining % 3600) / 60;
int seconds_remaining = time_remaining % 60;
// Print the progress bar
std::cout << "\r\033[Kframe=" << processed_frames << "/" << total_frames << " ("
<< std::fixed << std::setprecision(2) << percentage
<< "%); fps=" << std::fixed << std::setprecision(2) << processing_rate
<< "; elapsed=" << std::setw(2) << std::setfill('0') << hours_elapsed
<< ":" << std::setw(2) << std::setfill('0') << minutes_elapsed << ":"
<< std::setw(2) << std::setfill('0') << seconds_elapsed
<< "; remaining=" << std::setw(2) << std::setfill('0') << hours_remaining
<< ":" << std::setw(2) << std::setfill('0') << minutes_remaining << ":"
<< std::setw(2) << std::setfill('0') << seconds_remaining;
std::cout.flush(); std::cout.flush();
newline_required = true; newline_required = true;
} }