mirror of
https://github.com/k4yt3x/video2x.git
synced 2024-12-27 14:39:09 +00:00
feat(logger): improve FFmpeg logging format
Signed-off-by: k4yt3x <i@k4yt3x.com>
This commit is contained in:
parent
6676cd2439
commit
f3999a431c
@ -26,19 +26,20 @@ static spdlog::level::level_enum ffmpeg_level_to_spdlog(int av_level) {
|
||||
}
|
||||
}
|
||||
|
||||
static void ffmpeg_log_callback(void *, int av_level, const char *fmt, va_list vargs) {
|
||||
// Format the message into a buffer
|
||||
char buffer[1024];
|
||||
vsnprintf(buffer, sizeof(buffer), fmt, vargs);
|
||||
static void ffmpeg_log_callback(void *avcl, int level, const char *fmt, va_list vargs) {
|
||||
// Format the message the same way as the default callback
|
||||
char line[1024];
|
||||
int print_prefix = 1;
|
||||
av_log_format_line(avcl, level, fmt, vargs, line, sizeof(line), &print_prefix);
|
||||
|
||||
// Trim trailing newlines
|
||||
std::string message = buffer;
|
||||
std::string message = line;
|
||||
while (!message.empty() && (message.back() == '\n' || message.back() == '\r')) {
|
||||
message.pop_back();
|
||||
}
|
||||
|
||||
// Forward FFmpeg log message to the logger instance
|
||||
video2x::logger()->log(ffmpeg_level_to_spdlog(av_level), message);
|
||||
// Forward the formatted FFmpeg log message to the logger
|
||||
video2x::logger()->log(ffmpeg_level_to_spdlog(level), "[FFmpeg] {}", message);
|
||||
}
|
||||
|
||||
namespace video2x {
|
||||
|
@ -53,7 +53,14 @@ int wmain(int argc, wchar_t *argv[]) {
|
||||
#else
|
||||
int main(int argc, char **argv) {
|
||||
#endif
|
||||
// Initialize arguments structures
|
||||
// Initialize newline-safe logger with custom formatting pattern
|
||||
std::shared_ptr<newline_safe_sink> logger_sink = std::make_shared<newline_safe_sink>();
|
||||
std::vector<spdlog::sink_ptr> sinks = {logger_sink};
|
||||
video2x::logger_manager::LoggerManager::instance().reconfigure_logger(
|
||||
"video2x", sinks, "[%Y-%m-%d %H:%M:%S] [%^%l%$] %v"
|
||||
);
|
||||
|
||||
// Initialize argument and configuration structs
|
||||
Arguments arguments;
|
||||
video2x::processors::ProcessorConfig proc_cfg;
|
||||
video2x::encoder::EncoderConfig enc_cfg;
|
||||
@ -76,11 +83,6 @@ int main(int argc, char **argv) {
|
||||
proc_cfg, enc_cfg, arguments.vk_device_index, arguments.hw_device_type, arguments.benchmark
|
||||
);
|
||||
|
||||
// Register a newline-safe log sink
|
||||
std::shared_ptr<newline_safe_sink> logger_sink = std::make_shared<newline_safe_sink>();
|
||||
std::vector<spdlog::sink_ptr> sinks = {logger_sink};
|
||||
video2x::logger_manager::LoggerManager::instance().reconfigure_logger("video2x", sinks);
|
||||
|
||||
// Create a thread for video processing
|
||||
int proc_ret = 0;
|
||||
std::atomic<bool> completed = false; // Use atomic for thread-safe updates
|
||||
@ -207,6 +209,7 @@ int main(int argc, char **argv) {
|
||||
|
||||
// Print a newline if progress bar was displayed
|
||||
if (logger_sink->get_needs_newline()) {
|
||||
logger_sink->set_needs_newline(false);
|
||||
std::cout << '\n';
|
||||
}
|
||||
|
||||
@ -222,6 +225,8 @@ int main(int argc, char **argv) {
|
||||
video2x::logger()->info("Video processed successfully");
|
||||
}
|
||||
|
||||
// Print the processing summary if the log level is info or lower
|
||||
if (video2x::logger()->level() <= spdlog::level::info) {
|
||||
// Calculate statistics
|
||||
int64_t processed_frames = video_processor.get_processed_frames();
|
||||
int time_elapsed = static_cast<int>(timer.get_elapsed_time() / 1000);
|
||||
@ -235,9 +240,9 @@ int main(int argc, char **argv) {
|
||||
<< " summary ======" << std::endl;
|
||||
std::cout << "Video file processed: " << arguments.in_fname.u8string() << std::endl;
|
||||
std::cout << "Total frames processed: " << processed_frames << std::endl;
|
||||
std::cout << "Total time taken: " << std::setw(2) << std::setfill('0') << hours_elapsed << ":"
|
||||
<< std::setw(2) << std::setfill('0') << minutes_elapsed << ":" << std::setw(2)
|
||||
<< std::setfill('0') << seconds_elapsed << std::endl;
|
||||
std::cout << "Total time taken: " << std::setw(2) << std::setfill('0') << hours_elapsed
|
||||
<< ":" << std::setw(2) << std::setfill('0') << minutes_elapsed << ":"
|
||||
<< std::setw(2) << std::setfill('0') << seconds_elapsed << std::endl;
|
||||
std::cout << "Average processing speed: " << std::fixed << std::setprecision(2)
|
||||
<< average_speed_fps << " FPS" << std::endl;
|
||||
|
||||
@ -245,6 +250,7 @@ int main(int argc, char **argv) {
|
||||
if (!arguments.benchmark) {
|
||||
std::cout << "Output written to: " << arguments.out_fname.u8string() << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user