Skip to content

Instantly share code, notes, and snippets.

@showa-yojyo
Last active July 27, 2024 13:39
Show Gist options
  • Save showa-yojyo/da8569814f71628491f10b6b6019d2f7 to your computer and use it in GitHub Desktop.
Save showa-yojyo/da8569814f71628491f10b6b6019d2f7 to your computer and use it in GitHub Desktop.
図書館逃避行用 Makefile RC
# Makefile for 図書館逃避行
# Variables supplied from the command line or another Makefile, by `make -f
# Makefile.another`.
TITLE ?= 東京都ダミー区ダミー図書館
OUTPUT ?= ./a.mp4
INKSCAPE ?= inkscape
FFMPEG ?= ffmpeg
CONCAT_TOOL ?= video-concat-xfade
# You must explicitly set this variable:
SVG_TEMPLATE ?= /path/to/video-title-template.svg
SHELL := /bin/bash
# TODO: overridable or internal?
BUILDDIR := ./build
SRCDIR := ./src
# Internal variables
concat-audio := $(BUILDDIR)/audio-only.m4a
concat-video := $(BUILDDIR)/video-only.mp4
command-audio := $(BUILDDIR)/audio-command.sh
command-video := $(BUILDDIR)/video-command.sh
image := $(BUILDDIR)/title.png
svg := $(BUILDDIR)/video-title.svg
objects := $(concat-audio) $(concat-video) $(command-audio) $(command-video) $(image) $(svg)
source-videos != ls $(SRCDIR)/*.mp4
.PHONY: help all clean test image svg audio video commands
help:
@echo "Usage:"
@echo " make image TITLE=<title> to make the title image file"
@echo " make all TITLE=<title> OUTPUT=<path> to build all"
clean:
-rm -f $(objects)
# E.g. make image TITLE=東京都渋谷区こもれび大和田図書館
# or
# make image -- if build/svg file exists
image: $(image)
$(image): $(svg)
@$(INKSCAPE) --export-type=png --export-filename=$@ $<
# E.g. make svg TITLE=東京都渋谷区こもれび大和田図書館
svg: $(svg)
$(svg):
@mkdir -p $(@D)
@cp $(SVG_TEMPLATE) $(svg)
@sed -i "s/東京都なんとか図書館/$(TITLE)/" $@
# E.g. make svg TITLE=東京都渋谷区こもれび大和田図書館 OUTPUT=../shibuya-komorebi.mp4
all: $(OUTPUT)
$(OUTPUT): $(concat-audio) $(concat-video)
$(FFMPEG) -y -i $(concat-video) -i $(concat-audio) \
-c:v copy -c:a aac -map 0:v:0 -map 1:a:0 -movflags +faststart $@
# video-concat-xfade is a path
commands: $(command-audio) $(command-video)
$(command-audio) $(command-video)&: $(source-videos) $(image)
$(CONCAT_TOOL) \
--concat-audio-path $(concat-audio) --concat-video-path $(concat-video) \
--command-audio-path $(command-audio) \
--command-video-path $(command-video) \
--overlay-image-path $(image) \
--output $(OUTPUT) $(source-videos)
audio: $(concat-audio)
$(concat-audio): $(command-audio)
$$SHELL $(command-audio)
video: $(concat-video)
$(concat-video): $(command-video) $(image)
$$SHELL $(command-video)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment