# Русскоязычную версию туториала можно найти здесь
How to burn (reconstruct) date and time into a video using Blender? How to start render and saved rendered images with Python? How to deal with time and date in Python? — this tutorial is about these questions.
The result:
You have some video and you want to burn a date and time into this video (the stamp should update in a real-time).
The time and date are known - you can find this info in your file properties:
Let's add this info into the video.
We will use Python and Blender 2.8. You can use older Blender, but the Text object we will use doesn't support font selection in Blender older then 2.8, so let's use 2.8 Beta.
Open Blende Video Editor. Add a text (Add → Text). On the N-panel select font family, color and size.
Open an additional window – Text Editor, create a new file and save it with py format.
The algorithm is:
0. Go from the first to the last frame;
1. in every frame we should change the text to time and date, render this frame and save the result;
2. every 25 frames (if your original video has 25 frames per second) we add to the current time 1 second and reset frames counter to begin to count the next 25 frames.
We will realize it with a code. Insert the next code into the Text Editor:
import bpy from datetime import datetime, timedelta import datetime from time import sleep # Original time and date, in my case - 13.08.2018, 10:50:10 srcTime = datetime.datetime(2018, 8, 13, 10, 50, 10) # year, month, day, hour, minute, second fps = 25 # FPS secFPS = 0 # secFPS will count the number of passed frames. When in reach fps (25 in this example), 1 second will be added to the current time and secFPS will be reset # Going through all frames from the first to the last # bpy.data.scenes['Scene'].frame_end - the number of frames in the scene for i in range(1, bpy.data.scenes['Scene'].frame_end-1): # Did secFPS reached 25? # If didn't reach... if secFPS <= fps-1: # The numeration begins from 0, so we must subtract 1 to have 25 frames instead 26 # ... adding a current time (from srcTime) into the text # using strftime to transform date and time into a proper format (DD.MM.YYYY HH:MM:SS) bpy.data.scenes['Scene'].sequence_editor.sequences_all['Text'].text = srcTime.strftime("%d.%m.%Y %H:%M:%S") # render bpy.ops.render.render(use_viewport=True) # save the result (with the unique name "file + number of the current frame + extension" # I launch this script in GNU/Linux, in other systems the path can starts from C:\ or something like this bpy.data.images["Render Result"].save_render("/tmp/file"+str(i)+".png") # add 1 to the frames counter secFPS = secFPS + 1 # if DID reach: else: # add 1 second to the original time srcTime = srcTime + timedelta(seconds=1) # Add a current time (increased in 1 second) to the text bpy.data.scenes['Scene'].sequence_editor.sequences_all['Text'].text = srcTime.strftime("%d.%m.%Y %H:%M:%S") # render bpy.ops.render.render(use_viewport=True) # save the result bpy.data.images["Render Result"].save_render("/tmp/file"+str(i)+".png") # reset the counter secFPS = 0
Press Run Script. Blender will create an image sequence with timestamp. Now you can add it into the original video in Blender Video Editor.
© Denis Skiba aka Mapper720
16.04.2019