When we specifying the full path to save the rendered animation, we must correctly set the file extension, which will change depending on the codec chosen for packing animation.
For rendering static images, the output file extension can be easily obtained through the “file_extension” property:
1 2 3 |
print(bpy.context.scene.render.file_extension) # .png |
But this doesn’t work for animation. For video rendering, this property will still return the extension of the file used in temporary frames encoding, and not the final extension of the output video file.
To get exactly the extension with which we want to save the output animation, let’s write a simple function:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
def video_file_extension(): ext = { 'MPEG1': 'mpeg1', 'MPEG2': 'mpeg2', 'MPEG4': 'mp4', 'AVI': 'avi', 'QUICKTIME': 'mov', 'DV': 'dv', 'OGG': 'ogg', 'MKV': 'mkv', 'FLASH': 'flv', 'WEBM': 'webm' } return '.' + ext[bpy.context.scene.render.ffmpeg.format] |
Here, we define a dictionary with the list of all video codec formats supported by Blender and the corresponding file extensions for these formats.
Now we can easily get the output file extension by simply calling thif function:
1 2 3 |
print(video_file_extension()) # .mov |