Skip to content

Instantly share code, notes, and snippets.

Last active July 25, 2023 07:14
Show Gist options
  • Save jbilcke/5405777 to your computer and use it in GitHub Desktop.
Save jbilcke/5405777 to your computer and use it in GitHub Desktop.
How to create a video using Gephi + Scripting plugin + ffmpeg
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.
# tip:
# 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?
Copy link

in the script, timestamp is an attribute of the nodes, right? Which attribute is g in g.filter? I'm trying to use this code, but in my graph, the time parameter belongs to the edges (the animation shows the edges being added..), not to the nodes...How can I edit this code to that?
Thanks in advance!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment