YouTube is a great way to quickly disseminate obscure, long-tail music albums that carry cultural significance. As long as you remain under the radar of our friends at the music labels, of course :wink:

Here’s a recipe to prepare audio files for YouTube upload. The video is a looping slideshow of the images contained in the album’s artwork. Here’s a couple of examples of this recipe’s output:

Requires: imagemagick ffmpeg metaflac sox

for f in *.png; do convert "$f" -resize 800x600 -gravity center -background black -extent 800x600 png/"$f".png; done

  • If you have just one cover image to show, and you want one video file per track, you can take the following shortcut:

for f in *.flac; do ffmpeg -loop 1 -i cover.png -i "$f" -shortest -codec:v libx264 -crf 21 -bf 2 -flags +cgop -pix_fmt yuv420p -codec:a aac -strict -2 -b:a 384k -r:a 48000 -movflags faststart "${f/.flac/.mp4}"; done

Otherwise, read on:

ffmpeg -framerate 1/20 -pattern_type glob -i "png/*.png" -c:v libx264 -vf "fps=25,format=yuv420p" png.mp4

printf "file '%s'\n" ./*.flac > files.txt
ffmpeg -f concat -safe 0 -i files.txt files.flac
for i in {1..10}; do printf "file '%s'\n" png.mp4 >> pngs.txt; done
ffmpeg -f concat -safe 0 -i pngs.txt -c copy pngs.mp4

ffmpeg -i pngs.mp4 -i files.flac -shortest -codec:v libx264 -crf 21 -bf 2 -flags +cgop -pix_fmt yuv420p -codec:a aac -strict -2 -b:a 384k -r:a 48000 -movflags faststart youtube.mp4

  • Generate a YouTube track listing to copy-paste in the video description:

# Show album track list in YouTube-friendly format including
# clickable track offsets.
# Only works with .flac atm :-(
# Requires: metaflac sox

for f in "$@"
        offset=$(date -u -d "0 $start sec" +"%H:%M:%S")
        title=$(metaflac "$f" --show-tag=TITLE | sed s/.*=//g)
        trackno=$(metaflac "$f" --show-tag=TRACKNUMBER | sed s/.*=//g)
        echo "$offset" "$trackno" "$title"
        end=$(soxi -D "$f")
        start=$(bc -l <<< "$start + $end")

Originally published as a GitHub gist.