loadfile,select.lua: print only one bitrate

Print demux-bitrate if available, else hls-bitrate, not both (as
demux-bitrate is generally more reliable). This avoids printing "HLS
kbps" which looks weird.

Fixes
https://github.com/mpv-player/mpv/pull/14453#discussion_r1700550385
This commit is contained in:
Guido Cella 2024-08-01 19:36:32 +02:00 committed by sfan5
parent 11ed012c34
commit 5f768a688b
2 changed files with 8 additions and 7 deletions

View File

@ -299,10 +299,11 @@ static void print_stream(struct MPContext *mpctx, struct track *t, bool indent)
if (s && s->codec->samplerate) if (s && s->codec->samplerate)
APPEND(b, " %d Hz", s->codec->samplerate); APPEND(b, " %d Hz", s->codec->samplerate);
} }
if (s && s->codec->bitrate) if (s && s->codec->bitrate) {
APPEND(b, " %d kbps", (s->codec->bitrate + 500) / 1000); APPEND(b, " %d kbps", (s->codec->bitrate + 500) / 1000);
if (s && s->hls_bitrate) } else if (s && s->hls_bitrate) {
APPEND(b, " %d HLS kbps", (s->hls_bitrate + 500) / 1000); APPEND(b, " %d kbps", (s->hls_bitrate + 500) / 1000);
}
APPEND(b, ")"); APPEND(b, ")");
bool first = true; bool first = true;

View File

@ -82,6 +82,8 @@ local function format_flags(track)
end end
local function format_track(track) local function format_track(track)
local bitrate = track["demux-bitrate"] or track["hls-bitrate"]
return (track.selected and "" or "") .. return (track.selected and "" or "") ..
(track.title and " " .. track.title or "") .. (track.title and " " .. track.title or "") ..
" (" .. ( " (" .. (
@ -98,10 +100,8 @@ local function format_track(track)
and track["codec-profile"] .. " " or "") .. and track["codec-profile"] .. " " or "") ..
(track["demux-samplerate"] and track["demux-samplerate"] / 1000 .. (track["demux-samplerate"] and track["demux-samplerate"] / 1000 ..
" kHz " or "") .. " kHz " or "") ..
(track["demux-bitrate"] and string.format("%.0f", track["demux-bitrate"] / 1000) (bitrate and string.format("%.0f", bitrate / 1000) ..
.. " kbps " or "") .. " kbps " or "")
(track["hls-bitrate"] and string.format("%.0f", track["hls-bitrate"] / 1000)
.. " HLS kbps " or "")
):sub(1, -2) .. ")" .. format_flags(track) ):sub(1, -2) .. ")" .. format_flags(track)
end end