Using Makefile for Non-programming Tasks

Make is traditionally used to build artifacts from program source code. It can also be used for other tasks, where you need to “build” something out of a “source-of-truth”.

For example: video-editing. I personally find ffmpeg able to generate better quality compressed videos than FCPX or Premiere Pro, which is especially important if the desired bitrate is low. One of the use cases is this website, which has a video background. It is important to keep the video size as small as possible for video to load in a reasonable amount of time, while maintaining an acceptable quality. FCPX unfortunately cannot do that.

I can use a shell script of course. But it occurred to me that, make is actually the perfect tool for the job, if you treat the master video as the source file, and the resultant compressed videos as the artifacts.

SOURCE = ../render/out.mov
LINES = 1080
BITRATE = 1200k

PHONY: clean all

all: poster.jpg h264.mp4 vp9.webm

clean:
	rm -f poster.jpg h264.mp4 vp9.webm *.mbtree *.log

poster.jpg: $(SOURCE)
	ffmpeg -y -i $< -vf scale=-1\:$(LINES) -vframes 1 $@

h264.mp4: $(SOURCE)
	ffmpeg -y -i $< -vf scale=-1\:$(LINES) -c\:v libx264 -b\:v $(BITRATE) -preset veryslow -an -pass 1 $@
	ffmpeg -y -i $< -vf scale=-1\:$(LINES) -c\:v libx264 -b\:v $(BITRATE) -preset veryslow -an -pass 2 $@

vp9.webm: $(SOURCE)
	ffmpeg -y -i $< -vf scale=-1\:$(LINES) -c\:v libvpx-vp9 -b\:v $(BITRATE) -an -pass 1 -deadline good $@
	ffmpeg -y -i $< -vf scale=-1\:$(LINES) -c\:v libvpx-vp9 -b\:v $(BITRATE) -an -pass 2 -deadline good $@

Leave a comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.