Can someone teach me how to load a videoclip and set it to a image texture node using python?

My script loads a video and make a material; then it tries to put that video in an image texture node, also created by python.

My code fragment is below. This is the error that I get:

TypeError: bpy_struct: item.attr = val: ShaderNodeTexImage.image expected a Image type, not MovieClip

Error: Python script failed, check the message in the system console

I understand that image texture nodes can't handle a movieclip; but then what node do I have to use?

    texcord = nodes.new('ShaderNodeTexCoord')
    mapping = nodes.new('ShaderNodeMapping')
    teximg = nodes.new('ShaderNodeTexImage')
    bsdf = nodes.new('ShaderNodeBsdfPrincipled')   
    out = nodes.new('ShaderNodeOutputMaterial')   
    global nombre_vid
    #nodes['Movie Clip'].clip = nombre_vid
    tree.links.new(texcord.outputs[2], mapping.inputs[0])
    tree.links.new(mapping.outputs[0], teximg.inputs[0])
    tree.links.new(teximg.outputs[0], bsdf.inputs[0])
    tree.links.new(bsdf.outputs[0], out.inputs[0])
    bsdf.inputs[7].default_value = mat_roughness
    bsdf.inputs[4].default_value = mat_metallic
    global vid
    teximg.image = vid # vid is the video saved as a global var , not just the name
  • $\begingroup$ What do you want to obtain from the movie clip? $\endgroup$
    – lemon
    Commented Nov 21, 2021 at 16:10
  • $\begingroup$ a particular frame to use as texture for that plane (it is a flipbox). $\endgroup$
    – Lionvids
    Commented Nov 21, 2021 at 18:12
  • $\begingroup$ do you need the movie clip or simply the initial movie file? $\endgroup$
    – lemon
    Commented Nov 21, 2021 at 18:19
  • $\begingroup$ i need the movie clip as texture for the plane.. and i will to select a frame of that movieclip $\endgroup$
    – Lionvids
    Commented Nov 21, 2021 at 19:25

1 Answer 1


TL;DNR: You need to find the image data in bpy.data.images and use it in your assignment to teximage.image.

It is not clear to me what nombre_vid and vid are to you, but if you already have an image called "fire.mp4" loaded into blender, this script will work:

import bpy

object = bpy.context.active_object
assert object
assert object.type == 'MESH'
assert len(object.material_slots) == 0

material = bpy.data.materials.new(name="FIRE")
material.use_nodes = True
tree = material.node_tree
nodes = tree.nodes

texcord = nodes.new('ShaderNodeTexCoord')
mapping = nodes.new('ShaderNodeMapping')
teximage = nodes.new("ShaderNodeTexImage")

bsdf = nodes["Principled BSDF"]
assert bsdf.type == "BSDF_PRINCIPLED"

tree.links.new(texcord.outputs[2], mapping.inputs[0])
tree.links.new(mapping.outputs[0], teximage.inputs[0])
tree.links.new(teximage.outputs[0], bsdf.inputs[0])

teximage.image = bpy.data.images["fire.mp4"]

You need to change the name to the name you're using for the image clip.

If you don't have the file already loaded, you need to load it, of course. Something like this will work instead of the assignment at the end of the script.

teximage.image = bpy.data.images.load(PATH_TO_FILE)

This assumes that the active object is the one you want to add the clip to, and that it doesn't already have a material assigned. Creating the new material creates the BSDF node, so the script finds it, rather than creating another one.

  • $\begingroup$ amazing! it worked!! thanks so much!! $\endgroup$
    – Lionvids
    Commented Nov 21, 2021 at 21:45

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .