Skip to content

mbivert/mkshort

Repository files navigation

Introduction

mkshort is a small go tool to create short videos containing a diaporama of images with overlayed text, via ffmpeg(1). The input is a text file like this one:

# Specify an audio file with fade-in/out of 4sec both; skip the first 2sec
@2 4 4 BMC19T1VivaldiSeasonsSpring.mp3

:virgin-of-the-rocks-paris.jpg
0.7 3.5
	Here is what seems \\
	to be \\
	a little-known fact \\

...

+0.7 3
	Jesus, the \\
	bottom right child \\
+0.7 5
	Is the only one \\
	looking at the \\
	\textit{Source of Light} \\
	\emoji{face-in-clouds} \\

...

:virgin-of-the-rocks-london.jpg
+0.7 4
	This also holds in the \\
	"London" version of the \\
	painting \\
+0.7 2

The previous .gif was generated with ffmpeg(1) from the .mp4:

$ ffmpeg -y -i virgin-of-the-rocks.mp4 virgin-of-the-rocks-audio.gif

A video with sound is available here or here.

While ffmpeg(1) provides a text overlay filter, it can be limited. Instead, we're using LaTeX (LuaLaTeX) to provide a more complete features set (colored emojis (.pdf), mathematical typesetting, etc.).

A quick man page is available: mkshort(1). An old, semi-automatic awk(1)/sh(1)-based prototype is available in old/prototype.sh. A "Virgin of the rocks" example is provided. Quick help:

$ make help
Available targets:
	mkshort    : build mkshort
	all        : build mkshort; run tests
	clean      : removed compiled files
	tests      : run automated tests
	example    : display the ffmpeg(1) command,
	             build (a bit slow) and play the example.
	install    : install to /bin/ andqq /usr/share/man/man1/
	uninstall  : remove installed files

$ mkshort -help
Usage of mkshort:
  -b string
    	rescale padding color (default "black")
  -c string
    	LaTeX command, splitted on spaces (default "lualatex")
  -d string
    	cache directory (default "/home/mb/.mkshort")
  -e string
    	extension for the compiled text images (default ".png")
  -f string
    	output pixel format (default "yuv420p")
  -h int
    	output height (default 1920)
  -i string
    	text indentation (default "\t")
  -l string
    	shell to run the compiled ffmpeg(1) command (default "/bin/sh")
  -m	Enable/disable faststart (default true)
  -p string
    	LaTeX template (path)
  -r int
    	output framerate (default 30)
  -s float
    	default waiting time between text (default 0.8)
  -t string
    	LaTeX template (string) (default "\\documentclass[preview,convert={density=600,outext=.png,command=\\unexpanded{ {\\convertexe\\space -density \\density\\space\\infile\\space \\ifx\\size\\empty\\else -resize \\size\\fi\\space -quality 90 -trim +repage -background \"rgba(50,50,50,0.5)\" -bordercolor \"rgba(50,50,50,0.5)\" -border 25 -flatten \\outfile} } }]{standalone}\n% Requires lualatex\n\\usepackage{emoji}\n\n\\usepackage{xcolor}\n\\usepackage{amsmath}\n\\begin{document}\n\n\\begin{center}\n\\textcolor{white}{ {{ .text }} }\n\\end{center}\n\\end{document}\n")
  -w int
    	output width (default 1080)
  -x	Compiled command printed, not ran
  -y	Allow automatic output overwrite (default true)