Embed video thumbnails in audio files as cover art #2404

Closed
dequis opened this Issue Feb 18, 2014 · 13 comments

Comments

Projects
None yet
6 participants
Contributor

dequis commented Feb 18, 2014

So I found that the -f bestaudio feature downloads m4a files from youtube, which is great, but I'm missing my thumbnails. m4a files support embedding images in them, and video players such as mpv show those images as a static replacement of the video stream. Just like most of the music in video sites, but with a jpeg instead of a video with a single repeated frame.

I was considering writing a small script to get those files with youtube-dl --get-thumbnail and then embed them with AtomicParsley (a mpeg4 metadata manipulator, as this page suggests it's not working with ffmpeg), but then realized it would be a good feature to have as part of youtube-dl, since it already has features to add metadata to the video.

Does this sound like a desirable feature? Is the dependency with AtomicParsley an issue? If it's ok, I might go ahead and implement it, then send a PR later.

Collaborator

phihag commented Feb 18, 2014

Most definitly, this sounds like a great feature, if only as a flag by
default. One reason for the success of youtube-dl is that it works on
any platform and only requires the standard library. Therefore, we would
prefer the feature to be implemented without external libraries, as
otherwise, it will only work for a minority of users (but that would be
okay too, we just need to guard appropriately against a missing
AtomicParsley then).

jaimeMF added the request label Feb 18, 2014

Contributor

dequis commented Feb 18, 2014

Heh... I don't think I want to write a pure python implementation of a mpeg4 metadata parser/encoder, something that apparently the ffmpeg devs couldn't get right yet. From reading the mailing list thread that was linked from the ffmpeg tracker, seems like the issue is far from trivial. Nopenopenope.

Just checked the ./postprocessor/ffmpeg.py file, and since AtomicParsley is a command line tool just like ffmpeg, this feature could use utils.check_executable() to make it a soft dependency, and only checked for if a flag like --embed-thumbnail is passed to youtube-dl (for example). But yeah, still would apply to a minority of users - at least those who can install (and bother to install) this package.

Collaborator

phihag commented Feb 19, 2014

Sorry, I was under the impression that AtomicParsley was a Python library. An external program is fine (and actually preferred, since it's probably easier to install). So go ahead and add support ;) We should just include a good error message when AtomicParsley is missing.

Contributor

JMSwag commented Feb 22, 2014

Hey guys, I wouldn't mind implementing this.

Collaborator

pulpe commented Feb 22, 2014

Tried with AtomicParsley, but looks like it doesn't work.

AtomicParsley error: unsupported MPEG-4 file brand found 'dash'
Contributor

dequis commented Feb 22, 2014

Oh hey awesome, feels good to have an item from my TODO list stolen :3

Just tested it, works perfectly. Thanks!

Contributor

dequis commented Feb 22, 2014

I tried adding thumbnails to all the m4a I downloaded before, using both add-metadata and embed-thumbnail over a list of 206 videos.

$ perl -e 'while(<*.m4a>){ print s/^.*(.{11})\.m4a$/\1\n/r; }' > id_list
$ youtube-dl -f bestaudio --embed-thumbnail --add-metadata -a id_list

It succeeded with all the m4a files, except two, which I already used --embed-thumbnail with.

[download] [...].m4a has already been downloaded
[ffmpeg] Adding metadata to '[...].m4a'
ERROR: Could not write header for output file #0 (incorrect codec parameters ?): Operation not permitted

This can be reproduced with --embed-thumbnail once, then run youtube-dl again with the same video id and either --embed-thumbnail or --add-metadata. Sounds like another thumbnail related ffmpeg bug, I'm afraid :/

Collaborator

pulpe commented Feb 22, 2014

@dequis Should be fixed now.

Contributor

dequis commented Feb 22, 2014

Sweet, confirmed, no issues now. Thanks!

Well, a small side effect of the last few commits is that if youtube-dl is run again with --add-metadata but not --embed-thumbnail, the thumbnail gets removed from the existing file, but seems completely acceptable IMO. The other metadata is never removed if --add-metadata is missing.

Collaborator

pulpe commented Feb 22, 2014

@dequis This is unfortunately necessary because ffmpeg doesn't work with covers/thumbnails :(

Maybe we should give some warning?

Contributor

dequis commented Feb 22, 2014

Yeah, I understand that ffmpeg has issues with this, and this seems like a good solution for that problem.

Honestly it's a rare situation, you have to do --embed-thumbnail first then run youtube-dl again with --add-metadata only. I have no idea why anyone would do that, but if they do they can just try embedding the thumbnail again and it will work.

Collaborator

jaimeMF commented Apr 12, 2014

I've merged @pulpe's commits, it will be available in the next release. Thanks for the report.

jaimeMF closed this Apr 12, 2014

svnpenn commented Aug 31, 2014

Hello, I wrote the answer to that Stack Overflow question. I would just like to
add that AtomicParsley is not the only program that can do this. This may not
help the situation, but I thought it should be mentioned. Example

mp4box -itags cover=infile.png infile.m4a
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment