Skip to content

Instantly share code, notes, and snippets.

@Artefact2
Last active October 10, 2017 03:07
Show Gist options
  • Save Artefact2/a7f614631c3ad4355b4c to your computer and use it in GitHub Desktop.
Save Artefact2/a7f614631c3ad4355b4c to your computer and use it in GitHub Desktop.
Blender multithreaded rendering
CHROMASTART=0
CHROMAEND=0
MAINSTART=0
MAINEND=0
NJOBS=8
BATCH=$$(( ($(END) - $(START)) / $(NJOBS) ))
LAST=$$(( $(NJOBS)-1 ))
BLENDFILES=$(wildcard *.blend)
RULES=$(shell seq 0 $(LAST))
CHROMARULES=$(addprefix render/chroma, $(addsuffix .mkv, $(RULES)))
MAINRULES=$(addprefix render/main, $(addsuffix .mkv, $(RULES)))
default:
@echo "Use render/chroma.mkv or youtube.mkv rules."
clean:
rm -Rf source/BL_proxy render/*
upload: youtube.mkv thumb.png
youtube-upload --privacy=private --thumbnail=thumb.png --title=youtube.mkv youtube.mkv
reupload:
youtube-upload --privacy=private --thumbnail=thumb.png --title=youtube.mkv youtube.mkv
render/chroma.txt: Makefile
truncate -s 0 $@
for f in $(notdir $(CHROMARULES)); do echo "file '$$f'" >> $@; done
render/main.txt: Makefile
truncate -s 0 $@
for f in $(notdir $(MAINRULES)); do echo "file '$$f'" >> $@; done
render/chroma.mkv: render/chroma.txt $(CHROMARULES)
nice ffmpeg -y -f concat -i $< -c:v copy -f matroska $@
rm -f $(CHROMARULES)
youtube.mkv: render/main.txt $(MAINRULES) render/session.flac
nice ffmpeg -y -f concat -i render/main.txt -i render/session.flac -map 0:0 -map 1:0 -c:v libx264 -preset medium -crf 18 -c:a copy -f matroska $@
render/chroma%.mkv: $(BLENDFILES)
./renderpart "Chroma Key" $(NJOBS) $@ $(CHROMASTART) $(CHROMAEND)
render/main%.mkv: $(BLENDFILES)
./renderpart "Video Edits" $(NJOBS) $@ $(MAINSTART) $(MAINEND)
.PHONY: default clean upload reupload
#!/usr/bin/env php
<?php
list($me, $scene, $njobs, $output, $start, $end) = $argv;
if($end == 0) die(1);
preg_match('%(?<i>[0-9+])([^0-9]*)$%', $output, $match);
$i = (int)$match['i'];
$len = floor(((float)$end - (float)$start) / (float)$njobs);
$last = (int)((int)$njobs - 1);
$command = sprintf(
'nice blender -noaudio -b %s -S %s -o %s -x 0 -s %d -e %d -a | grep Saving',
escapeshellarg(substr(shell_exec('find . -maxdepth 1 -name "*.blend" | head -n 1'), 0, -1)),
escapeshellarg($scene),
escapeshellarg($output),
$i === 0 ? $start : ($start + $i*$len+1),
$i === $last ? $end : ($start + ($i+1)*$len)
);
echo $command."\n";
passthru($command, $r);
die($r);
@ldo
Copy link

ldo commented Oct 10, 2017

You should use nproc(1) to determine how many processes to run at once.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment