Generate a movie from SUMO

SUMO, the open-source traffic simulation tool, does not have a simple option to output a movie. Using TraCI, the UDP-based control interface for SUMO, you can quickly generate a set of images from your simulation:


import traci
import sys
import subprocess

#change if necessary
PORT = 8816

sumoProcess = subprocess.Popen("C:\\path\\to\\sumo-gui \"C:\\path\\to\\simfile.sumocfg\"", shell=True, stdout=sys.stdout)

print "SUMO Started"

traci.init(PORT)
step = 0
#Please note these numbers are x100 milliseconds only because the SUMO simulation is set to have timesteps of 0.1s - i.e. the numbers are not in time but in timesteps
#Set movie generation end
while step 25000): traci.gui.screenshot("View #0", "..\\figures\\figurepath\\sumovideo\\sumo2Dvideo"+str(step)+".png")
traci.simulationStep()
step += 1

traci.close()

Once this is done, you’ll have a set of images. Just open the first one in Virtualdub Mod, and it will show you all of them as a movie which you can output to the format of your choice – for example .webm.