From e4cb6fd0fd95533f5ef353e18decf1a9eec3c28c Mon Sep 17 00:00:00 2001 From: wm4 Date: Fri, 2 Mar 2018 12:57:28 +0100 Subject: demux: improve audio tag merging for OGG files It's a mess: mp3 files have user tags as global metadata (because the id3v2 tag is global and there is only 1 stream), while OGG files have it per-track (because it's per-stream on the lowest level). mpv needs to try to make something nice out of the mess. It did so by trying to detect audio-only OGG files, and then copying the per-stream metadata to the global metadata. Make the heuristic for detecting this slightly more clever, so it works for files with extra, unrelated streams, like the awful libavformat cover art hack. Fixes #5577. --- demux/demux.c | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/demux/demux.c b/demux/demux.c index 7b8faa0c01..c454286fda 100644 --- a/demux/demux.c +++ b/demux/demux.c @@ -1967,10 +1967,23 @@ void demux_update(demuxer_t *demuxer) } } - // Often useful audio-only files, which have metadata in the audio track - // metadata instead of the main metadata (especially OGG). - if (in->num_streams == 1) - mp_tags_merge(demuxer->metadata, in->streams[0]->tags); + // Often for useful audio-only files, which have metadata in the audio + // track metadata instead of the main metadata, but can also have cover + // art metadata (which libavformat likes to treat as video streams). + int astreams = 0; + int astream_id = -1; + int vstreams = 0; + for (int n = 0; n < in->num_streams; n++) { + struct sh_stream *sh = in->streams[n]; + if (sh->type == STREAM_VIDEO && !sh->attached_picture) + vstreams += 1; + if (sh->type == STREAM_AUDIO) { + astreams += 1; + astream_id = n; + } + } + if (vstreams == 0 && astreams == 1) + mp_tags_merge(demuxer->metadata, in->streams[astream_id]->tags); if (in->stream_metadata) mp_tags_merge(demuxer->metadata, in->stream_metadata); -- cgit v1.2.3