From 414c47d1d8c4b34e4dd0bfdbc5551d976dad7122 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kacper=20Michaj=C5=82ow?= Date: Sun, 5 May 2024 16:42:28 +0200 Subject: [PATCH] player/main: select msg output stream early This avoids printing any stray messages in encode output stream. --o is already pre-parse cli option which is designed to be parsed before anything else is printed to output. So we can use that to force stderr output if needed for encode mode. --- common/encode_lavc.c | 19 +++++++++++++------ common/encode_lavc.h | 2 ++ player/main.c | 4 ++++ 3 files changed, 19 insertions(+), 6 deletions(-) diff --git a/common/encode_lavc.c b/common/encode_lavc.c index a250f9c994..33743007dd 100644 --- a/common/encode_lavc.c +++ b/common/encode_lavc.c @@ -117,12 +117,6 @@ struct encode_lavc_context *encode_lavc_init(struct mpv_global *global) if (!strcmp(filename, "-")) filename = "pipe:1"; - if (filename && ( - !strcmp(filename, "/dev/stdout") || - !strcmp(filename, "pipe:") || - !strcmp(filename, "pipe:1"))) - mp_msg_force_stderr(global, true); - encode_lavc_discontinuity(ctx); p->muxer = avformat_alloc_context(); @@ -946,4 +940,17 @@ fail: return false; } +void encoder_update_log(struct mpv_global *global) +{ + struct encode_opts *options = mp_get_config_group(NULL, global, &encode_config); + if (options->file && (!strcmp(options->file, "-") || + !strcmp(options->file, "/dev/stdout") || + !strcmp(options->file, "pipe:") || + !strcmp(options->file, "pipe:1"))) + { + mp_msg_force_stderr(global, true); + } + talloc_free(options); +} + // vim: ts=4 sw=4 et diff --git a/common/encode_lavc.h b/common/encode_lavc.h index 8517726529..125108e538 100644 --- a/common/encode_lavc.h +++ b/common/encode_lavc.h @@ -111,4 +111,6 @@ bool encoder_encode(struct encoder_context *p, AVFrame *frame); // Caller needs to acquire encode_lavc_context.lock (or call it from on_ready). AVRational encoder_get_mux_timebase_unlocked(struct encoder_context *p); +void encoder_update_log(struct mpv_global *global); + #endif diff --git a/player/main.c b/player/main.c index 48d29b520e..22ed4e55da 100644 --- a/player/main.c +++ b/player/main.c @@ -44,6 +44,7 @@ #include "options/m_option.h" #include "options/m_property.h" #include "common/common.h" +#include "common/encode_lavc.h" #include "common/msg.h" #include "common/msg_control.h" #include "common/stats.h" @@ -139,6 +140,9 @@ void mp_update_logging(struct MPContext *mpctx, bool preinit) if (enabled && !preinit && mpctx->opts->consolecontrols) terminal_setup_getch(mpctx->input); + + if (enabled) + encoder_update_log(mpctx->global); } void mp_print_version(struct mp_log *log, int always)