forked from longtao.wu/droboticflow
64 lines
3.3 KiB
Python
64 lines
3.3 KiB
Python
"""Create six tiny generated captures; never reads customer media or credentials."""
|
|
|
|
import argparse
|
|
import hashlib
|
|
import json
|
|
from pathlib import Path
|
|
import shutil
|
|
import subprocess
|
|
|
|
|
|
def make_bundle(output):
|
|
root = Path(output).resolve()
|
|
root.mkdir(parents=True, exist_ok=False, mode=0o700)
|
|
video = root / "generated.mp4"
|
|
subprocess.run(["ffmpeg", "-nostdin", "-hide_banner", "-loglevel", "error",
|
|
"-f", "lavfi", "-i", "testsrc2=size=96x64:rate=4:duration=2",
|
|
"-c:v", "libx264", "-pix_fmt", "yuv420p", str(video)], check=True)
|
|
samples, assets = [], []
|
|
for project in ("BLF-data", "SL-data"):
|
|
for number in range(1, 4):
|
|
key = project.split("-")[0].lower() + f"-{number}"
|
|
directory = root / "templates" / key
|
|
directory.mkdir(parents=True, mode=0o700)
|
|
media = {}
|
|
for camera in ("left", "right"):
|
|
name = f"camera_{camera}.mp4"
|
|
shutil.copyfile(video, directory / name)
|
|
media[f"{camera}Video"] = f"templates/{key}/{name}"
|
|
pts_name = f"camera_{camera}_pts.csv"
|
|
(directory / pts_name).write_text("frame_index,timestamp_us\n" + "".join(
|
|
f"{frame},{1000000 + frame * 250000}\n" for frame in range(8)))
|
|
media[f"{camera}PTS"] = f"templates/{key}/{pts_name}"
|
|
(directory / "imu.csv").write_text("timestamp_us,x,y,z,type\n" + "".join(
|
|
f"{1000000 + frame * 250000},0,0,9.8,accel\n{1000000 + frame * 250000},0,0,0,gyro\n"
|
|
for frame in range(8)))
|
|
media["imu"] = f"templates/{key}/imu.csv"
|
|
sample = {"key": key, "project": project, "mode": "scratch" if number == 1 else "snapshot",
|
|
"source": {"captureId": f"synthetic-{key}", "taskId": f"synthetic-source-{key}", "version": "1"},
|
|
"media": media, "durationSeconds": 2}
|
|
if number > 1:
|
|
sample["snapshot"] = {
|
|
"stage": "annotation" if number == 2 else "quality_review",
|
|
"slices": [{"start": 0, "end": 2, "name": "测试切片"}],
|
|
"actions": [{"start": 0, "end": 1, "description": "测试动作"},
|
|
{"start": 1, "end": 2, "description": "", "isInvalid": False}],
|
|
}
|
|
samples.append(sample)
|
|
for path in media.values():
|
|
content = (root / path).read_bytes()
|
|
assets.append({"path": path, "size": len(content), "sha256": hashlib.sha256(content).hexdigest()})
|
|
video.unlink() # Only the generator's own temporary synthetic file.
|
|
dictionaries = {p: {"sliceNames": ["测试切片"], "descriptions": ["测试动作"],
|
|
"discardReasons": ["测试遮挡"]} for p in ("BLF-data", "SL-data")}
|
|
manifest = {"schemaVersion": "droboticflow.internal-test-seed/v1", "dictionaries": dictionaries,
|
|
"samples": samples, "assets": assets}
|
|
(root / "manifest.json").write_text(json.dumps(manifest, ensure_ascii=False, indent=2) + "\n")
|
|
return root / "manifest.json"
|
|
|
|
|
|
if __name__ == "__main__":
|
|
parser = argparse.ArgumentParser(description=__doc__)
|
|
parser.add_argument("--out", required=True)
|
|
print(make_bundle(parser.parse_args().out))
|