Render a single frame for preview when rendering animation

When rendering animations in Blender, it’s often necessary to save one single frame for later use as a preview. Of course, we can do this manually, after finishing the animation rendering, switch to the desired frame and separately render it. However, with the Blender Python API, we can organize the automatic saving of the desired frame during the animation render.

At first, to save a separate frame as image, let’s add a “Viewer” node in the “Compositor” window. The animation stream goes to the main “Output” node, and through the “Viewer” node we can access separate frames without interrupting the animation rendering process.

Open the “Compositor” area and add a “Viewer” node (shift+a – Output – Viewer). Link its “Image” input with the “Image” output of the “Render Layers” node.

Now open the “Text Editor” area and import the “bpy” module – the main Blender Python APY module. Aalso import the “os” module, which we will need to specify the path to save the frame for the preview image.

Set the frame number that will be saved for the preview:

And define a function that will save a frame from the “Viewer Node” to an image file:

In this function, we check if the currently processed frame number matches the one we set, and if so, we use the “save_render” function to save the output from the “Viewer Node” as an image.

We form the path for saving from the path of the currently opened project, the additional path specified in the “Output” section of the “Output Properties” panel, and simply “preview” as the file name, adding the extension to it.

Now we need to execute our function on every frame when the animation is rendered. To do this, let’s bind our function to the “frame_change_pre” handler:

Let’s execute the script by pressing the button “Run Script” with the arrow and start the animation rendering (ctrl + F12). As a result, we will get an animation clip and a separate “preview” image file made from the desired frame.

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comment
Newest
Oldest Most Voted
Inline Feedbacks
View all comments