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 $@

By Yifan Gu

aka. Frank, aka. 顾屹凡

Leave a comment

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: