Skip to content

Instantly share code, notes, and snippets.

@adrienjoly
Last active May 3, 2024 01:47
Show Gist options
  • Star 7 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save adrienjoly/3290cba25c3350e264c0a43765f11e75 to your computer and use it in GitHub Desktop.
Save adrienjoly/3290cba25c3350e264c0a43765f11e75 to your computer and use it in GitHub Desktop.
Create a YouTube Art Track for free using HTML, CSS and ffmpeg

Create a YouTube Art Track using HTML, CSS and ffmpeg

This may be more of a recipe than a tutorial, but let me just share the steps I followed to generate YouTube Art Track for my band, using intermediate computer skills.

Motivation

As a musician, sharing your music on YouTube is a must. But YouTube is a video platform, and making a music video to go with a song can be costly and time consuming. Several web services propose to generate a nice looking video out of your MP3 file, and to upload the result directly to your YouTube account, but this would cost you $30 per song in HD quality.

Expected output

We target a fixed image with the following layout, to be displayed while the track is playing from youtube.com:

 ________________________
|  _________             |
| |         |            |
| |  cover  |  Title     |
| |   art   |  Artist    |
| |_________|            |
|________________________|

Recommendations from YouTube

In order to make sure that the quality of the final video will be optimal, let's see what YouTube recommends in terms of video definition and encoding formats.

  • MP4 file
  • Audio: AAC-LC, 96 kHz or 48 kHz, ~384 kbit/s (for Stereo)
  • Video: H.264, Variable bitrate, chrominance: 4:2:0
  • Video definition: 2560 x 1440 (for 1440p), with 16:9 aspect ratio

Step 1. Generate the image

  1. Fork this Codepen: https://codepen.io/adrienjoly/pen/GXKQYj?editors=1100
  2. In the HTML panel, change the track info to put your own
  3. In the CSS panel, change the URL of your cover art
  4. From the bottom-right corner of Codepen, export to a ZIP file
  5. Extract the ZIP file and open the HTML file in full-screen
  6. Take a full-screen screenshot into a PNG file (i.e. on a Mac with retina display, Cmd-Shift-3 should generate a 2560 x 1440 screenshot)

Step 2. Generate the video

Run the following command to generate a YouTube-ready video from the Tierra.png screenshot and the Tierra.wav audio track:

$ ffmpeg -loop 1 -i Tierra.png -i Tierra.wav -c:v libx264 -tune stillimage -c:a aac -b:a 384k -pix_fmt yuv420p -shortest Tierra_out.mp4

If you don't have ffmpeg on your system, install it.

Note: I let YouTube crop my image to its own definition. If you want to crop it yourself, follow: https://www.oodlestechnologies.com/blogs/Crop-and-scale-image-using-ffmpeg.

Step 3. Upload to Youtube

The last step is the most obvious one: go to youtube.com/upload, and drop your video there. (e.g. Tierra_out.mp4, in my case)

Enjoy! And good luck with the promotion of your music!

@sLeSC
Copy link

sLeSC commented Jul 11, 2020

This is amazing :)! Good work. Thanks for sharing.

@newperson1746
Copy link

newperson1746 commented Jul 26, 2020

This is excellent! I just edited the css lightly (but kinda hackily with negative margin sizes) to give an exact 1:1 match to youtube with the Source Sans Pro font and some spacing corrections.

It'll be a one to one perfect match under the following conditions:

  • rendered at 1920x1080
  • Cover art aspect ratio= 1:1

I'm sure this could be made resolution independent by rewriting the pixel units with device independent ones, but 1080p is fine for me. I might do so later but it works for now.
Take a look here

Feel free to incorporate this!

Final published result on YouTube

@iamyukihiro
Copy link

iamyukihiro commented Jan 18, 2024

Thanks to you!
I was able to submit my music to YouTube.

It helped me a lot because I was having trouble dealing with the GUI tools!

https://www.youtube.com/watch?list=PLdOiVlQeqzOYg5rYHCey58yWRWMlTGps2&v=5GFcbVNA10c

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment