Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

various: sync track information output #14453

Merged
merged 4 commits into from
Jul 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions DOCS/interface-changes/packet-bitrate.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
remove deprecated `packet-video-bitrate` `packet-audio-bitrate` and `packet-sub-bitrate` properties
8 changes: 0 additions & 8 deletions DOCS/man/input.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3479,14 +3479,6 @@ Property list
In earlier versions of mpv, these properties returned a static (but bad)
guess using a completely different method.

``packet-video-bitrate``, ``packet-audio-bitrate``, ``packet-sub-bitrate``
Old and deprecated properties for ``video-bitrate``, ``audio-bitrate``,
``sub-bitrate``. They behave exactly the same, but return a value in
kilobits. Also, they don't have any OSD formatting, though the same can be
achieved with e.g. ``${=video-bitrate}``.

These properties shouldn't be used anymore.

``audio-device-list``
The list of discovered audio devices. This is mostly for use with the
client API, and reflects what ``--audio-device=help`` with the command line
Expand Down
28 changes: 10 additions & 18 deletions player/command.c
Original file line number Diff line number Diff line change
Expand Up @@ -2075,9 +2075,12 @@ static int get_track_entry(int item, int action, void *arg, void *ctx)
return m_property_read_sub(props, action, arg);
}

static const char *track_type_name(enum stream_type t)
static const char *track_type_name(struct track *t)
{
switch (t) {
if (t->image)
return "Image";

switch (t->type) {
case STREAM_VIDEO: return "Video";
case STREAM_AUDIO: return "Audio";
case STREAM_SUB: return "Sub";
Expand All @@ -2099,7 +2102,7 @@ static int property_list_tracks(void *ctx, struct m_property *prop,
continue;

res = talloc_asprintf_append(res, "%s: ",
track_type_name(track->type));
track_type_name(track));
res = talloc_strdup_append(res,
track->selected ? list_current : list_normal);
res = talloc_asprintf_append(res, "(%d) ", track->user_tid);
Expand Down Expand Up @@ -3337,8 +3340,7 @@ static int mp_property_packet_bitrate(void *ctx, struct m_property *prop,
int action, void *arg)
{
MPContext *mpctx = ctx;
int type = (uintptr_t)prop->priv & ~0x100;
bool old = (uintptr_t)prop->priv & 0x100;
int type = *(int *)prop->priv;

struct demuxer *demuxer = NULL;
if (mpctx->current_track[0][type])
Expand All @@ -3356,10 +3358,6 @@ static int mp_property_packet_bitrate(void *ctx, struct m_property *prop,
// r[type] is in bytes/second -> bits
double rate = r[type] * 8;

// Same story, but used kilobits for some reason.
if (old)
return m_property_int64_ro(action, arg, llrint(rate / 1000.0));

if (action == M_PROPERTY_PRINT) {
rate /= 1000;
if (rate < 1000) {
Expand Down Expand Up @@ -4130,15 +4128,9 @@ static const struct m_property mp_properties_base[] = {
{"ab-loop-a", mp_property_ab_loop},
{"ab-loop-b", mp_property_ab_loop},

#define PROPERTY_BITRATE(name, old, type) \
{name, mp_property_packet_bitrate, (void *)(uintptr_t)((type)|(old?0x100:0))}
PROPERTY_BITRATE("packet-video-bitrate", true, STREAM_VIDEO),
PROPERTY_BITRATE("packet-audio-bitrate", true, STREAM_AUDIO),
PROPERTY_BITRATE("packet-sub-bitrate", true, STREAM_SUB),

PROPERTY_BITRATE("video-bitrate", false, STREAM_VIDEO),
PROPERTY_BITRATE("audio-bitrate", false, STREAM_AUDIO),
PROPERTY_BITRATE("sub-bitrate", false, STREAM_SUB),
{"video-bitrate", mp_property_packet_bitrate, .priv = (void *)&(const int){STREAM_VIDEO}},
{"audio-bitrate", mp_property_packet_bitrate, .priv = (void *)&(const int){STREAM_AUDIO}},
{"sub-bitrate", mp_property_packet_bitrate, .priv = (void *)&(const int){STREAM_SUB}},

{"focused", mp_property_focused},
{"display-names", mp_property_display_names},
Expand Down
16 changes: 9 additions & 7 deletions player/loadfile.c
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ static void print_stream(struct MPContext *mpctx, struct track *t, bool indent)
const char *langopt = "?";
switch (t->type) {
case STREAM_VIDEO:
tname = "Video"; selopt = "vid"; langopt = "vlang";
tname = t->image ? "Image" : "Video"; selopt = "vid"; langopt = "vlang";
break;
case STREAM_AUDIO:
tname = "Audio"; selopt = "aid"; langopt = "alang";
Expand Down Expand Up @@ -299,21 +299,23 @@ static void print_stream(struct MPContext *mpctx, struct track *t, bool indent)
if (s && s->codec->samplerate)
APPEND(b, " %d Hz", s->codec->samplerate);
}
if (s && s->hls_bitrate > 0)
APPEND(b, " %d kbps", (s->hls_bitrate + 500) / 1000);
if (s && s->codec->bitrate)
APPEND(b, " %d kbps", (s->codec->bitrate + 500) / 1000);
if (s && s->hls_bitrate)
APPEND(b, " %d HLS kbps", (s->hls_bitrate + 500) / 1000);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this looks strange to me

Copy link
Member

@sfan5 sfan5 Aug 1, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what kind of unit is "HLS kbps"?
I get the idea to indicate where the bitrate came from but it looks weird and I don't think users really care.

my suggestion is to print codec bitrate if available or else print hls bitrate, but without the extra "HLS"
(based on the assumption that codec bitrate is generally more accurate than hls bitrate)

APPEND(b, ")");

bool first = true;
if (t->default_track)
ADD_FLAG(b, "default", first);
if (t->forced_track)
ADD_FLAG(b, "forced", first);
if (t->attached_picture)
ADD_FLAG(b, "picture", first);
if (t->dependent_track)
ADD_FLAG(b, "dependent", first);
if (t->visual_impaired_track)
ADD_FLAG(b, "visual_impaired", first);
ADD_FLAG(b, "visual-impaired", first);
if (t->hearing_impaired_track)
ADD_FLAG(b, "hearing_impaired", first);
ADD_FLAG(b, "hearing-impaired", first);
if (t->is_external)
ADD_FLAG(b, "external", first);
if (!first)
Expand Down
29 changes: 26 additions & 3 deletions player/lua/select.lua
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,25 @@ mp.add_forced_key_binding(nil, "select-playlist", function ()
})
end)

local function format_flags(track)
local flags = ""

for _, flag in ipairs({
"default", "forced", "dependent", "visual-impaired", "hearing-impaired",
"image", "external"
}) do
if track[flag] then
flags = flags .. flag .. " "
end
end

if flags == "" then
return ""
end

return " [" .. flags:sub(1, -2) .. "]"
end

local function format_track(track)
return (track.selected and "●" or "○") ..
(track.title and " " .. track.title or "") ..
Expand All @@ -79,15 +98,19 @@ local function format_track(track)
and track["codec-profile"] .. " " or "") ..
(track["demux-samplerate"] and track["demux-samplerate"] / 1000 ..
" kHz " or "") ..
(track.external and "external " or "")
):sub(1, -2) .. ")"
(track["demux-bitrate"] and string.format("%.0f", track["demux-bitrate"] / 1000)
.. " kbps " or "") ..
(track["hls-bitrate"] and string.format("%.0f", track["hls-bitrate"] / 1000)
.. " HLS kbps " or "")
):sub(1, -2) .. ")" .. format_flags(track)
end

mp.add_forced_key_binding(nil, "select-track", function ()
local tracks = {}

for i, track in ipairs(mp.get_property_native("track-list")) do
tracks[i] = track.type:sub(1, 1):upper() .. track.type:sub(2) .. ": " ..
tracks[i] = (track.image and "Image" or
track.type:sub(1, 1):upper() .. track.type:sub(2)) .. ": " ..
format_track(track)
end

Expand Down
15 changes: 8 additions & 7 deletions player/lua/stats.lua
Original file line number Diff line number Diff line change
Expand Up @@ -952,9 +952,10 @@ local function add_video(s)
return
end

append(s, "", {prefix="Video:", nl=o.nl .. o.nl, indent=""})
local track = mp.get_property_native("current-tracks/video")
if track and append(s, track["codec-desc"], {prefix_sep="", nl="", indent=""}) then
if track then
append(s, "", {prefix=track.image and "Image:" or "Video:", nl=o.nl .. o.nl, indent=""})
append(s, track["codec-desc"], {prefix_sep="", nl="", indent=""})
append(s, track["codec-profile"], {prefix="[", nl="", indent=" ", prefix_sep="",
no_prefix_markup=true, suffix="]"})
if track["codec"] ~= track["decoder"] then
Expand Down Expand Up @@ -992,7 +993,7 @@ local function add_video(s)
end
append_img_params(s, r, ro)
append_hdr(s, ro)
append_property(s, "packet-video-bitrate", {prefix="Bitrate:", suffix=" kbps"})
append_property(s, "video-bitrate", {prefix="Bitrate:"})
append_filters(s, "vf", "Filters:")
end

Expand Down Expand Up @@ -1037,7 +1038,7 @@ local function add_audio(s)
append(s, merge(r, ro, "format"), {prefix="Format:", nl=cc and "" or o.nl,
indent=cc and o.prefix_sep .. o.prefix_sep})
append(s, merge(r, ro, "samplerate"), {prefix="Sample Rate:", suffix=" Hz"})
append_property(s, "packet-audio-bitrate", {prefix="Bitrate:", suffix=" kbps"})
append_property(s, "audio-bitrate", {prefix="Bitrate:"})
append_filters(s, "af", "Filters:")
end

Expand Down Expand Up @@ -1217,7 +1218,7 @@ local function add_track(c, t, i)
return
end

local type = t["type"]:sub(1,1):upper() .. t["type"]:sub(2)
local type = t.image and "Image" or t["type"]:sub(1, 1):upper() .. t["type"]:sub(2)
append(c, "", {prefix=type .. ":", nl=o.nl .. o.nl, indent=""})
append(c, t["title"], {prefix_sep="", nl="", indent=""})
append(c, t["id"], {prefix="ID:"})
Expand All @@ -1226,8 +1227,8 @@ local function add_track(c, t, i)
append(c, t["ff-index"], {prefix="FFmpeg Index:", nl="", indent=o.prefix_sep .. o.prefix_sep})
append(c, t["external-filename"], {prefix="File:"})
append(c, "", {prefix="Flags:"})
local flags = {"default", "forced", "external", "dependent",
"hearing-impaired", "visual-impaired", "image", "albumart"}
local flags = {"default", "forced", "dependent", "visual-impaired",
"hearing-impaired", "image", "albumart", "external"}
local any = false
for _, flag in ipairs(flags) do
if t[flag] then
Expand Down