0

There seems to be almost no documentation on the youtube-dl python library and the parameters for the cli tool don't translate 1:1... I was able to find some parameters in the YoutubeDL.py that is linked in the Readme, but definitely not all of them.

For instance, it is not clear to me how I can embed the video thumbnail into the video file I'm downloading. With the cli tool, I can use --embed-thumbnail, but when I try to use it in the config object it doesn't work. I don't even get an error

 ydl_opts = {
     'format': 'bestvideo[height<=480]+bestaudio[ext=m4a]/best', # works
     'embed-thumbnail': True, # not working
     'embedthumbnail': True, # not working
     'updatetime': False # works
 }
 youtube_dl.YoutubeDL(ydl_opts)

Here is a cli example that worked for me:

youtube-dl --format "bestvideo[height<=480]+bestaudio[ext=m4a]/best" --embed-thumbnail https://www.youtube.com/watch?v=Co2KIYmaeTY

I verified it by running this on the resulting .mp4 file to extract the thumbnail:

AtomicParsley "thumbnail test-Co2KIYmaeTY.mp4" -E

This file is the closest I got: https://github.com/rg3/youtube-dl/blob/master/youtube_dl/postprocessor/embedthumbnail.py

But I'm not sure what to make out of it...

Ulrich Eckhardt
  • 16,572
  • 3
  • 28
  • 55
Forivin
  • 14,780
  • 27
  • 106
  • 199

1 Answers1

3

YoutubeDL.py does list all parameters to youtube-dl. embed-thumbnail and embedthumbnail don't work because they are not valid options for a YoutubeDL, and hence not listed in the list of options. However, these options cover "just" the download.

Many effects are implemented by postprocessors, i.e. code that runs after the download has been completed. Postprocessors can be composited in new ways, but if you just want to replicate an existing command-line invocation, have a look at the main function to find out how command-line options map to postprocessors and YoutubeDL API options. For instance, to write thumbnails into video files, you can use

from __future__ import unicode_literals
import youtube_dl

ydl_opts = {
    'format': 'bestvideo[height<=480]+bestaudio[ext=m4a]/best',
    'updatetime': False,
    'writethumbnail': True,
    'postprocessors': [{
        'key': 'EmbedThumbnail',
        'already_have_thumbnail': False,
    }],
}

with youtube_dl.YoutubeDL(ydl_opts) as ydl:
    ydl.download(['https://www.youtube.com/watch?v=BaW_jenozKc'])
  • Thanks, why is `writethumbnail` necessary, though? I don't want to save the jpg files, I just want to have them embedded in the video files. But without `writethumbnail` it stops working. – Forivin Mar 11 '18 at 21:28
  • At the moment, that's how the postprocessor works - it simply takes an image file. If you can provide a way to embed a thumbnail in another way, and extract it as an Python object instead of a file (probably needs base64 or so to be compatible with `-j`), feel free to suggest patches to youtube-dl. –  Mar 11 '18 at 23:41
  • But the cli tool can already do what I want. So shouldn't there be a way to do the same with the library? I mean for the cli tool I don't have to pass `writethumbnail` or so, I can just pass `embed-thumbnail` and thus I won't have to deal with jpg images in my downloads folder. – Forivin Mar 12 '18 at 07:43
  • The CLI sets `already_have_thumbnail` to `False`, which then makes the postprocessor delete the jpg file afterwards. I have updated the answer. –  Mar 12 '18 at 08:35
  • Can you specify the maximum FPS too? – MmBaguette May 07 '21 at 22:49