question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Feature Request] Crop to square thumbnail when embedding in MP3s

See original GitHub issue

Checklist

  • I’m reporting a feature request
  • I’ve verified that I’m running yt-dlp version 2021.06.09
  • I’ve searched the bugtracker for similar feature requests including closed ones

Description

Music thumbnails from YouTube are always in 16:9 format, but the album art pictured is always 1:1. As a result, embedded thumbnails are letterboxed and get distorted in music players. Youtube-DL has an identitical issue at ytdl-org/youtube-dl#20011, but it and its respective pull request has since been ignored; I’m hoping this fork will be more receptive.

A pull request already exists for Youtube-DL to do this (ytdl-org/youtube-dl#20022,) and it turns out that it’s a pretty simple adjustment to the embed_thumbnail postprocessor to filter the thumbnail.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:10 (3 by maintainers)

github_iconTop GitHub Comments

4reactions
pukkandancommented, Jul 2, 2021

You can already do this using --ppa.

Just put this in your config file:

–ppa ‘’‘EmbedThumbnail+ffmpeg_o:-c:v mjpeg -vf crop=“‘if(gt(ih,iw),iw,ih)’:‘if(gt(iw,ih),ih,iw)’”’‘’ (See below comments)

Eg:

$ yt-dlp -x --audio-format mp3 "3_Nn1Ihr1jI" --embed-thumbnail -v --convert-thumbnail jpg --ppa "EmbedThumbnail+ffmpeg_o:-c:v mjpeg -vf crop=\"'if(gt(ih,iw),iw,ih)':'if(gt(iw,ih),ih,iw)'\"" --exec ffprobe
[debug] Command-line config: ['-x', '--audio-format', 'mp3', '3_Nn1Ihr1jI', '--embed-thumbnail', '-v', '--convert-thumbnail', 'jpg', '--ppa', 'EmbedThumbnail+ffmpeg_o:-c:v mjpeg -vf crop="\'if(gt(ih,iw),iw,ih)\':\'if(gt(iw,ih),ih,iw)\'"', '--exec', 'ffprobe']
[debug] Encodings: locale cp1252, fs utf-8, out utf-8, pref cp1252
[debug] yt-dlp version 2021.06.09 (source)
[debug] Plugin Extractors: ['SamplePlugin']
[debug] Git HEAD: 4c7853de14
[debug] Python version 3.9.5 (CPython 64bit) - Windows-10-10.0.19043-SP0
[debug] exe versions: ffmpeg 2021-04-11-git-309e3cc15c-full_build-www.gyan.dev, ffprobe 2021-04-11-git-309e3cc15c-full_build-www.gyan.dev, phantomjs 2.1.1
[debug] Proxy map: {}
[debug] [youtube] Extracting URL: 3_Nn1Ihr1jI
[youtube] 3_Nn1Ihr1jI: Downloading webpage
[debug] Formats sorted by: hasvid, ie_pref, lang, quality, res, fps, vcodec:vp9.2(10), acodec, filesize, fs_approx, tbr, vbr, abr, asr, proto, vext, aext, hasaud, source, id
[info] 3_Nn1Ihr1jI: Downloading 1 format(s): 251
[youtube] 3_Nn1Ihr1jI: Downloading thumbnail  ...
[youtube] 3_Nn1Ihr1jI: Writing thumbnail to: Don't Worry About Me - Episode 29 [3_Nn1Ihr1jI].webp
[ThumbnailsConvertor] Converting thumbnail "Don't Worry About Me - Episode 29 [3_Nn1Ihr1jI].webp" to jpg
[debug] ffmpeg command line: ffmpeg -y -loglevel "repeat+info" -f image2 -pattern_type none -i "file:Don't Worry About Me - Episode 29 [3_Nn1Ihr1jI].webp" "-bsf:v" mjpeg2jpeg "file:Don't Worry About Me - Episode 29 [3_Nn1Ihr1jI].jpg"
Deleting original file Don't Worry About Me - Episode 29 [3_Nn1Ihr1jI].webp (pass -k to keep)
[download] Don't Worry About Me - Episode 29 [3_Nn1Ihr1jI].mp3 has already been downloaded
[debug] ffmpeg command line: ffprobe -show_streams "file:Don't Worry About Me - Episode 29 [3_Nn1Ihr1jI].mp3"
[ExtractAudio] Post-process file Don't Worry About Me - Episode 29 [3_Nn1Ihr1jI].mp3 exists, skipping
[EmbedThumbnail] ffmpeg: Adding thumbnail to "Don't Worry About Me - Episode 29 [3_Nn1Ihr1jI].mp3"
[debug] ffmpeg command line: ffmpeg -y -loglevel "repeat+info" -i "file:Don't Worry About Me - Episode 29 [3_Nn1Ihr1jI].mp3" -i "file:Don't Worry About Me - Episode 29 [3_Nn1Ihr1jI].jpg" -c copy -map "0:0" -map "1:0" -id3v2_version 3 "-metadata:s:v" "title=\"Album cover\"" "-metadata:s:v" "comment=\"Cover (front)\"" "-c:v" mjpeg -vf "crop='if(gt(ih,iw),iw,ih)':'if(gt(iw,ih),ih,iw)'" "file:Don't Worry About Me - Episode 29 [3_Nn1Ihr1jI].temp.mp3"
Deleting original file Don't Worry About Me - Episode 29 [3_Nn1Ihr1jI].jpg (pass -k to keep)
[Exec] Executing command: ffprobe "D:\AKJ\Progs\yt-dlc\Don't Worry About Me - Episode 29 [3_Nn1Ihr1jI].mp3"
ffprobe version 2021-04-11-git-309e3cc15c-full_build-www.gyan.dev Copyright (c) 2007-2021 the FFmpeg developers
  built with gcc 10.2.0 (Rev6, Built by MSYS2 project)
  configuration: --enable-gpl --enable-version3 --enable-static --disable-w32threads --disable-autodetect --enable-fontconfig --enable-iconv --enable-gnutls --enable-libxml2 --enable-gmp --enable-lzma --enable-libsnappy --enable-zlib --enable-librist --enable-libsrt --enable-libssh --enable-libzmq --enable-avisynth --enable-libbluray --enable-libcaca --enable-sdl2 --enable-libdav1d --enable-libzvbi --enable-librav1e --enable-libsvtav1 --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxvid --enable-libaom --enable-libopenjpeg --enable-libvpx --enable-libass --enable-frei0r --enable-libfreetype --enable-libfribidi --enable-libvidstab --enable-libvmaf --enable-libzimg --enable-amf --enable-cuda-llvm --enable-cuvid --enable-ffnvcodec --enable-nvdec --enable-nvenc --enable-d3d11va --enable-dxva2 --enable-libmfx --enable-libglslang --enable-vulkan --enable-opencl --enable-libcdio --enable-libgme --enable-libmodplug --enable-libopenmpt --enable-libopencore-amrwb --enable-libmp3lame --enable-libshine --enable-libtheora --enable-libtwolame --enable-libvo-amrwbenc --enable-libilbc --enable-libgsm --enable-libopencore-amrnb --enable-libopus --enable-libspeex --enable-libvorbis --enable-ladspa --enable-libbs2b --enable-libflite --enable-libmysofa --enable-librubberband --enable-libsoxr --enable-chromaprint
  libavutil      56. 72.100 / 56. 72.100
  libavcodec     58.136.101 / 58.136.101
  libavformat    58. 78.100 / 58. 78.100
  libavdevice    58. 14.100 / 58. 14.100
  libavfilter     7.111.100 /  7.111.100
  libswscale      5. 10.100 /  5. 10.100
  libswresample   3. 10.100 /  3. 10.100
  libpostproc    55. 10.100 / 55. 10.100
Input #0, mp3, from 'D:\AKJ\Progs\yt-dlc\Don't Worry About Me - Episode 29 [3_Nn1Ihr1jI].mp3':
  Metadata:
    encoder         : Lavf58.78.100
  Duration: 00:40:07.63, start: 0.023021, bitrate: 69 kb/s
  Stream #0:0: Audio: mp3, 48000 Hz, stereo, fltp, 69 kb/s
    Metadata:
      encoder         : Lavc58.13
  Stream #0:1: Video: mjpeg (Baseline), yuvj420p(pc, bt470bg/unknown/unknown), 720x720, 90k tbr, 90k tbn, 90k tbc (attached pic)
    Metadata:
      title           : "Album cover"
      comment         : Other
1reaction
matant94commented, Apr 12, 2022

Sorry I copy pasted the setting you get but still have a 1270x720 thumb here are my configs actually 'cause no ones worked

#Video Format Options
--check-formats
-f bestaudio -S "proto:https,acodec,+asr:44100" --audio-quality 0

#Subtitle Options

#Authentication
-n
--netrc-location "D:\Launcher\YTMusicDownloader\yt-dlp"

#Post-Processing Options
--ffmpeg-location "D:\Launcher\YTMusicDownloader\yt-dlp"
-x
--audio-format flac
--add-metadata

#SponsorBlock Options
--sponsorblock-mark all
--sponsorblock-remove sponsor,selfpromo

#Extractor Options
--extractor-args "youtube:player-client=android_music;include_live_dash"
--extractor-retries 15
--allow-dynamic-mpd

Actually I also can’t parse the track number

Read more comments on GitHub >

github_iconTop Results From Across the Web

How do I crop youtube thumbnails?? : r/youtubedl - Reddit
I want to crop the thumbnails into a square. This is what I typed into my notepad: -x. -f ba. --audio-format mp3.
Read more >
Cropped and square Thumbnail's - WordPress.org
Issue is the Thumbnail's, they are square and cropped. I need them to appear as original, rectangular. Contacted theme support, “Porto”. They stated,...
Read more >
Aperture Plugin - Apple Community - Apple Support Communities
The other feature request that jumped out at me - any way to have the last values ... Since the thumbnail is square,...
Read more >
Feature Requests (Page 6) — Juicebox-Pro Support — Juicebox ...
Juicebox-Pro will crop the thumbnails only if the thumbWidth and thumbHeight configuration options do not match the actual dimensions of the thumbnail images ......
Read more >
Real-time Thumbnail Generation in a (mostly) Serverless AWS ...
two stickmen cropping and resizing images ... But this all goes wrong when you need to embed a square image, you will not...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found