# How to Celebrate Your Code's Birthday

> Recently XRender turned 3 years old. I had played with gource and ffmpeg before, thinking I could use these two libraries to play the journey of her open source as a story.

- Published: 2022-07-09
- Author: Tw93
- HTML: https://tw93.fun/en/2022-07-09/code.html
- Chinese original: https://tw93.fun/2022-07-09/code.md
- All posts: https://tw93.fun/en/posts.md

---

Recently XRender turned 3 years old. I had played with gource and ffmpeg before, thinking I could use these two libraries to play the journey of her open source as a story.

{::nomarkdown}
<div class="video-container">
<iframe width="1920" height="1080" src="https://www.youtube.com/embed/pDWNb2ltJQE" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
</div>
{:/nomarkdown}

*Best watched fullscreen with headphones. There's a real sense of watching the clouds part to reveal the moon — for engineers, it feels like watching the story of a project unfold like a movie.*

### Very simple, you can also try

1. Preparation work, install [gource](https://github.com/acaudwell/Gource) and [ffmpeg](https://ffmpeg.org/). The former is used for visualizing commit logs, and the latter is used for video processing. To make gource support Chinese fonts, Homebrew installation may be very slow. Try this [acceleration address](https://zhuanlan.zhihu.com/p/111014448) for domestic mirroring.

```bash
// Install
brew install gource
brew install ffmpeg

// Let gource support Chinese fonts
rm /usr/local/var/homebrew/linked/gource/share/gource/fonts/FreeSans.ttf
ln -s /System/Library/Fonts/Hiragino\ Sans\ GB.ttc /usr/local/var/homebrew/linked/gource/share/gource/fonts/FreeSans.ttf
```

2. Find a git-managed project you like the most, enter the root directory of the local folder via command line, copy the following command and press Enter, and you can see the effect and generate the video.

```bash
gource \
--title "Title" \
--seconds-per-day 0.1 \
-1200x675 \
--high-dpi \
--multi-sampling \
--background-colour 000000 \
--dir-colour 62C454 \
--file-font-size 12 \
--font-size 24 \
--dir-font-size 14 \
--user-font-size 18 \
--auto-skip-seconds 0.2 \
--stop-at-end \
--highlight-users \
--highlight-dirs \
--file-extension-fallback \
--file-idle-time 0 \
--max-user-speed 200 \
--filename-time 2 \
--highlight-colour F5BE4F \
--date-format "%Y-%m-%d" \
--output-framerate 30 \
--output-ppm-stream - \
| ffmpeg -y -r 30 -f image2pipe -vcodec ppm -i - -vcodec libx264 -preset ultrafast -crf 1 -threads 0 -bf 0 movie.mp4

```

3. An engaging video needs a punchy soundtrack, like [sound.mp3](https://tw93.fun/files/audios/sound.mp3). Download it to the root directory of your project, and you can use avconv (or ffmpeg) to merge the audio track with the video:

```bash
ffmpeg -i movie.mp4 -i sound.mp3 -map 0 -map 1:a -c:v copy -shortest -vcodec libx264 -crf 24 output.mp4
```

4. Anything tracked by Git works — not just open source repos. Because it runs purely locally, your proprietary work code works just fine too. Give it a spin.
