Making an album sampler video on the command line

March 31st, 2015. Tagged: ffmpeg, Music, tools

Here's a video I made to raise awareness about Anaconda Limousine's first album (where I play guitar and co-wrote 1 song): https://www.youtube.com/watch?v=0LavyKbSuvI. This is a post that explains how it was made so if anyone wants to made a similar one, they can have something to step on.

Turns out videos like this are called "album sampler" and there are quite a few of those

Input and goals

You start with:

  1. an image, the album cover
  2. all the songs, say in WAV format

The goal is to create a video that has the image as a background and also the title of each song. The audio for the video is 1 minute of each song starting somewhere from the middle. When you click each title, the video jumps forward to the part of the video that has this song as a background. The last step must be done manually in youtube using the annotation feature but all the rest is command-line.

Here's what the end result should look like (annotations not working in Firefox)

Prerequisites

I'm assuming an out-of-the-box Mac. You're on your own on other OSs.

You will need:

  1. Homebrew (to install the other pre-requisites)
  2. ImageMagick (for some light image manipulation)
  3. Sox (cutting pieces of songs and fade in/out)
  4. ffmpeg (to make the video)

Installing 'brew:

$ ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

ImageMagick (install and test):

$ brew install imagemagick

$ convert -version
Version: ImageMagick 6.9.0-10 Q16 x86_64 2015-03-08 http://www.imagemagick.org
Copyright: Copyright (C) 1999-2015 ImageMagick Studio LLC

Sox:

$ brew install sox

$ sox -h

ffmpeg:

$ brew install ffmpeg

$ ffmpeg -version
ffmpeg version 2.6.1 Copyright (c) 2000-2015 the FFmpeg developers

The image

Starting with a cover image, scanned from the CD if you don't have the original, The CDs are pretty square:

anaconda

Let's use imagemagick to make it more video-dimensions friendly, meaning 16:9 ratio. My image happened to be 1200px, so keeping the height 1200px and the width becomes 1200 * 16 / 9 = 2133

We'll have the CD cover still in the center and fill the rest of the image with blackness:

# 1200x1200 to 16:9 ratio with black background
$ convert anaconda.jpg -background black -gravity center -extent 2133x1200 anaconda2.jpg

Result:

anaconda-16_9

After some manual typing of the track names (in Preview app) we get:

anaconda2

Not the prettiest, but it will have to do.

Audio

Say I have all the 9 wav files, ripped from the CD, in a ./wav directory. I need a loop that takes each file in this directory and runs it through Sox. In the past I've used ffmpeg to cut pieces of audio files, but turns out Sox can do it too and the best part is - it can also fade in and fade out so the previews are not abruptly cut.

Here's the loop:

$ i = 1; for f in wav/*; do sox "$f" "out/$((i++)).wav" trim 0:30.0 60 fade h 0:3 0 0:4; done

Now in ./out directory I have files 1.wav, 2.wav and so on... Each of these is a 1-minute slice, starting from the 30th second of the song. It fades in for 3 seconds and starts to fade out 4 seconds before the end of the one-minute piece.

Last audio step: make one file that is a concatenation of all 9 pieces:

$ sox out/1.wav out/2.wav out/3.wav out/4.wav out/5.wav out/6.wav out/7.wav out/8.wav out/9.wav all.wav

Video

The last step before uploading to youtube is to take the static image (anaconda2.jpg) and the background audio (all.wav) and make a video with ffmpeg:

$ ffmpeg -loop 1 -i anaconda2.jpg -i all.wav -r 1 -shortest anaconda.avi

That's all folks - the result is anaconda.avi ready for youtube and the millions of fans hungry for new music.

YouTube

After you upload the video, you have "Annotations" option, which doesn't work in Firefox, boo-hooo!

There are 5 ways to annotate, the one I liked the most is called "Spotlight".

Annotations can show up and then disapear, but you don't want that, so you make'em last throughout the video.

Make them transparent.

Make them link to the same video (0LavyKbSuvI in my case) and have the second song (link, annotation) go to minute 1 of the video, the next one to minute 2 and so on.

A little trick many people oversee is to make the first track go to 0:01 (1 second in), as opposed to the very beginning, because clicks on that link reload the video page otherwise.

Screen Shot 2015-03-31 at 12.35.59 AM

Thanks for reading!

... and happy album sampling!

Comments? Feedback? Find me on Twitter, Mastodon, Bluesky, LinkedIn, Threads