When I'm downloading songs and audio stories for my son's iPod, one of the requirements is that each song has its own cover art or thumbnail. Since my son is too young to read, he relies on the pictures to figure out which songs he's skipping through.
Since not all the content can be found on Apple's music store, I must rely on various other sources, even YouTube. Ripping songs from YouTube is relatively easy, since we have youtube-dl and its forks (I'm using yt-dlp). Still, the video thumbnail will always be a landscape picture (16:9 or whatever the video aspect ratio is). The song thumbnail on the iPod looks better when it's a square (aspect ratio 1:1), which triggered the perfectionist in me. I edited them manually using Photoshop for a while while I was editing them manually using Photoshop, but that required too much time.
So, I started looking into ways to automate this using yt-dlp and ffmpeg. After spending a few hours researching, here's the final result: a bash function that downloads a video/audio file from a URL supported by yt-dlp, converts it to mp3 192kpbs, and adds the metadata, including the picture, which was transformed to a square by adding blur to fill in the missing parts (similar to the way YouTube adds blur to the vertical videos on the desktop).
You can find the code on Github (in case the embedded JS does not load): https://gist.github.com/Luxian/...
I wrote this starting with examples and information that I found on the following links:
- StackOverflow: FFmpeg: convert any video to square 1:1 video with blurred sidebars
- StackOverflow: FFmpeg: How to convert vertical video with black sides to video 16:9 with blurred background sides
- FFmpeg Filtering Guide
I hope this helps someone else out there looking to achieve the same. If it does help you, please let me know in a comment.
Comments