Created
June 30, 2025 22:00
-
-
Save Cdaprod/f9177625a6b1f131f0a0a22f4dbafbcc to your computer and use it in GitHub Desktop.
Blender-in-Docker “Factory-Startup” one-liner that procedurally creates a scene (plane textured with a phone-screen video, sun light, animated camera with Bézier easing), then headlessly renders the result to an H.264 MP4—no pre-existing .blend required. Ideal as a reproducible, copy-paste gist for anyone needing quick 3-D perspective moves on v…
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
docker run --rm -i -v "$PWD":/w linuxserver/blender:4.4.3 \ | |
blender --factory-startup -b --python - <<'PY' | |
import bpy, math, os | |
vid = "/w/phone_screen.mp4" # <<< your vertical video | |
assert os.path.exists(vid), "Video missing" | |
# ------------------------------------------------------ build objects | |
bpy.ops.mesh.primitive_plane_add(size=2) | |
plane = bpy.context.object | |
mat = bpy.data.materials.new("PhoneVidMat") | |
mat.use_nodes = True | |
nodes, links = mat.node_tree.nodes, mat.node_tree.links | |
bsdf = nodes["Principled BSDF"] | |
tex = nodes.new("ShaderNodeTexImage") | |
tex.image = bpy.data.images.load(vid) | |
tex.image.source = 'MOVIE' # <-- key line | |
tex.image_user.use_auto_refresh = True # update each frame | |
links.new(tex.outputs["Color"], bsdf.inputs["Base Color"]) | |
plane.data.materials.append(mat) | |
# ------------------------------------------------------ camera + light | |
cam_data = bpy.data.cameras.new("Cam") | |
cam = bpy.data.objects.new("Cam", cam_data) | |
bpy.context.collection.objects.link(cam) | |
cam.location, cam.rotation_euler = (0, -4, 2), (math.radians(70),0,0) | |
bpy.context.scene.camera = cam | |
bpy.ops.object.light_add(type='SUN', location=(0,-2,4)) | |
# ------------------------------------------------------ quick pan anim | |
for f in range(0,240): | |
bpy.context.scene.frame_set(f) | |
cam.location.x = math.sin(f*0.02)*0.5 | |
cam.keyframe_insert("location", index=0) | |
for fc in cam.animation_data.action.fcurves: | |
for kp in fc.keyframe_points: | |
kp.interpolation, kp.easing = 'BEZIER', 'EASE_IN_OUT' | |
# ------------------------------------------------------ render | |
sc = bpy.context.scene | |
sc.frame_start, sc.frame_end = 0, 239 | |
sc.render.image_settings.file_format = 'FFMPEG' | |
sc.render.ffmpeg.codec = 'H264' | |
sc.render.ffmpeg.format = 'MPEG4' | |
sc.render.filepath = "/w/out.mp4" | |
bpy.ops.render.render(animation=True) | |
PY |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment