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

Add support for external cover art #3056

Closed
JamesTheAwesomeDude opened this issue Apr 15, 2016 · 23 comments
Closed

Add support for external cover art #3056

JamesTheAwesomeDude opened this issue Apr 15, 2016 · 23 comments

Comments

@JamesTheAwesomeDude
Copy link

JamesTheAwesomeDude commented Apr 15, 2016

Oftentimes, music will have its cover art stored as folder.jpg or cover.jpg either in its folder or in the parent folder (in the case of multi-disc albums), rather than separate copies of the cover art being embedded in each and every track in an album.

MPV currently neither automatically detects these files (VLC currently does do this, though only for same-folder cover art) nor has even a flag to specify the location of external cover art. This means that to play a song with its cover art being displayed by the music playing window, it must be converted/muxed to a temporary file containing the audio and cover art in one.

It would be a nice feature if MPV supported external cover art at some level; if not by detecting [Ff]older.jpg/cover.jpg, then at least by allowing a flag to be passed to specify the art to be displayed.

@ghost
Copy link

ghost commented Apr 16, 2016

You can do it with --external-file=image.jpg, but since the seek code doesn't consider it a static image (but merely a 1-frame video), the timing and seek behavior is strange.

@JamesTheAwesomeDude
Copy link
Author

Yeah, exactly.. :/

Embedded cover art is handled so nicely; it would be great to be able to
load external cover art that well.

~James

On Sat, Apr 16, 2016 at 11:35 AM, V. Lang notifications@github.com wrote:

You can do it with --external-file=image.jpg, but since the seek code
doesn't consider it a static image (but merely a 1-frame video), the timing
and seek behavior is strange.


You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub
#3056 (comment)

@bitingsock
Copy link
Contributor

bitingsock commented May 27, 2016

My idea is related but explained differently. I think it solves the same problem but allows for more uses:
#869

@bitingsock
Copy link
Contributor

I don't know if the seek code was ever change or not but using --external-file does seem to work for me now. osc and seeking seems functional

@marrowsuck
Copy link

Im on master b0951d7 and playing an audio file with external album art with this command
mpv --external-file=cover.jpg --force-window --image-display-duration=inf music.ogg
only displays a black window for me.
Any suggestions?

@ghost
Copy link

ghost commented Apr 7, 2018

You also need --vid=1.

@marrowsuck
Copy link

Great! Thanks!

@Akemi
Copy link
Member

Akemi commented Sep 21, 2019

seems fixed.

@Akemi Akemi closed this as completed Sep 21, 2019
@shmerl
Copy link

shmerl commented Jan 29, 2020

So is it supposed to work now with cover.jpg being placed in the same directory? Doesn't seem to work for me. I'm running it simply as mpv <audio_file>.

@CounterPillow
Copy link
Contributor

no, you need to specify --external-file=cover.jpg --vid=1. It's best if you implement a script that does this for you.

@shmerl
Copy link

shmerl commented Jan 29, 2020

Is there some way to make it a default for audio in mpv config file? I'd like to reproduce vlc's behavior in this, without the need to make scripts or type that explicitly.

Or may be such config option can be added if it doesn't exist yet?

@Dudemanguy
Copy link
Member

Dudemanguy commented Jan 29, 2020

If you tag the audio file's metadata with cover art, mpv will open that up automatically.

@ghost
Copy link

ghost commented Jan 29, 2020

I guess it'd be possible to automatically pick up an external file, but not sure how popular this would be. (And whether people would come up with dozens of alternative filenames that would "need" to be loaded.)

@shmerl
Copy link

shmerl commented Jan 29, 2020

If you tag the audio file's metadata with cover art, mpv will open that up automatically.

You mean to embed the image into the audio file? I've done that before, but it bloats the result, since you end up with the same image in each file from the album.

@shmerl
Copy link

shmerl commented Jan 29, 2020

I guess it'd be possible to automatically pick up an external file, but not sure how popular this would be. (And whether people would come up with dozens of alternative filenames that would "need" to be loaded.)

I don't necessarily propose a given default, but just an ability to explicitly configure the name, that will be then picked up without extra parameters.

I.e. something like this in mpv config file:

default-cover-art = cover.jpg

Whoever wants will be able to set it to whatever name they want.

@Dudemanguy
Copy link
Member

You mean to embed the image into the audio file? I've done that before, but it bloats the result, since you end up with the same image in each file from the album.

Yeah that's a valid point. I don't really care much about filesize myself, but it's certainly not very efficient.

@Lopson
Copy link

Lopson commented Aug 7, 2020

If you tag the audio file's metadata with cover art, mpv will open that up automatically.

I found an edge case: I have albums made up of multiple FLAC files, all of them have the respective cover art embedded into them. When I open the album's Cue Sheet, the cover art in the FLAC files is ignored.

For reference, I'm using the version currently available in Chocolatey, 0.32.0 built on Mon Jan 27 12:34:40 +08 2020.

@bitingsock
Copy link
Contributor

bitingsock commented Aug 7, 2020

when I play a cuesheet it displays embedded images but it only displays the image in the first file.
does this have something to do with EDL?

@ghost
Copy link

ghost commented Aug 8, 2020

These are all edge cases and have nothing to do with the original case.
Can anyone track down vlc's code for this? I want to know by which criteria they load such external files.

@shmerl
Copy link

shmerl commented Aug 20, 2020

Hm, putting this in config file works:

external-file=cover.jpg
vid=1

but it's also not correct for cases which already have an embedded cover for example and where you wouldn't have a cover file, so you'll get a message like:

[file] Cannot open file 'cover.jpg': No such file or directory
Failed to open cover.jpg.
Can not open external file cover.jpg.

What would be good to have is an option of using that only as a default and in case the file exists. Not as a mandatory option.

@guidocella
Copy link
Contributor

I have been using a script with video-add since it was added to load cover art. If you have playlists with tracks from multiple directories, this approach will update the cover when the directory changes.

If you want to load the cover only when it exists, this will work:

local utils = require 'mp.utils'

mp.register_event('file-loaded', function()
    for _, track in pairs(mp.get_property_native('track-list')) do
        if track.type == 'video' and not track.albumart then
            do return end
        end
    end

    local dir, _ = utils.split_path(mp.get_property('path'))
    local cover = dir .. '/cover.jpg'
    if file_exists(cover) then
        mp.commandv('video-add', cover)
    end
end)

function file_exists(name)
    local file = io.open(name)
    if file then
        io.close(file)
    end
    return not not file
end

If you don't want to override embedded cover arts, remove and not track.albumart or set audio-display=no.

This seems to be the code VLC uses to load cover art: https://code.videolan.org/chouquette/vlc/-/blob/master/modules/meta_engine/folder.c

@ghost
Copy link

ghost commented Sep 25, 2020

Everyone here is suggesting hacks over hacks instead of helping with how this could be implemented properly and answering requested information, so I'm going to lock this and I'll delete some posts.

@ghost ghost locked as resolved and limited conversation to collaborators Sep 25, 2020
@ghost ghost deleted a comment from bratekarate Sep 25, 2020
ghost pushed a commit that referenced this issue Sep 27, 2020
Picks up files like "cover.jpg". It's made part of normal external file
loading, so I'm adding 3 new options that are direct equivalents for the
options that control loading of external subtitle and audio files. Even
though I bet nobody wants them and they just increase confusion... I
guess the world is actually hell, so this outcome should be fine.

It prefers non-specific external files like "cover.jpg" over embedded
cover art. Not sure if that's wanted or unwanted.

There's some pain over explicitly marking such files as external
pictures. This is basically an optimization: in most cases, a heuristic
would treat an image file loaded with --external-file the same (it's a
heuristic because ffmpeg can't tell us whether something is an image or
a video). However, even with this heuristic, it would decode the cover
art picture again on each seek, which would essentially slow down
seeking in audio files. This bothered me greatly, which is why I'm
adding these additional options at all, and bothered with the previous
commit.

Fixes: #3056
@ghost
Copy link

ghost commented Sep 27, 2020

There's now external cover art loading by default in git master, using a hard-coded list: https://github.com/mpv-player/mpv/blob/master/player/external_files.c#L45

Make new issues on problems.

Dudemanguy pushed a commit to Dudemanguy/mpv that referenced this issue May 18, 2021
Picks up files like "cover.jpg". It's made part of normal external file
loading, so I'm adding 3 new options that are direct equivalents for the
options that control loading of external subtitle and audio files. Even
though I bet nobody wants them and they just increase confusion... I
guess the world is actually hell, so this outcome should be fine.

It prefers non-specific external files like "cover.jpg" over embedded
cover art. Not sure if that's wanted or unwanted.

There's some pain over explicitly marking such files as external
pictures. This is basically an optimization: in most cases, a heuristic
would treat an image file loaded with --external-file the same (it's a
heuristic because ffmpeg can't tell us whether something is an image or
a video). However, even with this heuristic, it would decode the cover
art picture again on each seek, which would essentially slow down
seeking in audio files. This bothered me greatly, which is why I'm
adding these additional options at all, and bothered with the previous
commit.

Fixes: mpv-player#3056
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

10 participants