Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [sumo-user] Time wrap in recording simulation

Hi Michael

Thank you for the reply. I will look into the build in video recording feature.

I'm almost sure the issue is not the with ffmpeg, as the issue is already visible from the screenshots taken. But the ffmpeg command use is:

ffmpeg -r 1  -start_number 0 -i /tmp/sumosim/img%07d.jpg -vframes 3600 -vcodec libx264 -crf 25  -pix_fmt yuv420p -vf "pad=ceil(iw/2)*2:ceil(ih/2)*2" video.mp4

I have put together a small example which exhibits the issue (attached). On my laptop the generated screenshots will sometimes jump back in time, it usually happens once or twice in the first two minutes of the simulation. Running python main.py will create a folder called screenshots and each simulation step (second) it will put a screenshot called img<simulation step>.jpg in this folder.

I am running this on Arch Linux, and I am using the newest Sumo version from AUR (1.2.0-2): https://aur.archlinux.org/packages/sumo/

sumo --version outputs:

Eclipse SUMO Version 1.2.0
 Build features: Linux-5.1.3-arch2-1-ARCH x86_64 GNU 8.3.0 Release Proj GUI GDAL OSG GL2PS SWIG
 Copyright (C) 2001-2019 German Aerospace Center (DLR) and others; https://sumo.dlr.de

Eclipse SUMO Version 1.2.0 is part of SUMO.
This program and the accompanying materials
are made available under the terms of the Eclipse Public License v2.0
which accompanies this distribution, and is available at
http://www.eclipse.org/legal/epl-v20.html
SPDX-License-Identifier: EPL-2.0

Best regards Jakob

On 21/06/2019 14.40, Michael Behrisch wrote:
Hi Jakob,
the problem is not known to me, so please share the ffmpeg call you are
using. Sumo also has a built in video recording feature if you compile
it with ffmpeg headers being present. Just check whether it presents the
option to save an h264 file when saving the screenshot and if so use
that ending to trigger video recording. It is still experimental, though.

Best regards,
Michael

Am 20.06.19 um 10:07 schrieb Jakob Haahr Taankvist:
Hi

I would like to create a video capture of a simulation, which can be run
in real time. To do this I use the Traci screenshot function to make a
screenshot after every step, effectively my script is this:

defrun_simulation():
step =0
whiletraci.simulation.getMinExpectedNumber() >0:
print(f"SIMULATED {step}seconds")
# Compute and set the next signal setting
...
print(traci.gui.screenshot("View #0",
"/tmp/sumosim/img{:07d}-{}.jpg".format(step, datetime.datetime.now())))
traci.simulationStep()
step +=1

I then generate a video using the extracted frames using ffmpeg.

My problem is that sometimes the extracted frame jumps back in time, see
e.g. the attached frames, frame 51 jumps back in time in this case. Am I
doing something wrong? Is there a better way to create a video of a
simulation?

I have not see the issue happen in the GUI. I run the simulation as fast
as possible.

Best regards Jakob Taankvist





_______________________________________________
sumo-user mailing list
sumo-user@xxxxxxxxxxx
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://www.eclipse.org/mailman/listinfo/sumo-user


import time
import os
import sys
# test
# Configuration

# we need to import python modules from the $SUMO_HOME/tools directory
if 'SUMO_HOME' in os.environ:
    tools = os.path.join(os.environ['SUMO_HOME'], 'tools')
    sys.path.append(tools)
else:
    sys.exit("please declare environment variable 'SUMO_HOME'")

from sumolib import checkBinary  # noqa
import traci  # noqa


def run_simulation(screenshot_folder):
    step = 0
    while traci.simulation.getMinExpectedNumber() > 0:

        # It looks like this is what triggers the issure - in the real case we compute a signal setting and the computation time are sometimes very fast and sometimes very slow.
        if step % 10 != 0:
            time.sleep(0.05)
        else:
            time.sleep(0.9)
        traci.gui.screenshot("View #0", os.path.join(screenshot_folder, "img{:07d}.jpg".format(step)))
        traci.simulationStep()
        step += 1


if __name__ == "__main__":
    sumoBinary = checkBinary('sumo-gui')

    traci.start([sumoBinary, "--start", "--quit-on-end", "--seed", "0", "-c", "net.sumocfg"])
    screenshot_folder = "screenshots"
    if not os.path.exists(screenshot_folder):
        os.mkdir(screenshot_folder)
    run_simulation(screenshot_folder)
<?xml version="1.0" encoding="UTF-8"?>

<!-- generated on 2019-06-24T14:27:54 CEST by Eclipse SUMO netedit Version 1.2.0
<configuration xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"; xsi:noNamespaceSchemaLocation="http://sumo.dlr.de/xsd/netconvertConfiguration.xsd";>

    <processing>
        <offset.disable-normalization value="true"/>
    </processing>

    <junctions>
        <no-turnarounds value="true"/>
    </junctions>

</configuration>
-->

<net version="1.1" junctionCornerDetail="5" limitTurnSpeed="5.50" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"; xsi:noNamespaceSchemaLocation="http://sumo.dlr.de/xsd/net_file.xsd";>

    <location netOffset="0.00,0.00" convBoundary="-200.00,50.00,200.00,50.00" origBoundary="10000000000.00,10000000000.00,-10000000000.00,-10000000000.00" projParameter="!"/>

    <edge id="gneE0" from="gneJ0" to="gneJ1" priority="-1">
        <lane id="gneE0_0" index="0" speed="13.89" length="400.00" shape="-200.00,48.40 200.00,48.40"/>
    </edge>

    <junction id="gneJ0" type="dead_end" x="-200.00" y="50.00" incLanes="" intLanes="" shape="-200.00,50.00 -200.00,46.80"/>
    <junction id="gneJ1" type="dead_end" x="200.00" y="50.00" incLanes="gneE0_0" intLanes="" shape="200.00,46.80 200.00,50.00"/>

</net>
<viewsettings>
    <delay value="0"/>
</viewsettings>
<?xml version="1.0" encoding="iso-8859-1"?>
<configuration xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
 xsi:noNamespaceSchemaLocation="http://sumo.dlr.de/xsd/sumoConfiguration.xsd";>
    <input>
        <net-file value="net.net.xml"/>
        <route-files value="routes.xml"/>
    </input>
    <time>
        <begin value="0"/>
        <end value="3600"/>
    </time>
    <gui-settings-file value="net.settings.xml"/>
    <time-to-teleport value="-1"/>
</configuration>
<?xml version="1.0" encoding="UTF-8"?>

<routes xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"; xsi:noNamespaceSchemaLocation="http://sumo.dlr.de/xsd/routes_file.xsd";>
    <flow id="e_n" from="gneE0" to="gneE0" type="DEFAULT_VEHTYPE" probability="0.2"/>
</routes>

Back to the top