mirror of https://github.com/mpv-player/mpv
loadfile: improve the format of terminal track information
Print vlang if present. Make unselected tracks and editions grey instead of adding (+) before selected tracks. Mark them with the same circles as show-text ${track-list} and script-message osc-tracklist when not outputting to a TTY. Don't print a different symbol with --sub-forced-events-only because nobody uses this option, and subtitles are very unlikely to mix forced and non-forced events. Align 2-digit track IDs. Align languages of up to 7 characters (the length of zh-Hans). Leave spaces when a track has no language but at least another track does to align the following track data with the other tracks. Add a space between values and their units. Convert Hz to kHz. Pretty print FPS and kHz with mp_format_double(). Don't print images' FPS because it's just a bogus value taken from --mf-fps. Co-authored-by: Kacper Michajłow <kasper93@gmail.com>
This commit is contained in:
parent
22aa570cf8
commit
d49879f1f7
|
@ -38,6 +38,8 @@
|
||||||
#define TERM_ESC_ENABLE_MOUSE "\033[?1003h"
|
#define TERM_ESC_ENABLE_MOUSE "\033[?1003h"
|
||||||
#define TERM_ESC_DISABLE_MOUSE "\033[?1003l"
|
#define TERM_ESC_DISABLE_MOUSE "\033[?1003l"
|
||||||
|
|
||||||
|
#define TERM_ESC_GREY "\033[38;5;8m"
|
||||||
|
|
||||||
struct input_ctx;
|
struct input_ctx;
|
||||||
|
|
||||||
/* Global initialization for terminal output. */
|
/* Global initialization for terminal output. */
|
||||||
|
|
|
@ -235,7 +235,10 @@ static void uninit_demuxer(struct MPContext *mpctx)
|
||||||
talloc_free(demuxers);
|
talloc_free(demuxers);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#define BLACK_CIRCLE "\xe2\x97\x8f"
|
||||||
|
#define WHITE_CIRCLE "\xe2\x97\x8b"
|
||||||
#define APPEND(s, ...) mp_snprintf_cat(s, sizeof(s), __VA_ARGS__)
|
#define APPEND(s, ...) mp_snprintf_cat(s, sizeof(s), __VA_ARGS__)
|
||||||
|
#define FILL(s, n) mp_snprintf_cat(s, sizeof(s), "%*s", n, "")
|
||||||
|
|
||||||
static void print_stream(struct MPContext *mpctx, struct track *t)
|
static void print_stream(struct MPContext *mpctx, struct track *t)
|
||||||
{
|
{
|
||||||
|
@ -245,7 +248,7 @@ static void print_stream(struct MPContext *mpctx, struct track *t)
|
||||||
const char *langopt = "?";
|
const char *langopt = "?";
|
||||||
switch (t->type) {
|
switch (t->type) {
|
||||||
case STREAM_VIDEO:
|
case STREAM_VIDEO:
|
||||||
tname = "Video"; selopt = "vid"; langopt = NULL;
|
tname = "Video"; selopt = "vid"; langopt = "vlang";
|
||||||
break;
|
break;
|
||||||
case STREAM_AUDIO:
|
case STREAM_AUDIO:
|
||||||
tname = "Audio"; selopt = "aid"; langopt = "alang";
|
tname = "Audio"; selopt = "aid"; langopt = "alang";
|
||||||
|
@ -255,24 +258,32 @@ static void print_stream(struct MPContext *mpctx, struct track *t)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
char b[2048] = {0};
|
char b[2048] = {0};
|
||||||
bool forced_only = false;
|
|
||||||
if (t->type == STREAM_SUB) {
|
bool tracks_have_lang = false;
|
||||||
bool forced_opt = mpctx->opts->subs_rend->sub_forced_events_only;
|
for (int n = 0; n < mpctx->num_tracks; n++) {
|
||||||
if (forced_opt)
|
if (mpctx->tracks[n]->lang) {
|
||||||
forced_only = t->selected;
|
tracks_have_lang = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!isatty(STDOUT_FILENO)) {
|
||||||
|
APPEND(b, "%s ", t->selected ? BLACK_CIRCLE : WHITE_CIRCLE);
|
||||||
|
} else if (!t->selected) {
|
||||||
|
APPEND(b, "%s", TERM_ESC_GREY);
|
||||||
|
}
|
||||||
|
APPEND(b, "%-5s --%s=%-2d", tname, selopt, t->user_tid);
|
||||||
|
if (t->lang) {
|
||||||
|
APPEND(b, " --%s=%-7s", langopt, t->lang);
|
||||||
|
} else if (tracks_have_lang) {
|
||||||
|
FILL(b, 16);
|
||||||
}
|
}
|
||||||
APPEND(b, " %3s %-5s", t->selected ? (forced_only ? "(*)" : "(+)") : "", tname);
|
|
||||||
APPEND(b, " --%s=%d", selopt, t->user_tid);
|
|
||||||
if (t->lang && langopt)
|
|
||||||
APPEND(b, " --%s=%s", langopt, t->lang);
|
|
||||||
if (t->default_track)
|
if (t->default_track)
|
||||||
APPEND(b, " (*)");
|
APPEND(b, " (*)");
|
||||||
if (t->forced_track)
|
if (t->forced_track)
|
||||||
APPEND(b, " (f)");
|
APPEND(b, " (f)");
|
||||||
if (t->attached_picture)
|
if (t->attached_picture)
|
||||||
APPEND(b, " [P]");
|
APPEND(b, " [P]");
|
||||||
if (forced_only)
|
|
||||||
APPEND(b, " [F]");
|
|
||||||
if (t->title)
|
if (t->title)
|
||||||
APPEND(b, " '%s'", t->title);
|
APPEND(b, " '%s'", t->title);
|
||||||
const char *codec = s ? s->codec->codec : NULL;
|
const char *codec = s ? s->codec->codec : NULL;
|
||||||
|
@ -282,13 +293,20 @@ static void print_stream(struct MPContext *mpctx, struct track *t)
|
||||||
if (t->type == STREAM_VIDEO) {
|
if (t->type == STREAM_VIDEO) {
|
||||||
if (s && s->codec->disp_w)
|
if (s && s->codec->disp_w)
|
||||||
APPEND(b, " %dx%d", s->codec->disp_w, s->codec->disp_h);
|
APPEND(b, " %dx%d", s->codec->disp_w, s->codec->disp_h);
|
||||||
if (s && s->codec->fps)
|
if (s && s->codec->fps && !t->image) {
|
||||||
APPEND(b, " %.3ffps", s->codec->fps);
|
char *fps = mp_format_double(NULL, s->codec->fps, 4, false, false, true);
|
||||||
|
APPEND(b, " %s fps", fps);
|
||||||
|
talloc_free(fps);
|
||||||
|
}
|
||||||
} else if (t->type == STREAM_AUDIO) {
|
} else if (t->type == STREAM_AUDIO) {
|
||||||
if (s && s->codec->channels.num)
|
if (s && s->codec->channels.num)
|
||||||
APPEND(b, " %dch", s->codec->channels.num);
|
APPEND(b, " %d ch", s->codec->channels.num);
|
||||||
if (s && s->codec->samplerate)
|
if (s && s->codec->samplerate) {
|
||||||
APPEND(b, " %dHz", s->codec->samplerate);
|
char *samplerate = mp_format_double(NULL, s->codec->samplerate / 1000.0,
|
||||||
|
4, false, false, true);
|
||||||
|
APPEND(b, " %s kHz", samplerate);
|
||||||
|
talloc_free(samplerate);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
APPEND(b, ")");
|
APPEND(b, ")");
|
||||||
if (s && s->hls_bitrate > 0)
|
if (s && s->hls_bitrate > 0)
|
||||||
|
@ -320,8 +338,12 @@ void update_demuxer_properties(struct MPContext *mpctx)
|
||||||
for (int n = 0; n < demuxer->num_editions; n++) {
|
for (int n = 0; n < demuxer->num_editions; n++) {
|
||||||
struct demux_edition *edition = &demuxer->editions[n];
|
struct demux_edition *edition = &demuxer->editions[n];
|
||||||
char b[128] = {0};
|
char b[128] = {0};
|
||||||
APPEND(b, " %3s --edition=%d",
|
if (!isatty(STDOUT_FILENO)) {
|
||||||
n == demuxer->edition ? "(+)" : "", n);
|
APPEND(b, "%s ", n == demuxer->edition ? BLACK_CIRCLE : WHITE_CIRCLE);
|
||||||
|
} else if (n != demuxer->edition) {
|
||||||
|
APPEND(b, "%s", TERM_ESC_GREY);
|
||||||
|
}
|
||||||
|
APPEND(b, "--edition=%d", n);
|
||||||
char *name = mp_tags_get_str(edition->metadata, "title");
|
char *name = mp_tags_get_str(edition->metadata, "title");
|
||||||
if (name)
|
if (name)
|
||||||
APPEND(b, " '%s'", name);
|
APPEND(b, " '%s'", name);
|
||||||
|
|
Loading…
Reference in New Issue