Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:CARLA simulator Carla Client Replay File

From Leeroopedia
Knowledge Sources
Domains Simulation, Recording
Last Updated 2026-02-15 00:00 GMT

Overview

Concrete tool for replaying a previously recorded simulation session from a binary log file provided by the CARLA simulator.

Description

The Client.replay_file method instructs the CARLA server to load a recording file and begin replaying it. The server recreates all actors from the recording and applies their recorded transforms and states frame-by-frame. The method provides parameters to control the start time, duration, camera following target, and whether to replay sensor actors.

The replay begins asynchronously after the method returns. The server handles actor spawning, transform application, and cleanup. When the replay reaches the end of the specified duration (or the end of the recording), actors created by the replay are destroyed and the world returns to its pre-replay state.

Setting duration to 0.0 replays the entire recording from the start time to the end. Setting follow_id to 0 disables camera following. The replay_sensors flag, when enabled, recreates sensor actors (cameras, LiDAR, etc.) that were present in the original recording, allowing sensor data to be regenerated during replay.

Usage

Call this method after inspecting a recording file to identify the time ranges and actor IDs of interest. Use show_recorder_file_info first to discover actor IDs for the follow_id parameter and to determine appropriate start_time and duration values for targeted replay.

Code Reference

Source Location

  • Repository: CARLA
  • File: PythonAPI/carla/src/Client.cpp:L209, LibCarla/source/carla/client/Client.h:L141-144

Signature

Client.replay_file(filename: str, start_time: float, duration: float, follow_id: int, replay_sensors: bool = False) -> str

Import

import carla

I/O Contract

Inputs

Name Type Required Description
filename str Yes Path or name of the recording file to replay. If relative, the server searches its default recording directory.
start_time float Yes Time in seconds from the beginning of the recording at which to start replay. Use 0.0 to start from the beginning.
duration float Yes Duration in seconds to replay. Use 0.0 to replay the entire recording from the start time to the end.
follow_id int Yes Actor ID for the spectator camera to follow during replay. Use 0 to disable camera following.
replay_sensors bool No When True, recreates sensor actors from the recording and produces sensor output during replay. Defaults to False.

Outputs

Name Type Description
return str Confirmation string indicating replay has started, including information about the file being replayed.

Usage Examples

Basic Example

import carla
import time

client = carla.Client('localhost', 2000)
client.set_timeout(10.0)

# Replay the entire recording from the beginning
result = client.replay_file("traffic_scenario_01.log", 0.0, 0.0, 0)
print(result)

# Let the replay run
time.sleep(60)

Targeted Replay with Camera Following

import carla
import time

client = carla.Client('localhost', 2000)
client.set_timeout(10.0)

# First, inspect the recording to find actor IDs
info = client.show_recorder_file_info("traffic_scenario_01.log", show_all=False)
print(info)

# Suppose we identified actor ID 42 (a Tesla Model 3) from the info output.
# Replay 20 seconds starting at the 10-second mark, following actor 42.
result = client.replay_file(
    "traffic_scenario_01.log",
    start_time=10.0,
    duration=20.0,
    follow_id=42
)
print(result)

# Slow down playback for detailed inspection
client.set_replayer_time_factor(0.5)

time.sleep(40)  # 20 seconds of sim time at 0.5x = 40 real seconds

Replay with Sensor Regeneration

import carla
import time

client = carla.Client('localhost', 2000)
client.set_timeout(10.0)
world = client.get_world()

# Replay with sensors enabled to regenerate camera/LiDAR data
result = client.replay_file(
    "recorded_with_sensors.log",
    start_time=0.0,
    duration=30.0,
    follow_id=42,
    replay_sensors=True
)
print(result)

# Sensors from the original recording will produce output during replay.
# You can attach callbacks to process the regenerated sensor data.
# This is useful for testing different perception algorithms on the same scenario.

time.sleep(30)

Collision Investigation Workflow

import carla
import time

client = carla.Client('localhost', 2000)
client.set_timeout(10.0)

filename = "highway_scenario.log"

# Step 1: Find collisions in the recording
collisions = client.show_recorder_collisions(filename, "v", "v")
print("Vehicle-vehicle collisions:")
print(collisions)

# Step 2: Inspect the recording to understand the timeline
info = client.show_recorder_file_info(filename, show_all=False)

# Step 3: Replay the 10 seconds leading up to the collision
# Suppose the collision occurred at t=45.3s involving actor 67
collision_time = 45.3
lead_time = 10.0

result = client.replay_file(
    filename,
    start_time=collision_time - lead_time,
    duration=lead_time + 5.0,  # Include 5 seconds after collision
    follow_id=67
)

# Slow down for detailed analysis
client.set_replayer_time_factor(0.25)

time.sleep(60)  # Watch the slow-motion replay

Related Pages

Implements Principle

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment