madlep.com Julian Doherty

Hitler tries to embed subtitles with FFmpeg on OSX

Last weekend I made Hitler finds out about Operation Fortitude, a “Hitler Reacts” meme video in response to the bungled Operation Fortitude operation in Melbourne. Somehow the video went minorly viral, getting linked from a few news sources.

The effort to actually produce it though, was non-trivial. Being a command line geek, I figured there would be a way to do it using open source. There is: FFmpeg is the tool for the job. However on OSX, this isn’t so straight forward. In theory it should just work once you figure out the right incantation… But it doesn’t.

I got it all working in the end though, and figured I should write up the solution. Pat McKenna had a better idea on how to communicate it.

do it as a “Hitler tries to get ffmpeg to embed subtitles on OS X” video

For the traditionalists, here’s the actual commands to run

brew install ffmpeg --with-libass --with-fontconfig --with-freetype
sudo vim /opt/X11/lib/X11/fontconfig/fonts.conf
  # add `<div>Library/Fonts</div>` as a `<fontconfig>` element in fonts.conf
echo "export FONTCONFIG_PATH=/opt/X11/lib/X11/fontconfig" >> .bash_profile

You can download the original video here, and the example .srt file from this video here.

# this generates a file with the subtitles embedded as a separate stream
# it only saves the text, and doesn't render it to a bitmap in the actual video frames
# so it won't show up when you upload to youtube
# but it runs instantly, so it's useful for previewing timing etc
ffmpeg -i downfall_bunker_scene.mp4 -i subtitles.srt -c:v copy -c:a copy -c:s mov_text preview.mp4
# this renders the actual file. On my 2013 Macbook Pro, it's about 3 minutes to run
ffmpeg -i subtitles.srt subtitles.ass # convert .srt subtitles to .ass format subtitle file
ffmpeg -i downfall_bunker_scene.mp4 -vf "ass=subtitles.ass" output.mp4 # render actual video

Happy memeing. Remember to always meme responsibly. Please be advised that the “Hitler Reacts” meme is severely past it’s use-by date, so only use when absolutely necessary (as an ironic response to a Godwin’s Law situation is OK).

comments powered by Disqus