Created
April 9, 2025 22:22
-
-
Save Cdaprod/a75afa390f2e13e95ea050f42df69802 to your computer and use it in GitHub Desktop.
Blender & Python HUD after effects template.
This file contains 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
import bpy | |
# Clear default scene | |
bpy.ops.object.select_all(action='SELECT') | |
bpy.ops.object.delete() | |
# ------------------------------- | |
# Load Background CapCut Export | |
# ------------------------------- | |
bg = bpy.ops.import_image.to_plane(files=[{"name":"capcut_bg.mp4"}]) | |
bg_obj = bpy.context.selected_objects[0] | |
bg_obj.scale = (16, 9, 1) # landscape ratio | |
bg_obj.location = (0, 0, 0) | |
# ------------------------------- | |
# Load iPhone Overlay | |
# ------------------------------- | |
bpy.ops.mesh.primitive_plane_add(size=1, location=(-6, 0, 0.01)) | |
overlay = bpy.context.object | |
overlay.scale = (1, 2, 1) # vertical iPhone shape | |
# Apply video texture to the overlay plane | |
mat = bpy.data.materials.new(name="iPhoneVideoMat") | |
mat.use_nodes = True | |
bsdf = mat.node_tree.nodes["Principled BSDF"] | |
mat.node_tree.nodes.remove(bsdf) | |
nodes = mat.node_tree.nodes | |
links = mat.node_tree.links | |
tex = nodes.new("ShaderNodeTexImage") | |
tex.image = bpy.data.images.load("/path/to/iphone_screen.mp4") | |
tex.image.source = 'MOVIE' | |
tex.image_user.frame_duration = 300 # adjust if needed | |
chroma = nodes.new("ShaderNodeKeying") # Chroma Key node | |
chroma.inputs["Key Color"].default_value = (0.0, 1.0, 0.0, 1) # green | |
transp = nodes.new("ShaderNodeBsdfTransparent") | |
mix = nodes.new("ShaderNodeMixShader") | |
output = nodes["Material Output"] | |
# Connect chroma key pipeline | |
links.new(chroma.inputs["Image"], tex.outputs["Color"]) | |
links.new(mix.inputs[0], chroma.outputs["Fac"]) | |
links.new(mix.inputs[1], transp.outputs["BSDF"]) | |
links.new(mix.inputs[2], tex.outputs["Color"]) | |
links.new(output.inputs["Surface"], mix.outputs["Shader"]) | |
overlay.data.materials.append(mat) | |
# ------------------------------- | |
# Apply Skew / Perspective | |
# ------------------------------- | |
overlay.rotation_euler = (0.1, -0.4, 0.2) # Slight skew toward center | |
# ------------------------------- | |
# Setup Camera | |
# ------------------------------- | |
bpy.ops.object.camera_add(location=(0, -12, 0), rotation=(1.57, 0, 0)) | |
cam = bpy.context.object | |
bpy.context.scene.camera = cam | |
# ------------------------------- | |
# Set Render Settings | |
# ------------------------------- | |
scene = bpy.context.scene | |
scene.render.resolution_x = 1920 | |
scene.render.resolution_y = 1080 | |
scene.render.fps = 30 | |
scene.frame_start = 1 | |
scene.frame_end = 300 | |
scene.render.image_settings.file_format = 'FFMPEG' | |
scene.render.ffmpeg.format = 'MPEG4' | |
scene.render.filepath = "/output/final_overlay.mp4" | |
# ------------------------------- | |
# Render Animation | |
# ------------------------------- | |
bpy.ops.render.render(animation=True) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment