I need to merge 2 videos in Python Nuke but also I want to merge their audio channels. However Nuke reads and writes only their video with no audio at all after running the code below:
import nuke
content = nuke.createNode("Read")
content["file"].fromUserText("/content.mp4")
bg = nuke.createNode("Read")
bg["file"].fromUserText("/bg.mov")
merged = nuke.nodes.Merge(inputs=[bg, content])
output = nuke.nodes.Write(file="/output.mov", inputs=[merged])
nuke.render(output)
The Foundry NUKE isn't a video editor, it's a compositing package. So, if you need to merge an audio component with a video component, use Audio File
option having a corresponding path (you can read in the same .mov
file or choose a separate audio file).
Here's how your code should look (I used .mov
file with Apple ProRes 4x4 codec):
import nuke
nuke.nodes.Read(file="/Users/swift/Desktop/TESTED.mov", last=1800)
output = nuke.nodes.Write(file="/Users/swift/Desktop/nuke1920.mov",
file_type="mov",
mov64_audiofile="/Users/swift/Desktop/TESTED.mov")
nuke.render(output)
Output pane of Script Editor presents no errors:
Alternatively, if you need to work with audio tools, use NUKE Studio.
P.S.
Take into consideration that Non-Commercial NUKE version supports output resolution not greater than 1920x1080. And Non-Commercial NUKE doesn't support mp4
codec, and a processing of more than 10 nodes for Python scripting.
And one more thing – you're trying to render 2 videos but you're outputting only 3 channels – RGB. Make sure you have an appropriate channel set for A and B streams! I don't know what you're trying to accomplish but you may use a Copy
node instead of Merge
node to render 2 sets of RGBs.