Skip to content

Instantly share code, notes, and snippets.

@4np
Last active December 11, 2015 15:38
Show Gist options
  • Save 4np/4621828 to your computer and use it in GitHub Desktop.
Save 4np/4621828 to your computer and use it in GitHub Desktop.
Generate a graph video of a svn project. Requires gource and ffmpeg
# alias for creating a graph video of a git project
g() {
DEFAULT_USER_IMAGE=~/Pictures/avatars/default.png
USER_IMAGE_DIR=~/Pictures/avatars
BRANCH=master
# determine first commit for this branch
FIRST_COMMIT=`git log $BRANCH --reverse --format=%H|head -n 1`
# get the third last commit to have a pretty accurate timestamp
LAST_COMMIT=`git log $BRANCH --format=%H|head -n 3|tail -n 1`
# determine lifetime of this branch
FIRST_STAMP=`git show --format=%at $FIRST_COMMIT|head -n 1`
LAST_STAMP=`git show --format=%at $LAST_COMMIT|head -n 1`
# calculate the number of seconds this branch has lived
SECONDS=$((LAST_STAMP-FIRST_STAMP))
# determine how much seconds should be shown per day
SECONDS_PER_DAY=`echo "scale=2; 12600000/$SECONDS"| bc`
# set miscelaneous options
MISC_OPTIONS="--seconds-per-day $SECONDS_PER_DAY --file-idle-time 0 --git-branch $BRANCH --highlight-user 4np"
if [ ${#@} -lt 1 ]; then
echo 'usage:'
echo 'g videotitle [optional:720p|1080p] [optional:logo image]'
echo 'g "this is my video" /tmp/logo.png'
elif [[ -d ./.git ]]; then
echo "generating commit animation..."
# determine resolution
if [ ${#@} -gt 1 ]
then
if [ $2 == "720p" ]
then
SIZE="-960x720 --font-size 10"
SIZE_FFMPEG="-s 960x720"
else
SIZE="-1920x1080 --font-size 20"
SIZE_FFMPEG="-s 1920x1080"
fi
else
SIZE="-1920x1080 --font-size 20"
SIZE_FFMPEG="-s 1920x1080"
fi
# add a logo?
if [ ${#@} -gt 2 ]
then
LOGO="--logo $3"
else
LOGO=
fi
# add a title
TITLE="--title \""$1"\""
#ffmpeg -y -r 60 -f image2pipe -vcodec ppm -i gource.ppm -vcodec libx264 -preset ultrafast -crf 1 -threads 0 -bf 0 gource.mp4
# generate commit animation
gource --hide filenames,progress,mouse --background 181818 --default-user-image $DEFAULT_USER_IMAGE --user-image-dir $USER_IMAGE_DIR \
--camera-mode track --stop-at-end -s 0.2 -i 63072000 --hide filenames,bloom,progress,mouse $TITLE $LOGO $SIZE $MISC_OPTIONS \
--multi-sampling -r 25 \
-o - | ffmpeg -y -b 3000K -r 25 -f image2pipe -vcodec ppm -i - -vcodec libx264 -vpre slow SIZE_FFMPEG -threads 0 video.mp4
# get the duration of the generated video
FF=$(ffmpeg -i video.mp4 2>&1)
D="${FF#*Duration: }"
DURATION=`echo "${D%%,*}"`
echo "looking for a song with duration $DURATION to mux audio in..."
# mux audio with video
# ffmpeg -y -b 2048k -r 25 -f image2pipe -vcodec ppm -s 1920x1080 -threads 0 -i ~/Music/iTunes/iTunes\ Music/Music/Band\ Of\ Horses/Everything\ All\ The\ Time/04\ The\ Funeral.mp3 -i graph.mp4 graph-with-audio.mp4
#MUSIC=~/Music/iTunes/iTunes\ Media/Music/Band\ Of\ Horses/Everything\ All\ The\ Time/04\ The\ Funeral.mp3
#ffmpeg -i video.mp4 -vcodec copy -i $MUSIC -acodec copy video-with-audio.mov
else
echo `pwd`' is no git repository...'
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment