|ts_min=1352261778000, # "from" timestamp..|
|ts_max=1352262378000, # .."to" timestamp|
|frames=20, # number of images in the video. eg 200 frames for a video at 20 frames per seconds = 10 seconds of video|
|output_prefix="/path/to/output/dir/frame_", # path where to write the png. images will be prefixed with "frame_"|
|output_format=".png" # you probably want to leave png here|
|# not tested - of course you need to change this to your settings|
|# here this will generate a 20 frame/sec video of 1024x1024 pixels. Not standard for a video, but computers can deal with it :)|
|# the duration of the video is controlled by the number of images. ffmpeg will automatically stop when it reaches the end.|
|# frame_%d.png will count from 1 to N|
|# frame_%02d.png will count from 01 to N|
|# frame_%03d.png will count from 001 to N.. you get the point|
|ffmpeg -r 20 -f image2 -i /path/to/output/dir/frame_%d.png -y -s 1024x1024 out.mp4|
|# videomaker assumes each node has a "timestamp" numeric that can be compared|
|def videomaker(ts_min, ts_max, frames, output_prefix, output_format):|
|length = ts_max - ts_min # duration between min and max. these can Integers or Double - just use the same unit everywhere|
|interval = length / float(frames) # time interval between each frame|
|t = ts_min # set the cursor to the beginning|
|for i in range(0, frames): # let's start to count from image 0 to image FRAMES|
|t += i * interval|
|setVisible(g.filter(timestamp < t)) # filter using the "timestamp" node attribute. We keep nodes *before* the time cursor|
|exportGraph("%s%s%s" % (output_prefix, i, output_format)) # export. maybe put more parameters here?|
Okay so I tried it in production. It works! png compress well ("clean" images, good compression ratio in mp4)
Anyway, here are some explanations:
It is not easy to create a generic plugin, because I think most people may want to do something between each iteration.
It should be possible, anyway, to have a better version of videomaker with support for callbacks (you would then put your layout etc.. in the callback). I think it is possible in Jython (?).
Thanks Julian for setting us on the right path! I got up and running pretty quickly, but then found a minor but fundamental bug in the time calculation.
See line 7 of videomaker.py. t should be incremented by the interval, not interval * frame number (or t could be assigned t =ts_min + i * interval)
Hoping this helps others!
Hi there. I've been looking for this for a while, thanks for pulling it together!
Any thoughts? help appreciated