shpindler
shpindler

Reputation: 387

Generating a video with a transparent black square on the BG

I need to get video with scale-in and scale-out animations in Nuke but also I want the black square on the background to be transparent however it isn't by default. How can I make it transparent (alpha channel with 0 value)?

This is my code:

import nuke

projset = nuke.Root()
projset["format"].setValue("HD_1080")

content = nuke.createNode("Read")
content["file"].fromUserText("input.jpeg")
result = nuke.nodes.Transform()
result.setInput(0, content)

result["center"].setValue(result.width() / 2, 0)
result["center"].setValue(result.height() / 2, 1)

scale = result["scale"]
scale.setAnimated()
for value, time in (
    (0, 0),
    (1, 20),
    (1, 40),
    (0, 60),
):
    scale.setValue(value, time=time)

output = nuke.nodes.Write(file="output.mov")
output.setInput(0, result)

nuke.render(output)

Upvotes: 1

Views: 217

Answers (1)

Andy Jazz
Andy Jazz

Reputation: 58563

To create a semi-transparent square use a Constant and Premult nodes:

import nuke

constant = nuke.createNode("Constant")
constant["channels"].setValue("rgba")
constant["format"].setValue("square_256")
nuke.createNode('Premult')
nukescripts.connect_selected_to_viewer(0)

for node in nuke.allNodes():
    if node.Class() == "Constant":
        nuke.toNode('Constant1')['color'].setValue( [0, 0, 0, 0.5] )

If you need to output a semi-transparent rectangle as a general background, however, you have to use Apple ProRes 4x4 codec with alpha channel.

Upvotes: 0

Related Questions