Spaces:
Running on CPU Upgrade
Running on CPU Upgrade
Sync from huggingface/lerobot-dataset-visualizer via hub-sync
Browse files
src/components/simple-videos-player.tsx
CHANGED
|
@@ -61,6 +61,15 @@ export const SimpleVideosPlayer = ({
|
|
| 61 |
|
| 62 |
const hiddenSet = React.useMemo(() => new Set(hiddenVideos), [hiddenVideos]);
|
| 63 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 64 |
const firstVisibleIdx = videosInfo.findIndex(
|
| 65 |
(video) => !hiddenSet.has(video.filename),
|
| 66 |
);
|
|
@@ -347,83 +356,105 @@ export const SimpleVideosPlayer = ({
|
|
| 347 |
if (hiddenVideos.includes(info.filename)) return null;
|
| 348 |
|
| 349 |
const isEnlarged = enlargedVideo === info.filename;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 350 |
|
| 351 |
return (
|
| 352 |
<div
|
| 353 |
key={info.filename}
|
| 354 |
className={`${
|
| 355 |
isEnlarged
|
| 356 |
-
? "z-40 fixed inset-0 bg-black
|
| 357 |
: "max-w-96"
|
| 358 |
}`}
|
| 359 |
-
|
| 360 |
-
|
| 361 |
-
|
| 362 |
-
|
| 363 |
-
<button
|
| 364 |
-
title={isEnlarged ? "Minimize" : "Enlarge"}
|
| 365 |
-
className="p-1 rounded text-slate-500 hover:text-slate-200 hover:bg-white/5 transition-colors"
|
| 366 |
-
onClick={() =>
|
| 367 |
-
setEnlargedVideo(isEnlarged ? null : info.filename)
|
| 368 |
}
|
| 369 |
-
|
| 370 |
-
|
| 371 |
-
|
| 372 |
-
|
| 373 |
-
|
| 374 |
-
|
| 375 |
-
</
|
| 376 |
-
<
|
| 377 |
-
|
| 378 |
-
|
| 379 |
-
|
| 380 |
-
|
| 381 |
-
|
| 382 |
-
// the enlarged state too — otherwise it stays pointed
|
| 383 |
-
// at the now-hidden filename and pops back to fullscreen
|
| 384 |
-
// the moment the user un-hides it.
|
| 385 |
-
if (enlargedVideo === info.filename) {
|
| 386 |
-
setEnlargedVideo(null);
|
| 387 |
}
|
| 388 |
-
|
| 389 |
-
|
| 390 |
-
|
| 391 |
-
|
| 392 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 393 |
}
|
|
|
|
|
|
|
|
|
|
| 394 |
>
|
| 395 |
-
<
|
| 396 |
-
|
| 397 |
-
|
| 398 |
-
|
| 399 |
-
<div className="relative w-full">
|
| 400 |
-
<video
|
| 401 |
-
ref={videoRefCallbacksRef.current[idx]}
|
| 402 |
-
className={`w-full object-contain ${
|
| 403 |
-
isEnlarged ? "max-h-[90vh] max-w-[90vw]" : ""
|
| 404 |
-
} ${info.isGrayscale ? "opacity-0" : ""}`}
|
| 405 |
-
muted
|
| 406 |
-
preload="auto"
|
| 407 |
-
crossOrigin="anonymous"
|
| 408 |
-
>
|
| 409 |
-
<source src={proxyHfUrl(info.url)} type="video/mp4" />
|
| 410 |
-
Your browser does not support the video tag.
|
| 411 |
-
</video>
|
| 412 |
-
{/* Grayscale feeds: the hidden <video> above still decodes and
|
| 413 |
drives timing; this canvas paints its frames recolored with
|
| 414 |
the viridis colormap. */}
|
| 415 |
-
|
| 416 |
-
|
| 417 |
-
|
| 418 |
-
|
| 419 |
-
|
| 420 |
-
|
| 421 |
AnnotationsContext; pointer-events fall through when
|
| 422 |
not in draw mode so video controls remain usable. */}
|
| 423 |
-
|
| 424 |
-
|
| 425 |
-
|
| 426 |
-
|
|
|
|
| 427 |
</div>
|
| 428 |
</div>
|
| 429 |
);
|
|
|
|
| 61 |
|
| 62 |
const hiddenSet = React.useMemo(() => new Set(hiddenVideos), [hiddenVideos]);
|
| 63 |
|
| 64 |
+
useEffect(() => {
|
| 65 |
+
if (!enlargedVideo) return;
|
| 66 |
+
const onKeyDown = (e: KeyboardEvent) => {
|
| 67 |
+
if (e.key === "Escape") setEnlargedVideo(null);
|
| 68 |
+
};
|
| 69 |
+
window.addEventListener("keydown", onKeyDown);
|
| 70 |
+
return () => window.removeEventListener("keydown", onKeyDown);
|
| 71 |
+
}, [enlargedVideo]);
|
| 72 |
+
|
| 73 |
const firstVisibleIdx = videosInfo.findIndex(
|
| 74 |
(video) => !hiddenSet.has(video.filename),
|
| 75 |
);
|
|
|
|
| 356 |
if (hiddenVideos.includes(info.filename)) return null;
|
| 357 |
|
| 358 |
const isEnlarged = enlargedVideo === info.filename;
|
| 359 |
+
const videoEl = videoEls[idx];
|
| 360 |
+
/// Size the enlarged box to the video's own aspect ratio, so object-contain never letterboxes
|
| 361 |
+
/// it away from the title bar.
|
| 362 |
+
const aspect =
|
| 363 |
+
videoEl && videoEl.videoHeight > 0
|
| 364 |
+
? videoEl.videoWidth / videoEl.videoHeight
|
| 365 |
+
: 4 / 3;
|
| 366 |
|
| 367 |
return (
|
| 368 |
<div
|
| 369 |
key={info.filename}
|
| 370 |
className={`${
|
| 371 |
isEnlarged
|
| 372 |
+
? "z-40 fixed inset-0 bg-black/90 flex items-center justify-center"
|
| 373 |
: "max-w-96"
|
| 374 |
}`}
|
| 375 |
+
onClick={
|
| 376 |
+
isEnlarged
|
| 377 |
+
? (e) => {
|
| 378 |
+
if (e.target === e.currentTarget) setEnlargedVideo(null);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 379 |
}
|
| 380 |
+
: undefined
|
| 381 |
+
}
|
| 382 |
+
>
|
| 383 |
+
{/* Shrink-wraps the enlarged video so the title bar matches its width. */}
|
| 384 |
+
<div className={isEnlarged ? "w-fit" : undefined}>
|
| 385 |
+
<p className="truncate w-full rounded-t-md bg-[var(--surface-1)] border border-b-0 border-white/5 px-2.5 py-1 text-[11px] text-slate-400 flex items-center justify-between gap-2">
|
| 386 |
+
<span className="truncate">{info.filename}</span>
|
| 387 |
+
<span className="flex gap-0.5 shrink-0">
|
| 388 |
+
<button
|
| 389 |
+
title={isEnlarged ? "Minimize (Esc)" : "Enlarge"}
|
| 390 |
+
className="p-1 rounded text-slate-500 hover:text-slate-200 hover:bg-white/5 transition-colors"
|
| 391 |
+
onClick={() =>
|
| 392 |
+
setEnlargedVideo(isEnlarged ? null : info.filename)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 393 |
}
|
| 394 |
+
>
|
| 395 |
+
{isEnlarged ? (
|
| 396 |
+
<FaCompress size={10} />
|
| 397 |
+
) : (
|
| 398 |
+
<FaExpand size={10} />
|
| 399 |
+
)}
|
| 400 |
+
</button>
|
| 401 |
+
<button
|
| 402 |
+
title="Hide Video"
|
| 403 |
+
className="p-1 rounded text-slate-500 hover:text-slate-200 hover:bg-white/5 transition-colors disabled:opacity-30 disabled:hover:bg-transparent"
|
| 404 |
+
onClick={() => {
|
| 405 |
+
setHiddenVideos((prev) => [...prev, info.filename]);
|
| 406 |
+
// If the user hid the camera that was enlarged, clear
|
| 407 |
+
// the enlarged state too — otherwise it stays pointed
|
| 408 |
+
// at the now-hidden filename and pops back to fullscreen
|
| 409 |
+
// the moment the user un-hides it.
|
| 410 |
+
if (enlargedVideo === info.filename) {
|
| 411 |
+
setEnlargedVideo(null);
|
| 412 |
+
}
|
| 413 |
+
}}
|
| 414 |
+
disabled={
|
| 415 |
+
videosInfo.filter(
|
| 416 |
+
(v) => !hiddenVideos.includes(v.filename),
|
| 417 |
+
).length === 1
|
| 418 |
+
}
|
| 419 |
+
>
|
| 420 |
+
<FaTimes size={10} />
|
| 421 |
+
</button>
|
| 422 |
+
</span>
|
| 423 |
+
</p>
|
| 424 |
+
<div className="relative w-full">
|
| 425 |
+
<video
|
| 426 |
+
ref={videoRefCallbacksRef.current[idx]}
|
| 427 |
+
className={`object-contain ${
|
| 428 |
+
isEnlarged ? "block h-auto" : "w-full"
|
| 429 |
+
} ${info.isGrayscale ? "opacity-0" : ""}`}
|
| 430 |
+
style={
|
| 431 |
+
isEnlarged
|
| 432 |
+
? { width: `min(90vw, calc(85vh * ${aspect}))` }
|
| 433 |
+
: undefined
|
| 434 |
}
|
| 435 |
+
muted
|
| 436 |
+
preload="auto"
|
| 437 |
+
crossOrigin="anonymous"
|
| 438 |
>
|
| 439 |
+
<source src={proxyHfUrl(info.url)} type="video/mp4" />
|
| 440 |
+
Your browser does not support the video tag.
|
| 441 |
+
</video>
|
| 442 |
+
{/* Grayscale feeds: the hidden <video> above still decodes and
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 443 |
drives timing; this canvas paints its frames recolored with
|
| 444 |
the viridis colormap. */}
|
| 445 |
+
<ColormappedVideo
|
| 446 |
+
videoEl={videoEls[idx] ?? null}
|
| 447 |
+
active={info.isGrayscale}
|
| 448 |
+
range={info.colormapRange}
|
| 449 |
+
/>
|
| 450 |
+
{/* VQA bbox/keypoint overlay. Reads atoms + drawMode from
|
| 451 |
AnnotationsContext; pointer-events fall through when
|
| 452 |
not in draw mode so video controls remain usable. */}
|
| 453 |
+
<VideoOverlayCanvas
|
| 454 |
+
videoEl={videoEls[idx] ?? null}
|
| 455 |
+
cameraKey={info.filename}
|
| 456 |
+
/>
|
| 457 |
+
</div>
|
| 458 |
</div>
|
| 459 |
</div>
|
| 460 |
);
|