Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Convert audio track/album to YouTube video

youtube-album

A recipe to prepare audio file(s) for YouTube upload. Video will be a slideshow of images on repeat.

Requires: imagemagick ffmpeg

  1. Convert images to required size. Here I assume .png files and output to png/ folder. See http://www.imagemagick.org/Usage/crop/#extent

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

  1. Generate video out of pngs. Here each image is shown for 20 seconds. See https://trac.ffmpeg.org/wiki/Slideshow and https://en.wikibooks.org/wiki/FFMPEG_An_Intermediate_Guide/image_sequence#Filename_patterns

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

  1. Concatenate audio files. See https://trac.ffmpeg.org/wiki/Concatenate
printf "file '%s'\n" ./*.flac > files.txt
ffmpeg -f concat -safe 0 -i files.txt files.flac
  1. Concatenate png video enough times to cover audio duration. See http://superuser.com/a/1116107/55867 for rationale.
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
  1. Create YouTube video using acceptable encoding settings. See https://www.virag.si/2015/06/encoding-videos-for-youtube-with-ffmpeg/

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

  1. Generate a YouTube track listing to copy-paste in the video description.

./youtube-listing.sh *.flac

#!/bin/bash
# Show album track list in YouTube-friendly format including
# clickable track offsets.
#
# Only works with .flac atm :-(
#
# Requires: metaflac sox
start=0
for f in "$@"
do
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")
done
@infojunkie

This comment has been minimized.

Copy link
Owner Author

infojunkie commented Aug 22, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.