[LAU] Generate "automagic" music videos with ffmpeg & friends

Will Godfrey willgodfrey at musically.me.uk
Thu Oct 20 15:50:43 UTC 2016


On Thu, 20 Oct 2016 14:33:19 +0100
Yassin Philip <philcm at gnu.org> wrote:

> Hi Listers!
> 
> Here is a little tooly that I made that may be be of any use to you guys ;
> 
> Today, if you want to publish a song, pretty soon they're going to ask 
> your for "the video". But sometimes you don't have the time / money to 
> do it. Heck, it's a job. The "Lost Week" video 
> <https://www.youtube.com/watch?v=O27yC-qLlMM> took me like a (big. Huge) 
> week to put together, not counting shooting time. BTW it was edited in 
> KDEnlive, but since No Sister 
> <https://www.youtube.com/watch?v=7EH9jSnYAGI> (and my Why, Phil show 
> <https://www.youtube.com/watch?v=2zZO7-wo2_o> and all) I use Blender for 
> that kind of things now.
> 
> Back on topic : You don't have time to put together a proper video for 
> your shiny new because you have a life and recording the song already 
> took the best of it lately.
> 
> Here is a script 
> <https://github.com/xaccrocheur/kituu/blob/master/scripts/px-video-maker.sh> 
> to quickly generate a cool-looking music video 
> <https://www.youtube.com/watch?v=t-u18CbdjBE>, given the sound file, the 
> cover artwork image and an optional ending bit :
> 
> #!/usr/bin/env bash
> 
> FILE_PATH="$1"
> FFMPEG="ffmpeg"
> ARTIST="$2"
> ALBUM="$3"
> COVER_FILE_PATH="$4"
> EFFECT="$5"
> 
> if [ "$#" -ne 5 ]; then
>      echo "Usage: $0 [audio file path] 'artist name' 'album name' 
> [artwork image file path] [point|line|p2p|cline]"
>      exit
> fi
> 
> convert -resize 1280x720 "${COVER_FILE_PATH}" -background none -gravity 
> center -extent 1280x720 "${COVER_FILE_PATH}.jpg"
> 
> $FFMPEG -y -i "${FILE_PATH}" -loop 1 -i "${COVER_FILE_PATH}.jpg" 
> -filter_complex "[0:a] 
> showwaves=s=1280x310:mode=${EFFECT}:r=25,colorkey=0x000000:0.1:0.5[wave];[1:v][wave] 
> overlay=y=H-h:eval=init[canvas];[canvas]drawtext=fontfile='Jura-Book.ttf':fontsize=60:text='${ARTIST}':x=30:y=(h-70-text_h*2.5):fontcolor=white:shadowy=2:shadowx=2:shadowcolor=black,drawtext=fontfile='Jura-Book.ttf':fontsize=72:text='${ALBUM}':x=20:y=(h-70-text_h):fontcolor=ff6600:shadowy=2:shadowx=2:shadowcolor=black" 
> -shortest -codec:v libx264 -crf 18 -preset fast -codec:a aac -strict -2 
> -b:a 192k "${FILE_PATH}-composite.mp4"
> 
> if [[ -e "end.mp4" ]]; then
>      $FFMPEG -y -i "${FILE_PATH}-composite.mp4" -i "end.mp4" 
> -filter_complex "[0:0] [0:1] [1:0] [1:1] concat=n=2:v=1:a=1 [v] [a]" 
> -map "[v]" -map "[a]" "${ARTIST}-${ALBUM}.mp4"
> 
>      rm -rf "${FILE_PATH}-composite.mp4"
> else
>      mv "${FILE_PATH}-composite.mp4" "${ARTIST}-${ALBUM}.mp4"
> fi
> 
> rm -rf "${COVER_FILE_PATH}.jpg"
> 
> echo -e "
> ################################################
> DONE : ${ARTIST}-${ALBUM}.mp4"
> 
> This will
> 
>   * Take the (PNG) cover, and center it inside a 1280x720 (AKA 720p)
>     pixels video ;
>   * Generate a "wave" of the (WAV) sound file ;
>   * Print "Artist" in Orange, And then "Title" in White, below, slightly
>     bigger and offset to the left ;
>   * Merge the 3 together ;
>   * If there exists a file named "end.mp4" in the directory, append it
>     to the final video ;
>   * Clean up everything, and produce a file named "Artist-Title.mp4" in
>     720p.
> 
> Notes:
> 
>   * This script depends on the ffmpeg and imagemagick packages
>   * The last argument is the style of the dancing waveform, take a short
>     audio file to experiment with all 4 of them
>   * The "end.mp4" file is optional, it's there if you want an ending
>     credit / legal / whatever bit, or a nice fade out, anything. It's
>     scaled to fit.
>   * If there is a "Jura-Book.ttf" font file in the directory from which
>     the script is invoked, it will be used, otherwise your default serif
>     font will be.
> 
> With it, you can make that kind of music video 
> <https://www.youtube.com/watch?v=t-u18CbdjBE> ; hope it's useful, cheers 
> everybody, keep on rocking it!
> 
> 
> yPhil
> 
I like the idea... lots! Thanks. I must find time to try it out.

-- 
Will J Godfrey
http://www.musically.me.uk
Say you have a poem and I have a tune.
Exchange them and we can both have a poem, a tune, and a song.


More information about the Linux-audio-user mailing list