mirror of https://github.com/mpv-player/mpv
player: filter tags, add --display-tags option
This attempts to increase user-friendliness by excluding useless tags. It should be especially helpful with mp4 files, because the FFmpeg mp4 demuxer adds tons of completely useless information to the metadata. Fixes #1403.
This commit is contained in:
parent
6618e5d69a
commit
8048374a5c
|
@ -3187,6 +3187,14 @@ PVR
|
|||
Miscellaneous
|
||||
-------------
|
||||
|
||||
``--display-tags=tag1,tags2,...``
|
||||
Set the list of tags that should be displayed on the terminal. Tags that
|
||||
are in the list, but are not present in the played file, will not be shown.
|
||||
The special value ``all`` disables filtering.
|
||||
|
||||
The default includes a common list of tags, call mpv with ``--list-options``
|
||||
to see it.
|
||||
|
||||
``--mc=<seconds/frame>``
|
||||
Maximum A-V sync correction per frame (in seconds)
|
||||
|
||||
|
|
|
@ -74,6 +74,25 @@ struct mp_tags *mp_tags_dup(void *tparent, struct mp_tags *tags)
|
|||
return new;
|
||||
}
|
||||
|
||||
// Return a copy of the tags, but containing only keys in list. Also forces
|
||||
// the order and casing of the keys (for cosmetic reasons).
|
||||
// The special key "all" matches all keys.
|
||||
struct mp_tags *mp_tags_filtered(void *tparent, struct mp_tags *tags, char **list)
|
||||
{
|
||||
struct mp_tags *new = talloc_zero(tparent, struct mp_tags);
|
||||
for (int n = 0; list && list[n]; n++) {
|
||||
char *key = list[n];
|
||||
if (strcasecmp(key, "all") == 0) {
|
||||
talloc_free(new);
|
||||
return mp_tags_dup(tparent, tags);
|
||||
}
|
||||
char *value = mp_tags_get_str(tags, key);
|
||||
if (value)
|
||||
mp_tags_set_str(new, key, value);
|
||||
}
|
||||
return new;
|
||||
}
|
||||
|
||||
void mp_tags_merge(struct mp_tags *tags, struct mp_tags *src)
|
||||
{
|
||||
for (int n = 0; n < src->num_keys; n++)
|
||||
|
|
|
@ -15,6 +15,7 @@ char *mp_tags_get_str(struct mp_tags *tags, const char *key);
|
|||
char *mp_tags_get_bstr(struct mp_tags *tags, bstr key);
|
||||
void mp_tags_clear(struct mp_tags *tags);
|
||||
struct mp_tags *mp_tags_dup(void *tparent, struct mp_tags *tags);
|
||||
struct mp_tags *mp_tags_filtered(void *tparent, struct mp_tags *tags, char **list);
|
||||
void mp_tags_merge(struct mp_tags *tags, struct mp_tags *src);
|
||||
struct AVDictionary;
|
||||
void mp_tags_copy_from_av_dictionary(struct mp_tags *tags,
|
||||
|
|
|
@ -213,6 +213,8 @@ const m_option_t mp_opts[] = {
|
|||
OPT_CHOICE("hls-bitrate", hls_bitrate, M_OPT_FIXED,
|
||||
({"no", 0}, {"min", 1}, {"max", 2})),
|
||||
|
||||
OPT_STRINGLIST("display-tags*", display_tags, 0),
|
||||
|
||||
#if HAVE_CDDA
|
||||
OPT_SUBSTRUCT("cdda", stream_cdda_opts, stream_cdda_conf, 0),
|
||||
OPT_STRING("cdrom-device", cdrom_device, M_OPT_FILE),
|
||||
|
@ -778,6 +780,12 @@ const struct MPOpts mp_default_opts = {
|
|||
.dvd_angle = 1,
|
||||
|
||||
.mf_fps = 1.0,
|
||||
|
||||
.display_tags = (char **)(const char*[]){
|
||||
"artist", "album", "album_artist", "comment", "composer", "genre",
|
||||
"performer", "title", "track", "icy-title",
|
||||
NULL
|
||||
},
|
||||
};
|
||||
|
||||
#endif /* MPLAYER_CFG_MPLAYER_H */
|
||||
|
|
|
@ -180,6 +180,7 @@ typedef struct MPOpts {
|
|||
char **audio_lang;
|
||||
char **sub_lang;
|
||||
int audio_display;
|
||||
char **display_tags;
|
||||
int sub_visibility;
|
||||
int sub_pos;
|
||||
float sub_delay;
|
||||
|
|
|
@ -196,7 +196,7 @@ typedef struct MPContext {
|
|||
double video_offset;
|
||||
|
||||
struct demuxer *demuxer;
|
||||
struct mp_tags *tags;
|
||||
struct mp_tags *filtered_tags;
|
||||
|
||||
struct track **tracks;
|
||||
int num_tracks;
|
||||
|
|
|
@ -168,9 +168,10 @@ void update_demuxer_properties(struct MPContext *mpctx)
|
|||
tracks->events &= ~DEMUX_EVENT_STREAMS;
|
||||
}
|
||||
if (events & DEMUX_EVENT_METADATA) {
|
||||
struct mp_tags *info = demuxer->metadata;
|
||||
struct mp_tags *info =
|
||||
mp_tags_filtered(mpctx, demuxer->metadata, mpctx->opts->display_tags);
|
||||
// prev is used to attempt to print changed tags only (to some degree)
|
||||
struct mp_tags *prev = mpctx->tags;
|
||||
struct mp_tags *prev = mpctx->filtered_tags;
|
||||
int n_prev = 0;
|
||||
bool had_output = false;
|
||||
for (int n = 0; n < info->num_keys; n++) {
|
||||
|
@ -186,8 +187,8 @@ void update_demuxer_properties(struct MPContext *mpctx)
|
|||
MP_INFO(mpctx, " %s: %s\n", info->keys[n], info->values[n]);
|
||||
had_output = true;
|
||||
}
|
||||
talloc_free(mpctx->tags);
|
||||
mpctx->tags = mp_tags_dup(mpctx, info);
|
||||
talloc_free(mpctx->filtered_tags);
|
||||
mpctx->filtered_tags = info;
|
||||
mp_notify(mpctx, MPV_EVENT_METADATA_UPDATE, NULL);
|
||||
}
|
||||
demuxer->events = 0;
|
||||
|
@ -1223,8 +1224,8 @@ terminate_playback:
|
|||
|
||||
m_config_restore_backups(mpctx->mconfig);
|
||||
|
||||
talloc_free(mpctx->tags);
|
||||
mpctx->tags = NULL;
|
||||
talloc_free(mpctx->filtered_tags);
|
||||
mpctx->filtered_tags = NULL;
|
||||
|
||||
mpctx->playback_initialized = false;
|
||||
|
||||
|
|
Loading…
Reference in New Issue