|
1 | 1 | import math |
2 | 2 | import argparse |
| 3 | +import subprocess |
3 | 4 | from pathlib import Path |
4 | 5 |
|
5 | 6 | import numpy as np |
|
33 | 34 | ) |
34 | 35 |
|
35 | 36 |
|
| 37 | +def process_video(simulation_duration: float, start_time: float = 0.0): |
| 38 | + cmd = [ |
| 39 | + "ffprobe", |
| 40 | + "-i", |
| 41 | + "talos_run.mp4", |
| 42 | + "-show_entries", |
| 43 | + "format=duration", |
| 44 | + "-v", |
| 45 | + "quiet", |
| 46 | + "-of", |
| 47 | + "csv=p=0", |
| 48 | + ] |
| 49 | + |
| 50 | + out = subprocess.check_output(cmd).decode().strip() |
| 51 | + video_duration = float(out) |
| 52 | + |
| 53 | + ratio = simulation_duration / video_duration |
| 54 | + |
| 55 | + cmd = [ |
| 56 | + "ffmpeg", |
| 57 | + "-ss", |
| 58 | + str(start_time / ratio), |
| 59 | + "-i", |
| 60 | + "talos_run.mp4", |
| 61 | + "-filter:v", |
| 62 | + f"setpts={ratio}*PTS", |
| 63 | + "-r", |
| 64 | + "60", |
| 65 | + "-c:v", |
| 66 | + "libx264", |
| 67 | + "-crf", |
| 68 | + "18", |
| 69 | + "-preset", |
| 70 | + "slow", |
| 71 | + "talos_run_fixed.mp4", |
| 72 | + ] |
| 73 | + |
| 74 | + subprocess.run(cmd, check=True) |
| 75 | + |
| 76 | + |
36 | 77 | def main(): |
37 | 78 | p = argparse.ArgumentParser() |
38 | 79 | p.add_argument("--path-talos-data", type=Path, help="Path to talos_data root") |
@@ -221,6 +262,8 @@ def main(): |
221 | 262 | rf_forces = np.zeros((len(phases), 1)) |
222 | 263 | lf_forces = np.zeros((len(phases), 1)) |
223 | 264 |
|
| 265 | + log_id = pb.startStateLogging(pb.STATE_LOGGING_VIDEO_MP4, "talos_run.mp4") |
| 266 | + |
224 | 267 | # We start the walking phase |
225 | 268 | for k, _ in enumerate(phases[:-2]): |
226 | 269 | # Get the current configuration of the robot from the simulator |
@@ -301,6 +344,10 @@ def main(): |
301 | 344 |
|
302 | 345 | rf_forces[k], lf_forces[k] = simulator.get_contact_forces() |
303 | 346 |
|
| 347 | + pb.stopStateLogging(log_id) |
| 348 | + |
| 349 | + process_video(t[-1], t_init + 2.0) |
| 350 | + |
304 | 351 | if args.plot_results: |
305 | 352 |
|
306 | 353 | zmp_ref_plot = np.zeros((zmp_ref.shape[0], 3)) |
|
0 commit comments