Skip to content

Commit

Permalink
Blender sequencing pipeline (#111)
Browse files Browse the repository at this point in the history
* Added blender sequencer pipeline to devops folder. closes #107

* added blender rendering pipeline to devops folder
  • Loading branch information
Helveg committed Sep 25, 2020
1 parent 1e99ab8 commit 8caca2d
Show file tree
Hide file tree
Showing 4 changed files with 111 additions and 0 deletions.
21 changes: 21 additions & 0 deletions devops/blender-pipe/jrender.slurm
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/bin/bash -l
#SBATCH --job-name="Blender"
#SBATCH --mail-type=ALL
#SBATCH --time=01:00:00
#SBATCH --nodes=25
#SBATCH --ntasks-per-core=1
#SBATCH --ntasks-per-node=24
#SBATCH --cpus-per-task=1
#SBATCH --partition=normal
#SBATCH --constraint=mc
#SBATCH --hint=nomultithread

export OMP_NUM_THREADS=$SLURM_CPUS_PER_TASK

module swap gcc/8.3.0 gcc/9.3.0
module load daint-mc
module load cray-python/3.8.2.1
module load PyExtensions/python3-CrayGNU-20.08
module load h5py/2.10.0-CrayGNU-20.08-python3-parallel

srun python render.py $1 $2
17 changes: 17 additions & 0 deletions devops/blender-pipe/jsequence.slurm
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/bin/bash -l
#SBATCH --job-name="Render Blender"
#SBATCH --mail-type=ALL
#SBATCH --mail-user=robin.deschepper93@gmail.com
#SBATCH --time=00:15:00
#SBATCH --nodes=1
#SBATCH --ntasks-per-core=1
#SBATCH --ntasks-per-node=1
#SBATCH --cpus-per-task=1
#SBATCH --partition=normal
#SBATCH --constraint=mc
#SBATCH --hint=nomultithread

export OMP_NUM_THREADS=$SLURM_CPUS_PER_TASK

source $HOME/load_blender.sh
srun blender-2.91.0-cacd57b67a15-linux64/blender -b $1 -E CYCLES -P render.py -- $2
38 changes: 38 additions & 0 deletions devops/blender-pipe/render.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import mpi4py.MPI, os, sys, subprocess

rank = mpi4py.MPI.COMM_WORLD.rank + 1
size = mpi4py.MPI.COMM_WORLD.size
f = sys.argv[1]
o = sys.argv[2]
e = "CYCLES" if len(sys.argv) < 4 or sys.argv[3] != "EEVEE" else "BLENDER_EEVEE"
if o[-1] != "/":
o += "/"

if rank == 1:
from pathlib import Path

op = Path(o)
print("pathinfo:", op.parts, len(op.parts), op.parts[:-1])
if len(op.parts) > 1:
Path(os.path.join(*op.parts[:-1])).mkdir(parents=True, exist_ok=True)
op.mkdir(exist_ok=False)

print(f"Starting blender {e} job")

subprocess.check_call(
[
"blender-2.90.0-linux64/blender",
"-b",
f,
"-E",
e,
"-o",
o,
"-s",
rank,
"-j",
size,
"-a",
]
)
mpi4py.MPI.COMM_WORLD.Barrier()
35 changes: 35 additions & 0 deletions devops/blender-pipe/sequence.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import os, sys, bpy, glob

scene = bpy.context.scene
args = sys.argv[sys.argv.index("--") + 1 :]
path = os.path.abspath(args[0])
if path[-1] != "/":
path += "/"
print("output path:", path)
scene.render.filepath = path
bpy.context.scene.render.image_settings.file_format = "FFMPEG"
preset_script = os.path.join(sys.prefix, "../scripts/presets/ffmpeg/h264_in_MP4.py")
exec(open(preset_script).read())

files = [f.split("/")[-1] for f in sorted(glob.glob(os.path.join(path, "*.png")))]
scene.sequence_editor_create()

for seq in scene.sequence_editor.sequences:
if seq["created_by_bsb"]:
scene.sequence_editor.sequences.remove(seq)

start = int(files[0].split("/")[-1].split(".")[0])
seq = scene.sequence_editor.sequences.new_image(
name="FullStrip", filepath=os.path.join(path, files[0]), channel=1, frame_start=start
)
seq["created_by_bsb"] = True
for f in files:
seq.elements.append(f)


bpy.context.scene.frame_start = start
bpy.context.scene.frame_end = start + len(seq.elements) - 1
bpy.context.scene.render.use_compositing = False
bpy.context.scene.render.use_sequencer = True

print(bpy.ops.render.render(animation=True))

0 comments on commit 8caca2d

Please sign in to comment.