2013-07-25

Turn a set of mp3s into static image music videos


I wanted to take a directory full of mp3s, in this case a bunch of Creative Commons Attribution from Kevin MacLeod (http://incompetech.com/music/) and make videos that simply have the artist name and track name, and moreover string many of those videos together into a longer compilation- the Linux bash script to do this follows.

It seems like ffmpeg fails to concatenate after the videos reached an hour in length- I would get a segfault at that point.  The music and video was getting unsynchronized which causes the titles to run longer than the music does, I'll have to look more into that.

Make title image videos from a directory of mp3s:

mkdir output
rm output/*

for i in *mp3;
do
convert -background black -fill white \
          -size 1920x1080  -pointsize 80  -gravity center \
        label:"Kevin Macleod\n\n`echo $i | sed s/.mp3//`"     output/"$i.png"

# TBD replace with ffmpeg
avconv -loop 1 -r 1 -i output/"$i.png" -c:v libx264  -i "$i" -c:a aac -strict experimental -shortest output/"$i.mp4"

done

Then concatenate into one long video (thanks to https://trac.ffmpeg.org/wiki/How%20to%20concatenate%20(join,%20merge)%20media%20files)

rm all_videos.txt
for i in *mp4;
do
  echo $i
  echo "file '$i'" >> all_videos.txt
done


mkdir output
ffmpeg -f concat -i all_videos.txt -c copy output/kevin_macleod_1.mp4

No comments: