Skip to content

Free Motion Capture for Everyone 💀✨

TypeScript

Development (#861)

philipqueen3943f6dbabbe
diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml
index 470c843c..cc088213 100644
--- a/.github/workflows/test.yml
+++ b/.github/workflows/test.yml
@@ -35,7 +35,7 @@ jobs:
- uses: actions/checkout@v4
- name: Install uv
- uses: astral-sh/setup-uv@v4
+ uses: astral-sh/setup-uv@cec208311dfd045dd5311c1add060b2062131d57
with:
version: "latest"
enable-cache: true
diff --git a/freemocap-ui/electron/main/api.ts b/freemocap-ui/electron/main/api.ts
index fe77a599..5a216123 100644
--- a/freemocap-ui/electron/main/api.ts
+++ b/freemocap-ui/electron/main/api.ts
@@ -307,6 +307,18 @@ export const api = t.router({
return result.canceled ? null : result.filePaths[0];
}),
+ selectVideoFiles: t.procedure
+ .mutation(async () => {
+ const result = await dialog.showOpenDialog({
+ properties: ['openFile', 'multiSelections'],
+ filters: [
+ { name: 'Video Files', extensions: ['mp4', 'avi', 'mov', 'mkv', 'webm', 'wmv', 'flv'] },
+ { name: 'All Files', extensions: ['*'] },
+ ],
+ });
+ return result.canceled ? [] : result.filePaths;
+ }),
+
validateCalibrationDirectory: t.procedure
.input(z.object({ directoryPath: z.string() }))
diff --git a/freemocap-ui/public/images/charuco_board.webp b/freemocap-ui/src/assets/images/charuco_board.webp
similarity index 100%
rename from freemocap-ui/public/images/charuco_board.webp
rename to freemocap-ui/src/assets/images/charuco_board.webp
diff --git a/freemocap-ui/public/images/charuco_settings.webp b/freemocap-ui/src/assets/images/charuco_settings.webp
similarity index 100%
rename from freemocap-ui/public/images/charuco_settings.webp
rename to freemocap-ui/src/assets/images/charuco_settings.webp
diff --git a/freemocap-ui/src/components/control-panels/mocap-control-panel/BlenderSection.tsx b/freemocap-ui/src/components/control-panels/mocap-control-panel/BlenderSection.tsx
index 95a228f9..ef264d9d 100644
--- a/freemocap-ui/src/components/control-panels/mocap-control-panel/BlenderSection.tsx
+++ b/freemocap-ui/src/components/control-panels/mocap-control-panel/BlenderSection.tsx
@@ -3,19 +3,25 @@ import {useBlender} from '@/hooks/useBlender';
import {useElectronIPC} from '@/services';
import ToggleComponent from '@/components/ui-components/ToggleComponent';
import IconButton from '@/components/ui-components/IconButton';
+import type {DetectorType} from '@/store/slices/mocap/mocap-slice';
interface BlenderSectionProps {
recordingFolderPath: string | null | undefined;
disabled?: boolean;
/** When provided, the "Open .blend in Blender" button is disabled unless true. */
hasBlendFile?: boolean;
+ /** The freemocap_blender_addon only understands MediaPipe output so far. */
+ detectorType?: DetectorType;
}
export const BlenderSection: React.FC<BlenderSectionProps> = ({
recordingFolderPath,
disabled = false,
hasBlendFile,
+ detectorType,
}) => {
+ const blenderSupported = detectorType === undefined || detectorType === 'mediapipe';
+
const {api, isElectron} = useElectronIPC();
const {
effectiveBlenderExePath,
@@ -60,6 +66,7 @@ export const BlenderSection: React.FC<BlenderSectionProps> = ({
};
const canExport =
+ blenderSupported &&
!!recordingFolderPath &&
!!effectiveBlenderExePath &&
!isExporting &&
@@ -129,16 +136,25 @@ export const BlenderSection: React.FC<BlenderSectionProps> = ({
</p>
</div>
+ {!blenderSupported && (
+ <p className="text sm text-gray">
+ Blender export only supports MediaPipe output right now - switch the
+ detector to MediaPipe to enable it.
+ </p>
+ )}
+
<div className="flex flex-col gap-1">
<ToggleComponent
text="Export to Blender after mocap processing"
- isToggled={exportToBlenderEnabled}
+ isToggled={exportToBlenderEnabled && blenderSupported}
onToggle={setExportToBlenderEnabled}
+ disabled={!blenderSupported}
/>
<ToggleComponent
text="Auto-open .blend file in Blender when done"
- isToggled={autoOpenBlendFile}
+ isToggled={autoOpenBlendFile && blenderSupported}
onToggle={setAutoOpenBlendFile}
+ disabled={!blenderSupported || !exportToBlenderEnabled}
/>
</div>
diff --git a/freemocap-ui/src/components/control-panels/mocap-control-panel/ImportVideosModal.tsx b/freemocap-ui/src/components/control-panels/mocap-control-panel/ImportVideosModal.tsx
new file mode 100644
index 00000000..6c125929
--- /dev/null
+++ b/freemocap-ui/src/components/control-panels/mocap-control-panel/ImportVideosModal.tsx
@@ -0,0 +1,249 @@
+import React, {useCallback, useEffect, useState} from 'react';
+import {useElectronIPC} from '@/services';
+import {useAppDispatch} from '@/store';
+import {checkVideoSync, importVideos, VideoSyncInfo} from '@/store/slices/mocap';
+import {activeRecordingSet, splitParentAndName} from '@/store/slices/active-recording/active-recording-slice';
+import ButtonSm from '@/components/ui-components/ButtonSm';
+import SubactionHeader from '@/components/ui-components/SubactionHeader';
+
+interface ImportVideosModalProps {
+ open: boolean;
+ onClose: () => void;
+ onImported?: () => void;
+}
+
+// Mirrors the backend's `default_recording_name` (freemocap/system/default_paths.py) —
+// a filename-friendly ISO-8601 timestamp with GMT offset, tagged "imported".
+function generateDefaultRecordingName(): string {
+ const now = new Date();
+ const pad = (n: number) => String(n).padStart(2, '0');
+ const isoTimestamp = `${now.getFullYear()}-${pad(now.getMonth() + 1)}-${pad(now.getDate())}` +
+ `T${pad(now.getHours())}:${pad(now.getMinutes())}:${pad(now.getSeconds())}`;
+
+ const offsetHours = -now.getTimezoneOffset() / 60;
+ const gmtOffset = `${offsetHours >= 0 ? '+' : '-'}${Math.abs(offsetHours)}`;
+
+ return `${isoTimestamp}_gmt${gmtOffset}`.replace(/:/g, '_') + '_imported';
+}
+
+export const ImportVideosModal: React.FC<ImportVideosModalProps> = ({open, onClose, onImported}) => {
+ const {isElectron, api} = useElectronIPC();
+ const dispatch = useAppDispatch();
+
+ const [videoPaths, setVideoPaths] = useState<string[]>([]);
+ const [recordingName, setRecordingName] = useState('');
+ const [defaultRecordingName, setDefaultRecordingName] = useState('');
+ const [busy, setBusy] = useState(false);
+ const [error, setError] = useState<string | null>(null);
+ const [checkingSync, setCheckingSync] = useState(false);
+ const [syncCheck, setSyncCheck] = useState<{ synchronized: boolean; videos: VideoSyncInfo[]; detail: string | null } | null>(null);
+
+ useEffect(() => {
+ if (!open) return;
+ setVideoPaths([]);
+ setRecordingName('');
+ setDefaultRecordingName(generateDefaultRecordingName());
+ setBusy(false);
+ setError(null);
+ setCheckingSync(false);
+ setSyncCheck(null);
+ }, [open]);
+
+ useEffect(() => {
+ if (!open) return;
+ if (videoPaths.length === 0) {
+ setSyncCheck(null);
+ return;
+ }
+ let cancelled = false;
+ setCheckingSync(true);
+ dispatch(checkVideoSync({videoPaths}))
+ .unwrap()
+ .then((result) => {
+ if (!cancelled) setSyncCheck(result);
+ })
+ .catch((err) => {
+ if (!cancelled) {
+ setSyncCheck(null);
+ setError(typeof err === 'string' ? err : 'Failed to check video synchronization');
+ }
+ })
+ .finally(() => {
+ if (!cancelled) setCheckingSync(false);
+ });
+ return () => {
+ cancelled = true;
+ };
+ }, [open, videoPaths, dispatch]);
+
+ useEffect(() => {
+ if (!open) return;
+ const onKeyDown = (e: KeyboardEvent) => {
+ if (e.key === 'Escape') onClose();
+ };
+ window.addEventListener('keydown', onKeyDown);
+ return () => window.removeEventListener('keydown', onKeyDown);
+ }, [open, onClose]);
+
+ const handleChooseFiles = useCallback(async () => {
+ if (!isElectron || !api) return;
+ try {
+ const result: string[] = await api.fileSystem.selectVideoFiles.mutate();
+ if (result.length > 0) {
+ setVideoPaths(result);
+ setError(null);
+ }
+ } catch (err) {
+ console.error('Failed to select video files:', err);
+ setError('Failed to select video files');
+ }
+ }, [isElectron, api]);
+
+ const handleClearSelection = useCallback(() => {
+ setVideoPaths([]);
+ setSyncCheck(null);
+ setError(null);
+ }, []);
+
+ const handleImport = useCallback(async () => {
+ if (videoPaths.length === 0 || busy) return;
+ setBusy(true);
+ setError(null);
+ try {
+ const result = await dispatch(importVideos({
+ videoPaths,
+ recordingName: recordingName.trim() || undefined,
+ })).unwrap();
+
+ const parsed = splitParentAndName(result.recordingPath);
+ dispatch(activeRecordingSet({
+ recordingName: result.recordingName,
+ baseDirectory: parsed?.baseDirectory,
+ origin: 'browsed',
+ }));
+ onImported?.();
+ onClose();
+ } catch (err) {
+ setError(typeof err === 'string' ? err : 'Failed to import videos');
+ } finally {
+ setBusy(false);
+ }
+ }, [videoPaths, recordingName, busy, dispatch, onClose, onImported]);
+
+ const importDisabledReason = busy
+ ? 'Importing…'
+ : videoPaths.length === 0
+ ? 'Select video files to import'
+ : checkingSync
+ ? 'Checking synchronization…'
+ : (!syncCheck || !syncCheck.synchronized)
+ ? 'Selected videos are not synchronized'
+ : null;
+
+ if (!open) return null;
+
+ return (
+ <>
+ {/* Backdrop */}
+ <div className="pos-fixed inset-0 bg-surface-overlay z-10" onClick={onClose}/>
+
+ {/* Modal */}
+ <div className="settings-modal bg-primary border-1 border-black pos-fixed elevated-sharp p-1 flex flex-col br-2">
+ <div className="flex flex-col p-2 gap-2 bg-middark br-1">
+ <div className="flex justify-content-space-between items-center">
+ <SubactionHeader text="Import Videos"/>
+ </div>
+
+ <p className="text sm text-gray">
+ Select pre-synchronized video files recorded outside FreeMoCap. A new recording
+ folder will be created and the videos copied into it.
+ </p>
+
+ <div className="flex flex-col gap-2 bg-secondary p-2 br-1">
+ <SubactionHeader text="Video files" className="text-gray"/>
+ <div className="flex flex-row gap-2">
+ <ButtonSm
+ text="Choose Video Files..."
+ buttonType="quaternary"
+ onClick={handleChooseFiles}
+ disabled={!isElectron || busy}
+ />
+ <ButtonSm
+ text="Clear Selection"
+ buttonType="quaternary"
+ onClick={handleClearSelection}
+ disabled={videoPaths.length === 0 || busy}
+ tooltip={videoPaths.length === 0}
+ tooltipText="No video files selected"
+ tooltipPosition="pos-top"
+ />
+ </div>
+ {videoPaths.length > 0 ? (
+ <div className="flex flex-col gap-1">
+ {videoPaths.map((path) => (
+ <p key={path} className="text sm text-white"
+ style={{fontFamily: 'monospace', wordBreak: 'break-all'}}>
+ {path.replace(/\\/g, '/').split('/').pop()}
+ </p>
+ ))}
+ </div>
+ ) : (
+ <p className="text sm text-darkgray">No video files selected</p>
+ )}
+ </div>
+
+ <div className="flex flex-col gap-1 bg-secondary p-2 br-1">
+ <SubactionHeader text="Recording name" className="text-gray"/>
+ <input
+ className="input-field text md"
+ value={recordingName}
+ onChange={(e) => setRecordingName(e.target.value)}
+ placeholder={defaultRecordingName}
+ disabled={busy}
+ />
+ </div>
+
+ {checkingSync && (
+ <p className="text sm text-gray">Checking synchronization…</p>
+ )}
+
+ {syncCheck && !syncCheck.synchronized && (
+ <div className="toast-notification error">
+ <p className="text sm">Selected videos are not synchronized — they have different frame counts.</p>
+ <div className="flex flex-col gap-1">
+ {syncCheck.videos.map((video) => (
+ <p key={video.filename} className="text sm"
+ style={{fontFamily: 'monospace', wordBreak: 'break-all'}}>
+ {video.filename}: {video.frameCount} frames ({video.fps.toFixed(2)} fps, {video.durationSeconds.toFixed(2)}s)
+ </p>
+ ))}
+ </div>
+ </div>
+ )}
+
+ {error && (
+ <div className="toast-notification error">
+ <p className="text sm">{error}</p>
+ </div>
+ )}
+
+ <div className="flex flex-row gap-2" style={{justifyContent: 'flex-end'}}>
+ <ButtonSm text="Cancel" buttonType="quaternary" onClick={onClose} disabled={busy}/>
+ <ButtonSm
+ text={busy ? 'Importing…' : 'Import'}
+ textColor="text-white"
+ className="primary accent"
+ onClick={handleImport}
+ disabled={importDisabledReason !== null}
+ tooltip={importDisabledReason !== null}
+ tooltipText={importDisabledReason ?? undefined}
+ tooltipPosition="pos-top"
+ />
+ </div>
+ </div>
+ </div>
+ </>
+ );
+};
+
+export default ImportVideosModal;
diff --git a/freemocap-ui/src/components/control-panels/mocap-control-panel/MocapPanel.tsx b/freemocap-ui/src/components/control-panels/mocap-control-panel/MocapPanel.tsx
index 9a8d7e5a..0dda64a6 100644
--- a/freemocap-ui/src/components/control-panels/mocap-control-panel/MocapPanel.tsx
+++ b/freemocap-ui/src/components/control-panels/mocap-control-panel/MocapPanel.tsx
@@ -38,6 +38,7 @@ export const MocapPanel: React.FC = () => {
setCalibrationTomlPath,
clearCalibrationTomlPath,
clearError,
+ detectorType,
} = useMocap();
const {
@@ -339,6 +340,7 @@ export const MocapPanel: React.FC = () => {
recordingFolderPath={mocapRecordingPath}
disabled={isLoading}
hasBlendFile={recordingStatus?.has_blend_file}
+ detectorType={detectorType}
/>
</div>
</div>
diff --git a/freemocap-ui/src/components/mocap-setup/mocap-blender-settings.tsx b/freemocap-ui/src/components/mocap-setup/mocap-blender-settings.tsx
index 850d0e6d..4e2de77c 100644
--- a/freemocap-ui/src/components/mocap-setup/mocap-blender-settings.tsx
+++ b/freemocap-ui/src/components/mocap-setup/mocap-blender-settings.tsx
@@ -17,7 +17,7 @@ const MOCAPBlenderSettings: React.FC<MOCAPBlenderSettingsProps> = ({
}) => {
const modalRef = useRef<HTMLDivElement>(null);
- const { mocapRecordingPath } = useMocap();
+ const { mocapRecordingPath, detectorType } = useMocap();
const { api, isElectron } = useElectronIPC();
const {
effectiveBlenderExePath,
@@ -56,8 +56,15 @@ const MOCAPBlenderSettings: React.FC<MOCAPBlenderSettingsProps> = ({
void triggerOpenInBlender(mocapRecordingPath);
};
+ // The freemocap_blender_addon only understands MediaPipe output so far -
+ // an rtmpose recording's Blender export is turned off client-side to match.
+ const blenderSupported = detectorType === "mediapipe";
+
const canExport =
- !!mocapRecordingPath && !!effectiveBlenderExePath && !isExporting;
+ blenderSupported &&
+ !!mocapRecordingPath &&
+ !!effectiveBlenderExePath &&
+ !isExporting;
const canOpen =
!!mocapRecordingPath && !!effectiveBlenderExePath && !isOpening;
@@ -145,17 +152,26 @@ const MOCAPBlenderSettings: React.FC<MOCAPBlenderSettingsProps> = ({
: "Click to browse for blender.exe"}
</p>
+ {!blenderSupported && (
+ <p className="text sm text-gray p-1">
+ Blender export only supports MediaPipe output right now - switch the detector
+ to MediaPipe to enable it.
+ </p>
+ )}
+
{/* Toggles */}
<ToggleComponent
text="Export to Blender after mocap processing"
- isToggled={exportToBlenderEnabled}
+ isToggled={exportToBlenderEnabled && blenderSupported}
onToggle={setExportToBlenderEnabled}
+ disabled={!blenderSupported}
/>
<ToggleComponent
text="Auto-open .blend file in Blender when done"
- isToggled={autoOpenBlendFile}
+ isToggled={autoOpenBlendFile && blenderSupported}
onToggle={setAutoOpenBlendFile}
+ disabled={!blenderSupported || !exportToBlenderEnabled}
/>
<ButtonSm
@@ -165,7 +181,11 @@ const MOCAPBlenderSettings: React.FC<MOCAPBlenderSettingsProps> = ({
className="full-width quaternary mt-3"
tooltip={true}
tooltipPosition="pos-bottom-left"
- tooltipText="Send your motion capture recording to Blender for further processing"
+ tooltipText={
+ blenderSupported
+ ? "Send your motion capture recording to Blender for further processing"
+ : "Blender export only supports MediaPipe output right now"
+ }
/>
<ButtonSm
diff --git a/freemocap-ui/src/components/mocap-setup/mocap-setup-modal.tsx b/freemocap-ui/src/components/mocap-setup/mocap-setup-modal.tsx
index 0d7083aa..e84276b4 100644
--- a/freemocap-ui/src/components/mocap-setup/mocap-setup-modal.tsx
+++ b/freemocap-ui/src/components/mocap-setup/mocap-setup-modal.tsx
@@ -29,8 +29,15 @@ const MocapSetupModal: React.FC<MocapSetupModalProps> = ({
directoryInfo,
calibrationTomlPath,
dispatchProcessMocapRecording,
+ validateDirectory,
} = useMocap();
+ useEffect(() => {
+ if (mocapRecordingPath) {
+ validateDirectory(mocapRecordingPath);
+ }
+ }, [mocapRecordingPath, validateDirectory]);
+
const processBlockedReason = useMemo((): string | null => {
if (canProcessMocapRecording) return null;
if (isRecording) return "Stop recording before processing";
diff --git a/freemocap-ui/src/components/pipeline-progress/calibration-progress/calibration-module.tsx b/freemocap-ui/src/components/pipeline-progress/calibration-progress/calibration-module.tsx
index 71bd578d..b963bd5a 100644
--- a/freemocap-ui/src/components/pipeline-progress/calibration-progress/calibration-module.tsx
+++ b/freemocap-ui/src/components/pipeline-progress/calibration-progress/calibration-module.tsx
@@ -8,6 +8,7 @@ import CalibrationSettings from "./calibration-settings";
import { FloatingOnboarding } from "@/hooks/floatingOnboarding";
import PromptTooltip from "@/components/ui-components/PromptTooltip";
import ButtonSm from "@/components/ui-components/ButtonSm";
+import charucoBoardImage from "@/assets/images/charuco_board.webp";
import { useCalibration } from "@/hooks/useCalibration";
import { useElectronIPC, useServer } from "@/services";
import { useAppDispatch, useAppSelector } from "@/store";
@@ -489,7 +490,7 @@ const CalibrationModule = ({
title="How to Calibrate your cameras"
text="Print a ChArUco board and show it to each camera while recording, pan and rotate it so it can be captured from different angles for accurate 3D tracking."
image={true}
- imageSrc="/images/charuco_board.webp"
+ imageSrc={charucoBoardImage}
position="pos-right"
variant="default"
button={true}
diff --git a/freemocap-ui/src/components/pipeline-progress/calibration-progress/calibration-settings.tsx b/freemocap-ui/src/components/pipeline-progress/calibration-progress/calibration-settings.tsx
index 9765c429..19035da0 100644
--- a/freemocap-ui/src/components/pipeline-progress/calibration-progress/calibration-settings.tsx
+++ b/freemocap-ui/src/components/pipeline-progress/calibration-progress/calibration-settings.tsx
@@ -12,6 +12,7 @@ import NameDropdownSelector from "@/components/ui-components/NameDropdownSelecto
import { useCalibration } from "@/hooks/useCalibration";
import { CalibrationSolverMethod } from "@/store/slices/calibration";
import PromptTooltip from "@/components/ui-components/PromptTooltip";
+import charucoSettingsImage from "@/assets/images/charuco_settings.webp";
type BoardPreset = "5 x 3" | "7 x 5" | "Custom";
@@ -45,9 +46,17 @@ interface CalibrationSettingsProps {
const CalibrationSettings = ({ onClose }: CalibrationSettingsProps) => {
const modalRef = useRef<HTMLDivElement>(null);
- const { config, updateCalibrationConfig } = useCalibration();
+ const { config, updateCalibrationConfig, pyceresAvailable } = useCalibration();
const board = config.charucoBoard;
+ const solverOptions = useMemo(
+ () =>
+ pyceresAvailable === false
+ ? PRESET_OPTIONS_SOLVER.filter((label) => label !== "Accurate")
+ : PRESET_OPTIONS_SOLVER,
+ [pyceresAvailable],
+ );
+
const handleClose = useCallback(() => {
if (onClose) onClose();
}, [onClose]);
@@ -165,7 +174,7 @@ const CalibrationSettings = ({ onClose }: CalibrationSettingsProps) => {
"Solver method: There are two options. Select the appropriate one depending on the use case."
}
image={true}
- imageSrc="/images/charuco_settings.webp"
+ imageSrc={charucoSettingsImage}
position="pos-right"
variant="default"
onClose={closeTooltip}
@@ -243,17 +252,24 @@ const CalibrationSettings = ({ onClose }: CalibrationSettingsProps) => {
<SubactionHeader text="Solver settings" />
- {/* Method dropdown */}
- <div className="flex p-1 flex-row gap-1 items-center justify-content-space-between">
- <span className="text-sm">Method</span>
- <NameDropdownSelector
- key={config.solverMethod}
- options={PRESET_OPTIONS_SOLVER}
- initialValue={solverMethodToLabel[config.solverMethod]}
- onChange={handleSolverChange}
- className="flex flex-row"
- />
- </div>
+ {/* Method dropdown (only shown when there's a choice to make) */}
+ {solverOptions.length > 1 ? (
+ <div className="flex p-1 flex-row gap-1 items-center justify-content-space-between">
+ <span className="text-sm">Method</span>
+ <NameDropdownSelector
+ key={config.solverMethod}
+ options={solverOptions}
+ initialValue={solverMethodToLabel[config.solverMethod]}
+ onChange={handleSolverChange}
+ className="flex flex-row"
+ />
+ </div>
+ ) : (
+ <div className="flex p-1 flex-row gap-1 items-center justify-content-space-between">
+ <span className="text-sm">Method</span>
+ <span className="text-sm">{solverMethodToLabel[config.solverMethod]}</span>
+ </div>
+ )}
</div>
</div>
);
diff --git a/freemocap-ui/src/components/playback/RecordingBrowser.tsx b/freemocap-ui/src/components/playback/RecordingBrowser.tsx
index 4a6bacf4..58091d31 100644
--- a/freemocap-ui/src/components/playback/RecordingBrowser.tsx
+++ b/freemocap-ui/src/components/playback/RecordingBrowser.tsx
@@ -31,6 +31,7 @@ import { serverUrls } from "@/constants/server-urls";
import ButtonSm from "@/components/ui-components/ButtonSm";
import SubactionHeader from "@/components/ui-components/SubactionHeader";
import IconButton from "@/components/ui-components/IconButton";
+import {ImportVideosModal} from "@/components/control-panels/mocap-control-panel/ImportVideosModal";
export type RecordingEntry = RecordingListEntry;
@@ -185,6 +186,7 @@ export const RecordingBrowser: React.FC<RecordingBrowserProps> = ({
const [sortField, setSortField] = useState<SortField>("date");
const [sortDir, setSortDir] = useState<SortDirection>("desc");
const [selectedPath, setSelectedPath] = useState<string | null>(null);
+ const [isImportModalOpen, setIsImportModalOpen] = useState(false);
const fetchRecordings = useCallback(
async (force = false) => {
@@ -366,7 +368,7 @@ export const RecordingBrowser: React.FC<RecordingBrowserProps> = ({
<SubactionHeader text={t("recordings")} />
</div>
</div>
- <div className="folder-directory-tool-bar flex flex-row gap-1 items-center">
+ <div className="folder-directory-tool-bar flex flex-row flex-wrap gap-1 items-center">
<IconButton
title={showFilter ? t("hideFilter") : t("filter")}
icon={showFilter ? "filter-active-icon" : "filter-icon"}
@@ -411,7 +413,19 @@ export const RecordingBrowser: React.FC<RecordingBrowserProps> = ({
</option>
))}
</select>
-
+
+ <ButtonSm
+ text="Import Videos"
+ iconClass="download-icon"
+ onClick={() => setIsImportModalOpen(true)}
+ disabled={!isElectron}
+ title={!isElectron ? "Import is only available in the desktop app" : undefined}
+ />
+ <ImportVideosModal
+ open={isImportModalOpen}
+ onClose={() => setIsImportModalOpen(false)}
+ onImported={() => fetchRecordings(true)}
+ />
</div>
</div>
<div className="folder-path-selection-group flex gap-1 flex-row flex-nowrap items-center flex-row justify-content-space-between w-full">
diff --git a/freemocap-ui/src/constants/server-urls.ts b/freemocap-ui/src/constants/server-urls.ts
index c9fc382d..ea2d9eae 100644
--- a/freemocap-ui/src/constants/server-urls.ts
+++ b/freemocap-ui/src/constants/server-urls.ts
@@ -80,11 +80,14 @@ class ServerUrls {
calibrationStartRecording: `${baseUrl}/freemocap/calibration/recording/start`,
calibrationStopRecording: `${baseUrl}/freemocap/calibration/recording/stop`,
calibrateRecording: `${baseUrl}/freemocap/calibration/recording/calibrate`,
+ calibrationPyceresAvailability: `${baseUrl}/freemocap/calibration/solver-methods/pyceres-availability`,
// Mocap endpoints
mocapStartRecording: `${baseUrl}/freemocap/mocap/recording/start`,
mocapStopRecording: `${baseUrl}/freemocap/mocap/recording/stop`,
processMocapRecording: `${baseUrl}/freemocap/mocap/recording/process`,
+ importVideos: `${baseUrl}/freemocap/mocap/recording/import`,
+ checkVideoSync: `${baseUrl}/freemocap/mocap/recording/check_sync`,
// Posthoc pipeline control
stopPipeline: (pipelineId: string) => `${baseUrl}/freemocap/posthoc/pipeline/${encodeURIComponent(pipelineId)}`,
diff --git a/freemocap-ui/src/hooks/useCalibration.ts b/freemocap-ui/src/hooks/useCalibration.ts
index 4c87cc07..f6db7652 100644
--- a/freemocap-ui/src/hooks/useCalibration.ts
+++ b/freemocap-ui/src/hooks/useCalibration.ts
@@ -1,5 +1,5 @@
// hooks/useCalibration.ts
-import {useCallback} from 'react';
+import {useCallback, useEffect} from 'react';
import {useAppDispatch, useAppSelector} from '@/store/hooks';
import {store} from '@/store';
import {useElectronIPC} from '@/services';
@@ -10,6 +10,7 @@ import {
CalibrationDirectoryInfo,
calibrationDirectoryInfoUpdated,
calibrationErrorCleared,
+ checkPyceresAvailability,
selectCalibration,
selectCalibrationDirectoryInfo,
selectCalibrationRecordingPath,
@@ -50,6 +51,12 @@ export function useCalibration() {
const directoryInfo = useAppSelector(selectCalibrationDirectoryInfo);
const isUsingManualPath = useAppSelector(selectIsUsingManualCalibrationPath);
+ useEffect(() => {
+ if (calibrationState.pyceresAvailable === null && !calibrationState.isCheckingPyceresAvailability) {
+ void dispatch(checkPyceresAvailability());
+ }
+ }, [dispatch, calibrationState.pyceresAvailable, calibrationState.isCheckingPyceresAvailability]);
+
const updateCalibrationConfig = useCallback(
(updates: Partial<CalibrationConfig>) => {
// Update local state first
@@ -127,6 +134,7 @@ export function useCalibration() {
isUsingManualPath,
canStartRecording,
canCalibrate,
+ pyceresAvailable: calibrationState.pyceresAvailable,
// Actions
updateCalibrationConfig,
setManualRecordingPath,
diff --git a/freemocap-ui/src/store/slices/blender/blender-slice.ts b/freemocap-ui/src/store/slices/blender/blender-slice.ts
index b5f7f920..09aa7e3b 100644
--- a/freemocap-ui/src/store/slices/blender/blender-slice.ts
+++ b/freemocap-ui/src/store/slices/blender/blender-slice.ts
@@ -8,6 +8,8 @@ export interface BlenderState {
detectedBlenderExePath: string | null;
exportToBlenderEnabled: boolean;
autoOpenBlendFile: boolean;
+ /** Remembers autoOpenBlendFile's value from before exportToBlenderEnabled was turned off, so it can be restored. */
+ autoOpenBlendFileBeforeExportDisabled: boolean | null;
isExporting: boolean;
isDetecting: boolean;
isOpening: boolean;
@@ -28,6 +30,7 @@ const initialState: BlenderState = {
detectedBlenderExePath: null,
exportToBlenderEnabled: _persistedBlender?.exportToBlenderEnabled ?? true,
autoOpenBlendFile: _persistedBlender?.autoOpenBlendFile ?? true,
+ autoOpenBlendFileBeforeExportDisabled: null,
isExporting: false,
isDetecting: false,
isOpening: false,
@@ -46,7 +49,15 @@ export const blenderSlice = createSlice({
state.blenderExePath = null;
},
exportToBlenderToggled: (state, action: PayloadAction<boolean>) => {
- state.exportToBlenderEnabled = action.payload;
+ const enabled = action.payload;
+ if (!enabled && state.exportToBlenderEnabled) {
+ state.autoOpenBlendFileBeforeExportDisabled = state.autoOpenBlendFile;
+ state.autoOpenBlendFile = false;
+ } else if (enabled && !state.exportToBlenderEnabled && state.autoOpenBlendFileBeforeExportDisabled !== null) {
+ state.autoOpenBlendFile = state.autoOpenBlendFileBeforeExportDisabled;
+ state.autoOpenBlendFileBeforeExportDisabled = null;
+ }
+ state.exportToBlenderEnabled = enabled;
},
autoOpenBlendFileToggled: (state, action: PayloadAction<boolean>) => {
state.autoOpenBlendFile = action.payload;
diff --git a/freemocap-ui/src/store/slices/calibration/calibration-slice.ts b/freemocap-ui/src/store/slices/calibration/calibration-slice.ts
index d586b73c..a7dd302d 100644
--- a/freemocap-ui/src/store/slices/calibration/calibration-slice.ts
+++ b/freemocap-ui/src/store/slices/calibration/calibration-slice.ts
@@ -3,6 +3,7 @@ import {RootState} from '../../types';
import {loadFromStorage} from '@/store/persistence';
import {
calibrateRecording,
+ checkPyceresAvailability,
loadCalibrationForRecording,
loadCalibrationToml,
startCalibrationRecording,
@@ -43,6 +44,8 @@ export interface CalibrationState {
directoryInfo: CalibrationDirectoryInfo | null;
loadedCalibration: LoadedCalibration | null;
dismissedCalibrationPath: string | null;
+ pyceresAvailable: boolean | null;
+ isCheckingPyceresAvailability: boolean;
}
const DEFAULT_CALIBRATION_CONFIG: CalibrationConfig = {
@@ -64,6 +67,8 @@ const initialState: CalibrationState = {
directoryInfo: null,
loadedCalibration: null,
dismissedCalibrationPath: null,
+ pyceresAvailable: null,
+ isCheckingPyceresAvailability: false,
};
export const calibrationSlice = createSlice({
@@ -158,6 +163,22 @@ export const calibrationSlice = createSlice({
state.isLoading = false;
state.error = action.payload || 'Failed to calibrate recording';
});
+
+ builder
+ .addCase(checkPyceresAvailability.pending, (state) => {
+ state.isCheckingPyceresAvailability = true;
+ })
+ .addCase(checkPyceresAvailability.fulfilled, (state, action) => {
+ state.isCheckingPyceresAvailability = false;
+ state.pyceresAvailable = action.payload.available;
+ if (!action.payload.available && state.config.solverMethod === 'pyceres') {
+ state.config.solverMethod = 'anipose';
+ }
+ })
+ .addCase(checkPyceresAvailability.rejected, (state) => {
+ state.isCheckingPyceresAvailability = false;
+ state.pyceresAvailable = false;
+ });
},
});
@@ -170,6 +191,7 @@ export const selectCalibrationError = (state: RootState) => state.calibration.er
export const selectCalibrationDirectoryInfo = (state: RootState) => state.calibration.directoryInfo;
export const selectLoadedCalibration = (state: RootState) => state.calibration.loadedCalibration;
export const selectDismissedCalibrationPath = (state: RootState) => state.calibration.dismissedCalibrationPath;
+export const selectPyceresAvailable = (state: RootState) => state.calibration.pyceresAvailable;
export const selectCalibrationRecordingPath = selectActiveRecordingFullPath;
diff --git a/freemocap-ui/src/store/slices/calibration/calibration-thunks.ts b/freemocap-ui/src/store/slices/calibration/calibration-thunks.ts
index 82551a9f..4b5810b2 100644
--- a/freemocap-ui/src/store/slices/calibration/calibration-thunks.ts
+++ b/freemocap-ui/src/store/slices/calibration/calibration-thunks.ts
@@ -8,6 +8,30 @@ import type {LoadedCalibration} from "./calibration-slice";
import {pipelineProgressUpdated, PipelinePhase, PipelineType} from "@/store/slices/pipelines";
import {getTimestampString} from "@/store/slices/recording/getTimestampString";
+export const checkPyceresAvailability = createAsyncThunk<
+ { available: boolean; message?: string | null },
+ void,
+ { state: RootState; rejectValue: string }
+>(
+ 'calibration/checkPyceresAvailability',
+ async (_, { rejectWithValue }) => {
+ try {
+ const response = await fetch(serverUrls.endpoints.calibrationPyceresAvailability);
+ if (!response.ok) {
+ return rejectWithValue(await getDetailedErrorMessage(response));
+ }
+ const data = await response.json();
+ return {
+ available: !!data.available,
+ message: data.message ?? null,
+ };
+ } catch (error) {
+ const msg = error instanceof Error ? error.message : 'Unknown error';
+ return rejectWithValue(msg);
+ }
+ }
+);
+
export const loadCalibrationForRecording = createAsyncThunk<
LoadedCalibration | null,
{ recordingId: string; recordingParentDirectory?: string | null },
diff --git a/freemocap-ui/src/store/slices/mocap/mocap-thunks.ts b/freemocap-ui/src/store/slices/mocap/mocap-thunks.ts
index 4ee5545d..129c49fe 100644
--- a/freemocap-ui/src/store/slices/mocap/mocap-thunks.ts
+++ b/freemocap-ui/src/store/slices/mocap/mocap-thunks.ts
@@ -12,6 +12,10 @@ function buildPosthocConfig(state: RootState) {
// Explicit override wins; fall back to the calibration loaded in the calibration panel
const calibrationTomlPath =
state.mocap.calibrationTomlPath ?? selectLoadedCalibration(state)?.path ?? null;
+ // The freemocap_blender_addon only understands MediaPipe output so far - gate the
+ // request payload here rather than clobbering the user's toggle preference in the
+ // UI, so switching the detector away and back doesn't lose their selection.
+ const blenderSupported = config.detectorType === "mediapipe";
return {
detectorType: config.detectorType,
rtmPoseModelName: config.rtmPoseModelName,
@@ -25,9 +29,9 @@ function buildPosthocConfig(state: RootState) {
calibrationTomlPath,
triangulationConfig: config.triangulation,
filterConfig: config.posthoc_filter,
- exportToBlender: blender.exportToBlenderEnabled,
+ exportToBlender: blenderSupported && blender.exportToBlenderEnabled,
blenderExePath: blender.blenderExePath ?? blender.detectedBlenderExePath,
- autoOpenBlendFile: blender.autoOpenBlendFile,
+ autoOpenBlendFile: blenderSupported && blender.autoOpenBlendFile,
};
}
@@ -124,6 +128,88 @@ export const stopMocapRecording = createAsyncThunk<
}
);
+export const importVideos = createAsyncThunk<
+ { success: boolean; recordingName: string; recordingPath: string; videoCount: number },
+ { videoPaths: string[]; recordingName?: string; baseDirectory?: string },
+ { state: RootState; rejectValue: string }
+>(
+ 'mocap/importVideos',
+ async ({ videoPaths, recordingName, baseDirectory }, { rejectWithValue }) => {
+ try {
+ const response = await fetch(serverUrls.endpoints.importVideos, {
+ method: 'POST',
+ headers: { 'Content-Type': 'application/json' },
+ body: JSON.stringify({ videoPaths, recordingName, baseDirectory }),
+ });
+
+ if (!response.ok) {
+ const errorMessage = await getDetailedErrorMessage(response);
+ return rejectWithValue(errorMessage);
+ }
+
+ const result = await response.json();
+ console.log('âś… Imported videos:', result);
+ return {
+ success: result.success,
+ recordingName: result.recording_name,
+ recordingPath: result.recording_path,
+ videoCount: result.video_count,
+ };
+ } catch (error) {
+ const errorMessage = error instanceof Error ? error.message : 'Unknown error';
+ console.error('❌ Failed to import videos:', errorMessage);
+ return rejectWithValue(errorMessage);
+ }
+ }
+);
+
+export interface VideoSyncInfo {
+ filename: string;
+ cameraId: string;
+ frameCount: number;
+ fps: number;
+ durationSeconds: number;
+}
+
+export const checkVideoSync = createAsyncThunk<
+ { synchronized: boolean; videos: VideoSyncInfo[]; detail: string | null },
+ { videoPaths: string[] },
+ { state: RootState; rejectValue: string }
+>(
+ 'mocap/checkVideoSync',
+ async ({ videoPaths }, { rejectWithValue }) => {
+ try {
+ const response = await fetch(serverUrls.endpoints.checkVideoSync, {
+ method: 'POST',
+ headers: { 'Content-Type': 'application/json' },
+ body: JSON.stringify({ videoPaths }),
+ });
+
+ if (!response.ok) {
+ const errorMessage = await getDetailedErrorMessage(response);
+ return rejectWithValue(errorMessage);
+ }
+
+ const result = await response.json();
+ return {
+ synchronized: result.synchronized,
+ videos: (result.videos ?? []).map((video: any) => ({
+ filename: video.filename,
+ cameraId: video.camera_id,
+ frameCount: video.frame_count,
+ fps: video.fps,
+ durationSeconds: video.duration_seconds,
+ })),
+ detail: result.detail ?? null,
+ };
+ } catch (error) {
+ const errorMessage = error instanceof Error ? error.message : 'Unknown error';
+ console.error('❌ Failed to check video sync:', errorMessage);
+ return rejectWithValue(errorMessage);
+ }
+ }
+);
+
export const processMocapRecording = createAsyncThunk<
{ success: boolean; message?: string; results?: unknown; pipeline_id?: string },
void,
diff --git a/freemocap/api/http/calibration/calibration_router.py b/freemocap/api/http/calibration/calibration_router.py
index b90628ec..c8e2b601 100644
--- a/freemocap/api/http/calibration/calibration_router.py
+++ b/freemocap/api/http/calibration/calibration_router.py
@@ -1,3 +1,4 @@
+import importlib.util
import json
import logging
from copy import deepcopy
@@ -87,6 +88,11 @@ class CalibrateRecordingResponse(BaseModel):
pipeline_id: str | None = None
+class PyceresAvailabilityResponse(BaseModel):
+ available: bool
+ message: str | None = None
+
+
# ==================== Helpers ====================
@@ -229,6 +235,17 @@ async def stop_calibration_recording(
raise HTTPException(status_code=500, detail=str(e))
+@calibration_router.get("/solver-methods/pyceres-availability")
+def get_pyceres_availability() -> PyceresAvailabilityResponse:
+ """Check whether the optional `pyceres` package (required by the 'Accurate' solver) is installed."""
+ if importlib.util.find_spec("pyceres") is not None:
+ return PyceresAvailabilityResponse(available=True)
+ return PyceresAvailabilityResponse(
+ available=False,
+ message="The 'pyceres' package is not installed in this environment.",
+ )
+
+
@calibration_router.post("/recording/calibrate")
async def calibrate_recording(request: CalibrateRecordingRequest) -> CalibrateRecordingResponse:
"""Process and calibrate a previously recorded session."""
diff --git a/freemocap/api/http/mocap/mocap_router.py b/freemocap/api/http/mocap/mocap_router.py
index 98f878ad..0e647388 100644
--- a/freemocap/api/http/mocap/mocap_router.py
+++ b/freemocap/api/http/mocap/mocap_router.py
@@ -1,14 +1,17 @@
import logging
+import shutil
from copy import deepcopy
from pathlib import Path
from fastapi import APIRouter, HTTPException
from pydantic import BaseModel, ConfigDict, Field
+from skellycam.core.recorders.videos.parse_video_filename import ParsedVideoFilename
from skellycam.core.recorders.videos.recording_info import RecordingInfo
from freemocap.app.freemocap_application import get_freemocap_app
+from freemocap.core.pipeline.posthoc.video_group_helper import VideoHelper
from freemocap.core.tasks.mocap.mocap_task_config import PosthocMocapPipelineConfig
-from freemocap.system.default_paths import FREEMOCAP_TEST_DATA_PATH
+from freemocap.system.default_paths import FREEMOCAP_TEST_DATA_PATH, default_recording_name, get_default_freemocap_recordings_path
logger = logging.getLogger(__name__)
@@ -94,9 +97,90 @@ class MocapRecordingResponse(BaseModel):
pipeline_id: str | None = None
+class ImportVideosRequest(BaseModel):
+ video_paths: list[str] = Field(alias="videoPaths")
+ recording_name: str | None = Field(default=None, alias="recordingName")
+ base_directory: str | None = Field(default=None, alias="baseDirectory")
+
+
+class ImportVideosResponse(BaseModel):
+ success: bool
+ recording_name: str
+ recording_path: str
+ video_count: int
+
+
+class CheckVideoSyncRequest(BaseModel):
+ video_paths: list[str] = Field(alias="videoPaths")
+
+
+class VideoSyncInfo(BaseModel):
+ filename: str
+ camera_id: str
+ frame_count: int
+ fps: float
+ duration_seconds: float
+
+
+class CheckVideoSyncResponse(BaseModel):
+ synchronized: bool
+ videos: list[VideoSyncInfo]
+ detail: str | None = None
+
+
# ==================== Endpoints ====================
+def _check_video_sync(video_paths: list[str]) -> CheckVideoSyncResponse:
+ """Check whether a group of imported videos share a single frame count.
+
+ Imported videos have no capture-time timestamp CSVs (those only exist for live
+ FreeMoCap/skellycam recordings), so frame count is the only signal available to judge
+ synchronization. This mirrors the check `VideoGroupHelper.validate_videos` enforces for
+ live recordings, but built from `VideoHelper` directly (rather than `VideoGroupHelper.
+ from_video_paths`) so per-video details can be returned even when frame counts mismatch.
+ """
+ paths = sorted(Path(p).expanduser() for p in video_paths)
+ for path in paths:
+ if not path.is_file():
+ raise HTTPException(status_code=400, detail=f"Video file not found: {path}")
+
+ parsed_list = [ParsedVideoFilename.from_path(p) for p in paths]
+ indices = [pv.camera_index for pv in parsed_list]
+ if -1 in indices or len(set(indices)) < len(indices):
+ for i, pv in enumerate(parsed_list):
+ pv.camera_index = i
+
+ helpers = [VideoHelper.from_video_path(path) for path in paths]
+ try:
+ videos = [
+ VideoSyncInfo(
+ filename=path.name,
+ camera_id=pv.camera_id,
+ frame_count=helper.metadata.frame_count,
+ fps=helper.metadata.fps,
+ duration_seconds=helper.metadata.duration_seconds,
+ )
+ for path, pv, helper in zip(paths, parsed_list, helpers)
+ ]
+ finally:
+ for helper in helpers:
+ helper.close()
+
+ frame_counts = {video.frame_count for video in videos}
+ synchronized = len(frame_counts) == 1
+
+ detail = None
+ if not synchronized:
+ lines = [f" {video.camera_id}: {video.frame_count} frames ({video.filename})" for video in videos]
+ detail = (
+ "Selected videos must have the same frame count to be synchronized, but they differ:\n"
+ + "\n".join(lines)
+ )
+
+ return CheckVideoSyncResponse(synchronized=synchronized, videos=videos, detail=detail)
+
+
@mocap_router.post("/recording/start")
async def start_mocap_recording(
request: StartMocapRecordingRequest,
@@ -136,6 +220,59 @@ async def stop_mocap_recording(request: StopMocapRecordingRequest) -> dict[str,
raise HTTPException(status_code=500, detail=str(e))
+@mocap_router.post("/recording/check_sync")
+async def check_video_sync(request: CheckVideoSyncRequest) -> CheckVideoSyncResponse:
+ """Check whether a set of externally-recorded videos share a frame count (i.e. are synchronized)."""
+ if not request.video_paths:
+ raise HTTPException(status_code=400, detail="No video files provided")
+ return _check_video_sync(request.video_paths)
+
+
+@mocap_router.post("/recording/import")
+async def import_videos(request: ImportVideosRequest) -> ImportVideosResponse:
+ """Create a new recording folder from externally-recorded, pre-synchronized videos."""
+ if not request.video_paths:
+ raise HTTPException(status_code=400, detail="No video files provided")
+
+ sync_result = _check_video_sync(request.video_paths)
+ if not sync_result.synchronized:
+ raise HTTPException(status_code=400, detail=sync_result.detail)
+
+ base_directory = (
+ Path(request.base_directory).expanduser()
+ if request.base_directory
+ else Path(get_default_freemocap_recordings_path())
+ )
+ recording_name = request.recording_name or default_recording_name(string_tag="imported")
+
+ # Legacy layout only — a single `synchronized_videos` folder at the recording root.
+ # Not `RecordingStructure.create_on_disk()`: that also creates `videos/annotated`,
+ # `output`, and `logs`, which an imported recording (nothing but videos) doesn't need yet.
+ recording_path = base_directory / recording_name
+ synchronized_videos_dir = recording_path / "synchronized_videos"
+ synchronized_videos_dir.mkdir(parents=True, exist_ok=True)
+
+ try:
+ for video_path in request.video_paths:
+ src = Path(video_path).expanduser()
+ if not src.is_file():
+ raise HTTPException(status_code=400, detail=f"Video file not found: {video_path}")
+ shutil.copy2(src, synchronized_videos_dir / src.name)
+ except Exception as e:
+ logger.exception(f"Error importing videos into {recording_path}: {e}")
+ if isinstance(e, HTTPException):
+ raise
+ raise HTTPException(status_code=500, detail=str(e))
+
+ logger.info(f"Imported {len(request.video_paths)} video(s) into {recording_path}")
+ return ImportVideosResponse(
+ success=True,
+ recording_name=recording_name,
+ recording_path=str(recording_path),
+ video_count=len(request.video_paths),
+ )
+
+
@mocap_router.post("/recording/process")
async def process_mocap_recording(request: ProcessMocapRecordingRequest) -> MocapRecordingResponse:
"""Process a previously recorded session with mocap pipeline."""
diff --git a/freemocap/core/blender/export_to_blender.py b/freemocap/core/blender/export_to_blender.py
index 8bc80a51..3b41f85a 100644
--- a/freemocap/core/blender/export_to_blender.py
+++ b/freemocap/core/blender/export_to_blender.py
@@ -9,7 +9,10 @@ import freemocap_blender_addon
from freemocap.core.blender.helpers import run_blender_export as run_blender_export_module
from freemocap.core.blender.helpers.run_blender_export import run_blender_export
from freemocap.core.blender.helpers.get_best_guess_of_blender_path import get_best_guess_of_blender_path
-from freemocap.system.recording_status.recording_status import raise_if_not_blender_ready, REQUIRED_BLENDER_INPUT_FILES
+from freemocap.system.recording_status.recording_status import (
+ raise_if_not_blender_ready,
+ detect_blender_input_detector,
+)
from freemocap.utilities.open_file import open_file
logger = logging.getLogger(__name__)
@@ -40,26 +43,22 @@ def run_subprocess(command_list: List[str]):
def export_to_blender(
recording_folder_path: str|Path,
+ detector:str,
blend_file_path: str|Path|None=None,
blender_exe_path: str|Path|None=None,
open_file_on_completion:bool=True,
):
- try:
- raise_if_not_blender_ready(recording_folder_path)
- except FileNotFoundError:
- output_data = Path(recording_folder_path) / "output_data"
- non_mediapipe_equivalents_present = all(
- any(output_data.glob(f.replace("mediapipe_", "*")))
- for f in REQUIRED_BLENDER_INPUT_FILES
+ if detector != "mediapipe":
+ message = (
+ f"Blender export skipped: recording was processed with '{detector}', but the "
+ "freemocap_blender_addon only supports MediaPipe output so far. Re-process with "
+ "MediaPipe to export to Blender."
)
- if non_mediapipe_equivalents_present:
- logger.warning(
- "Blender export skipped: the freemocap_blender_addon only supports recordings "
- "processed with MediaPipe. Re-process with MediaPipe to export to Blender."
- )
- else:
- logger.error("Missing required files to run AJC addon, did something go wrong during processing?")
- raise
+ logger.warning(message)
+ raise ValueError(message)
+
+ raise_if_not_blender_ready(recording_folder_path,
+ detector = detector)
if blender_exe_path is None:
blender_exe_path:Path = Path(get_best_guess_of_blender_path())
diff --git a/freemocap/core/pipeline/posthoc/posthoc_pipeline_manager.py b/freemocap/core/pipeline/posthoc/posthoc_pipeline_manager.py
index f22ec6db..19bbf0c7 100644
--- a/freemocap/core/pipeline/posthoc/posthoc_pipeline_manager.py
+++ b/freemocap/core/pipeline/posthoc/posthoc_pipeline_manager.py
@@ -26,7 +26,7 @@ from freemocap.core.tasks.calibration.posthoc_calibration_task import run_postho
from freemocap.core.tasks.mocap.mocap_task_config import PosthocMocapPipelineConfig
from freemocap.core.tasks.mocap.posthoc_mocap_task import run_posthoc_mocap_aggregator_task
from freemocap.core.types.type_overloads import PipelineIdString
-from freemocap.core.pipeline.posthoc.progress_messages import PipelineProgressMessage
+from freemocap.core.pipeline.posthoc.progress_messages import AggregatorNodeProgressMessage, PipelineProgressMessage
logger = logging.getLogger(__name__)
@@ -45,6 +45,10 @@ class PosthocPipelineManager(PipelineManagerABC):
worker_registry: WorkerRegistry
lock: multiprocessing.synchronize.Lock = field(default_factory=multiprocessing.Lock)
pipelines: dict[PipelineIdString, PosthocPipeline] = field(default_factory=dict)
+ # Synthetic terminal messages for pipelines stopped manually (via stop_pipeline/
+ # stop_all_pipelines), which never emit their own terminal COMPLETE/FAILED message
+ # since they're killed rather than left to finish. Drained by get_progress_updates().
+ pending_stop_messages: list[PipelineProgressMessage] = field(default_factory=list)
# ------------------------------------------------------------------
# Lazy cleanup
@@ -173,10 +177,23 @@ class PosthocPipelineManager(PipelineManagerABC):
# Lifecycle
# ------------------------------------------------------------------
+ def _stopped_by_user_message(self, pipeline: PosthocPipeline) -> AggregatorNodeProgressMessage:
+ return AggregatorNodeProgressMessage(
+ pipeline_id=pipeline.id,
+ pipeline_type=str(pipeline.pipeline_type),
+ phase="failed",
+ progress_fraction=0.0,
+ detail="Stopped by user",
+ recording_name=pipeline.recording_info.recording_name,
+ recording_path=str(pipeline.recording_info.full_recording_path),
+ )
+
def stop_pipeline(self, pipeline_id: PipelineIdString) -> bool:
"""Shutdown a single pipeline by ID. Returns True if found, False if not."""
with self.lock:
pipeline = self.pipelines.pop(pipeline_id, None)
+ if pipeline is not None:
+ self.pending_stop_messages.append(self._stopped_by_user_message(pipeline))
if pipeline is None:
logger.warning(f"stop_pipeline: pipeline [{pipeline_id}] not found")
return False
@@ -189,6 +206,9 @@ class PosthocPipelineManager(PipelineManagerABC):
with self.lock:
pipelines = list(self.pipelines.values())
self.pipelines.clear()
+ self.pending_stop_messages.extend(
+ self._stopped_by_user_message(pipeline) for pipeline in pipelines
+ )
for pipeline in pipelines:
pipeline.shutdown()
logger.info(f"Stopped {len(pipelines)} posthoc pipeline(s)")
@@ -207,7 +227,10 @@ class PosthocPipelineManager(PipelineManagerABC):
logger.info("PosthocPipelineManager: all pipelines shut down")
def get_progress_updates(self) -> list[PipelineProgressMessage]:
- progress_messages: list[PipelineProgressMessage] = []
+ with self.lock:
+ stop_messages, self.pending_stop_messages = self.pending_stop_messages, []
+
+ progress_messages: list[PipelineProgressMessage] = list(stop_messages)
for pipeline in self.pipelines.values():
progress_messages.extend(pipeline.get_progress_messages())
diff --git a/freemocap/core/tasks/calibration/posthoc_calibration_task.py b/freemocap/core/tasks/calibration/posthoc_calibration_task.py
index 0165b7db..889ab2ce 100644
--- a/freemocap/core/tasks/calibration/posthoc_calibration_task.py
+++ b/freemocap/core/tasks/calibration/posthoc_calibration_task.py
@@ -176,7 +176,14 @@ def _run_pyceres_path(
video_metadata: dict[CameraIdString, VideoMetadata],
) -> tuple[CalibrationResult, GroundPlaneResult | None]:
"""Run calibration using the pyceres bundle adjustment solver."""
- from freemocap.core.tasks.calibration.pyceres_calibration.pyceres_calibration_pipeline import run_pyceres_calibration
+ try:
+ from freemocap.core.tasks.calibration.pyceres_calibration.pyceres_calibration_pipeline import run_pyceres_calibration
+ except ImportError as e:
+ raise RuntimeError(
+ "The 'Accurate' calibration solver requires the optional `pyceres` package, "
+ "which is not installed in this environment. Install it with "
+ "`uv sync --group pyceres`, or select the 'Anipose legacy' solver instead."
+ ) from e
if len(all_observations) == 0:
raise ValueError("No valid charuco observations found")
diff --git a/freemocap/core/tasks/mocap/mocap_helpers/recording_framerate.py b/freemocap/core/tasks/mocap/mocap_helpers/recording_framerate.py
new file mode 100644
index 00000000..c519e7a0
--- /dev/null
+++ b/freemocap/core/tasks/mocap/mocap_helpers/recording_framerate.py
@@ -0,0 +1,125 @@
+"""Derive a recording's true framerate from the timestamps written alongside its videos.
+
+`FilterConfig.sampling_rate` defaults to 30.0 and nothing ever set it from the actual
+recording, so the post-processing Butterworth low-pass was designed against a framerate
+the capture never had. The cutoff scales with that error: a nominal 6 Hz cutoff becomes
+`6 * true_fps / 30` in reality. At 31 fps that is a mild 6.2 Hz; at 60 fps it is 12 Hz,
+which lets through most of the noise the filter exists to remove.
+
+The per-camera fps reported by the video containers cannot be used for this - the four
+cameras in a synchronized recording disagree with each other (34.28 / 34.48 / 34.66 /
+34.74 in one measured take) while sharing an identical frame count, because those values
+describe each camera's own nominal rate rather than the synchronized multiframe rate.
+The multiframe timestamps are the only record of the rate the frames actually share.
+
+skellycam already computes this median for its `*_stats.json` report, so that's tried
+first - it's a single field read instead of a full CSV re-parse. Older recordings (and,
+until skellycam's `RecordingTimestampsStats.to_json` bug is fixed, current ones too) can
+have an empty stats.json, so the CSV median below remains as a fallback.
+"""
+import json
+import logging
+from pathlib import Path
+
+import pandas as pd
+
+logger = logging.getLogger(__name__)
+
+# Recordings vary in layout between versions, so search rather than assume one path.
+_TIMESTAMP_GLOBS = (
+ "synchronized_videos/timestamps/*_timestamps.csv",
+ "synchronized_videos/timestamps/**/*timestamps.csv",
+)
+_STATS_JSON_GLOBS = (
+ "synchronized_videos/timestamps/*_stats.json",
+ "synchronized_videos/timestamps/**/*stats.json",
+)
+# Fixed by skellycam's MULTI_FRAME_TIMESTAMP_CSV_ROW dtype - the same column
+# skellycam's own framerate_stats.median in *_stats.json is computed from.
+_FRAMERATE_COLUMN = "from_previous.framerate.hz"
+_MIN_SAMPLES = 10
+# Anything outside this is more likely a parsing error than a real capture rate.
+_PLAUSIBLE_FPS = (1.0, 1000.0)
+
+
+def _find_timestamp_csv(recording_path: Path) -> Path | None:
+ for pattern in _TIMESTAMP_GLOBS:
+ for candidate in sorted(recording_path.glob(pattern)):
+ if candidate.is_file() and candidate.stat().st_size > 0:
+ return candidate
+ return None
+
+
+def _find_stats_json(recording_path: Path) -> Path | None:
+ for pattern in _STATS_JSON_GLOBS:
+ for candidate in sorted(recording_path.glob(pattern)):
+ if candidate.is_file() and candidate.stat().st_size > 0:
+ return candidate
+ return None
+
+
+def _framerate_from_stats_json(recording_path: Path) -> tuple[float, Path] | None:
+ json_path = _find_stats_json(recording_path)
+ if json_path is None:
+ return None
+
+ try:
+ stats = json.loads(json_path.read_text())
+ except (OSError, json.JSONDecodeError):
+ logger.warning(f"Could not parse {json_path}; falling back to CSV")
+ return None
+
+ median = stats.get("framerate_stats", {}).get("median")
+ if median is None:
+ # Empty until skellycam's RecordingTimestampsStats.to_json bug is fixed;
+ # not an error, just means this recording needs the CSV fallback.
+ return None
+
+ return float(median), json_path
+
+
+def _median_framerate_from_csv(csv_path: Path) -> float | None:
+ values = pd.read_csv(csv_path, usecols=[_FRAMERATE_COLUMN])[_FRAMERATE_COLUMN].dropna()
+ values = values[values > 0]
+ if len(values) < _MIN_SAMPLES:
+ return None
+ # Median, not mean: dropped frames produce double-length intervals that would
+ # drag a mean downward and understate the true rate.
+ return float(values.median())
+
+
+def get_recording_framerate(recording_path: str | Path) -> float | None:
+ """Return the recording's median framerate in fps, or None if it cannot be determined.
+
+ Returns None rather than a default so callers can decide whether to fall back or
+ fail - silently substituting a plausible-looking number is what caused the original
+ bug this function exists to fix.
+ """
+ recording_path = Path(recording_path)
+
+ from_json = _framerate_from_stats_json(recording_path)
+ if from_json is not None:
+ framerate, json_path = from_json
+ low, high = _PLAUSIBLE_FPS
+ if low <= framerate <= high:
+ logger.info(f"Derived recording framerate: {framerate:.3f} fps (from {json_path.name})")
+ return framerate
+ logger.warning(f"Derived implausible framerate {framerate:.2f} fps from {json_path}; falling back to CSV")
+
+ csv_path = _find_timestamp_csv(recording_path)
+ if csv_path is None:
+ logger.warning(f"No timestamps CSV found under {recording_path}; cannot determine framerate")
+ return None
+
+ framerate = _median_framerate_from_csv(csv_path)
+ if framerate is None:
+ logger.warning(f"Could not read usable framerates from {csv_path}")
+ return None
+
+ low, high = _PLAUSIBLE_FPS
+ if not (low <= framerate <= high):
+ logger.warning(f"Derived implausible framerate {framerate:.2f} fps from {csv_path}; ignoring")
+ return None
+
+ logger.info(f"Derived recording framerate: {framerate:.3f} fps (from {csv_path.name})")
+ return framerate
diff --git a/freemocap/core/tasks/mocap/posthoc_mocap_task.py b/freemocap/core/tasks/mocap/posthoc_mocap_task.py
index 3df2fa45..bbcb1b9d 100644
--- a/freemocap/core/tasks/mocap/posthoc_mocap_task.py
+++ b/freemocap/core/tasks/mocap/posthoc_mocap_task.py
@@ -29,6 +29,7 @@ from freemocap.core.blender.export_to_blender import export_to_blender
from freemocap.core.pipeline.posthoc.pipeline_phases import MocapStage
from freemocap.core.pipeline.posthoc.task_progress_reporter import TaskProgressReporter
from freemocap.core.tasks.calibration.shared.calibration_paths import get_last_successful_calibration_toml_path
+from freemocap.core.tasks.mocap.mocap_helpers.recording_framerate import get_recording_framerate
from freemocap.core.tasks.mocap.mocap_helpers.skeleton_from_mediapipe_observations import \
skeleton_from_mediapipe_observation_recorders
from freemocap.core.tracking.observation_buffer import ObservationBuffer
@@ -101,6 +102,28 @@ def run_posthoc_mocap_aggregator_task(
else:
logger.info(f"Calibration file already in recording folder, skipping copy: {recording_calibration_copy}")
+ # ---- Match the post-processing filter to the recording's real framerate ----
+ # FilterConfig.sampling_rate defaults to 30.0 and was never set from the capture, so
+ # the Butterworth low-pass was designed for a framerate the recording never had. The
+ # effective cutoff scales with the error: at 31 fps a nominal 6 Hz cutoff is really
+ # 6.2 Hz; at 60 fps it is 12 Hz, which lets through most of what the filter exists to
+ # remove.
+ filter_config = task_config.filter_config
+ true_fps = get_recording_framerate(recording_folder)
+ if true_fps is None:
+ logger.warning(
+ f"Could not determine recording framerate; leaving filter sampling_rate at "
+ f"{filter_config.sampling_rate} Hz. The {filter_config.cutoff} Hz cutoff will be "
+ f"wrong by whatever margin the real rate differs."
+ )
+ elif abs(true_fps - filter_config.sampling_rate) > 0.01:
+ logger.info(
+ f"Setting filter sampling_rate {filter_config.sampling_rate} -> {true_fps:.3f} Hz "
+ f"(effective cutoff was {filter_config.cutoff * true_fps / filter_config.sampling_rate:.2f} Hz "
+ f"instead of the requested {filter_config.cutoff} Hz)"
+ )
+ filter_config = filter_config.model_copy(update={"sampling_rate": true_fps})
+
# ---- Run skeleton triangulation ----
_reporter.report(stage=MocapStage.TRIANGULATING, detail="Triangulating skeleton")
logger.info("Starting skeleton triangulation...")
@@ -112,7 +135,7 @@ def run_posthoc_mocap_aggregator_task(
observation_recorders=observation_recorders,
path_to_calibration_toml=calibration_toml_path,
path_to_output_data_folder=output_folder,
- filter_config=task_config.filter_config,
+ filter_config=filter_config,
triangulation_config=task_config.triangulation_config
)
@@ -131,6 +154,7 @@ def run_posthoc_mocap_aggregator_task(
recording_folder_path=str(recording_info.full_recording_path),
blender_exe_path=task_config.blender_exe_path,
open_file_on_completion=task_config.auto_open_blend_file,
+ detector = task_config.detector_type
)
except Exception as e:
# Don't crash the whole aggregator if blender export fails —
diff --git a/freemocap/system/recording_status/recording_status.py b/freemocap/system/recording_status/recording_status.py
index 6526dde4..ac0f9fb6 100644
--- a/freemocap/system/recording_status/recording_status.py
+++ b/freemocap/system/recording_status/recording_status.py
@@ -18,21 +18,54 @@ OUTPUT_DATA_FOLDER_NAME = "output_data"
VIDEO_EXTENSIONS = {".mp4", ".avi", ".mov", ".mkv", ".webm"}
-REQUIRED_BLENDER_INPUT_FILES: list[str] = [
- "mediapipe_body_3d_xyz.npy",
- "mediapipe_right_hand_3d_xyz.npy",
- "mediapipe_left_hand_3d_xyz.npy",
- "mediapipe_face_3d_xyz.npy",
- "mediapipe_body_total_body_center_of_mass.npy",
- "mediapipe_body_segment_center_of_mass.npy",
-]
+def _blender_input_files_for(detector: str) -> list[str]:
+ """The .npy files the Blender add-on needs, for a given detector's output."""
+ return [
+ f"{detector}_body_3d_xyz.npy",
+ f"{detector}_right_hand_3d_xyz.npy",
+ f"{detector}_left_hand_3d_xyz.npy",
+ f"{detector}_face_3d_xyz.npy",
+ f"{detector}_body_total_body_center_of_mass.npy",
+ f"{detector}_body_segment_center_of_mass.npy",
+ ]
+
+
+# Output filenames are prefixed with the detector that produced them, so the required
+# set depends on which detector ran. This used to be a flat mediapipe-only list, which
+# meant an rtmpose recording always failed the pre-flight check with "missing
+# mediapipe_*.npy" and could never be exported to Blender at all.
+BLENDER_INPUT_FILES_BY_DETECTOR: dict[str, list[str]] = {
+ "rtmpose": _blender_input_files_for("rtmpose"),
+ "mediapipe": _blender_input_files_for("mediapipe"),
+}
+
+# Kept for backwards compatibility with callers that import this name directly.
+REQUIRED_BLENDER_INPUT_FILES: list[str] = BLENDER_INPUT_FILES_BY_DETECTOR["mediapipe"]
+
+DEFAULT_BLENDER_INPUT_DETECTOR = "mediapipe"
LEGACY_BLENDER_INPUT_FILENAMES: dict[str, str] = {
"mediapipe_right_hand_3d_xyz.npy": "mediapipe_right_hand_right_hand.npy",
"mediapipe_left_hand_3d_xyz.npy": "mediapipe_left_hand_left_hand.npy",
+ "rtmpose_right_hand_3d_xyz.npy": "rtmpose_right_hand_right_hand.npy",
+ "rtmpose_left_hand_3d_xyz.npy": "rtmpose_left_hand_left_hand.npy",
}
+
+def detect_blender_input_detector(output_data: Path) -> str:
+ """Which detector's output is present in this folder.
+
+ Picks whichever detector actually has a body file on disk rather than assuming one,
+ so a recording processed with either detector passes its own pre-flight check.
+ Falls back to the default so the caller still gets a useful "missing files" list
+ naming real filenames instead of an empty one.
+ """
+ for detector in BLENDER_INPUT_FILES_BY_DETECTOR:
+ if (output_data / f"{detector}_body_3d_xyz.npy").exists():
+ return detector
+ return DEFAULT_BLENDER_INPUT_DETECTOR
+
STAGE_RAW_VIDEOS = "Synchronized videos"
STAGE_CALIBRATION = "Calibration"
STAGE_BLENDER_INPUTS = "Blender input data (.npy)"
@@ -77,19 +110,21 @@ class RecordingStatus(BaseModel):
def missing_blender_input_files(
recording_folder_path: str | Path,
+ detector: str
) -> list[str]:
output_data = Path(recording_folder_path) / OUTPUT_DATA_FOLDER_NAME
return [
name
- for name in REQUIRED_BLENDER_INPUT_FILES
+ for name in BLENDER_INPUT_FILES_BY_DETECTOR[detector]
if not _find_blender_input_file(output_data, name).exists()
]
-def raise_if_not_blender_ready(recording_folder_path: str|Path) -> None:
+def raise_if_not_blender_ready(recording_folder_path: str|Path,
+ detector:str) -> None:
"""Pre-flight check for export_to_blender. Raises FileNotFoundError listing all missing files."""
- missing = missing_blender_input_files(recording_folder_path)
+ missing = missing_blender_input_files(recording_folder_path, detector)
if missing:
output_data = Path(recording_folder_path) / OUTPUT_DATA_FOLDER_NAME
raise FileNotFoundError(
@@ -189,13 +224,14 @@ def _build_blender_inputs_stage(
recording_folder: Path,
) -> StageStatus:
output_data = recording_folder / OUTPUT_DATA_FOLDER_NAME
+ detector = detect_blender_input_detector(output_data)
files = [
_file_status(
_find_blender_input_file(output_data, name),
display_name=name,
)
- for name in REQUIRED_BLENDER_INPUT_FILES
+ for name in BLENDER_INPUT_FILES_BY_DETECTOR[detector]
]
present = sum(1 for file_status in files if file_status.exists)
diff --git a/freemocap/tests/http/test_mocap_router_import.py b/freemocap/tests/http/test_mocap_router_import.py
new file mode 100644
index 00000000..16208cee
--- /dev/null
+++ b/freemocap/tests/http/test_mocap_router_import.py
@@ -0,0 +1,142 @@
+from pathlib import Path
+
+import cv2
+import numpy as np
+import pytest
+from fastapi import FastAPI
+from fastapi.testclient import TestClient
+
+from freemocap.api.http.mocap.mocap_router import mocap_router
+
+
+def client():
+ test_app = FastAPI()
+ test_app.include_router(mocap_router)
+ return TestClient(test_app)
+
+
+def _make_video_file(tmp_path: Path, name: str, num_frames: int = 5) -> Path:
+ """Write a small real video file so cv2 can read its frame count/fps."""
+ video_path = tmp_path / name
+ writer = cv2.VideoWriter(
+ str(video_path), cv2.VideoWriter_fourcc(*"mp4v"), 30.0, (16, 16)
+ )
+ for _ in range(num_frames):
+ writer.write(np.zeros((16, 16, 3), dtype=np.uint8))
+ writer.release()
+ return video_path
+
+
+class TestImportVideos:
+ def test_import_creates_recording_structure_and_copies_videos(self, tmp_path, client):
+ source_dir = tmp_path / "source"
+ source_dir.mkdir()
+ video_a = _make_video_file(source_dir, "cam0.mp4")
+ video_b = _make_video_file(source_dir, "cam1.mp4")
+
+ base_directory = tmp_path / "recordings"
+
+ response = client.post("/mocap/recording/import", json={
+ "videoPaths": [str(video_a), str(video_b)],
+ "recordingName": "my_import_test",
+ "baseDirectory": str(base_directory),
+ })
+
+ assert response.status_code == 200
+ body = response.json()
+ assert body["success"] is True
+ assert body["recording_name"] == "my_import_test"
+ assert body["video_count"] == 2
+
+ recording_path = Path(body["recording_path"])
+ synced_dir = recording_path / "synchronized_videos"
+ assert (synced_dir / "cam0.mp4").is_file()
+ assert (synced_dir / "cam1.mp4").is_file()
+ assert (synced_dir / "cam0.mp4").read_bytes() == video_a.read_bytes()
+
+ # Only the synchronized_videos folder should be created — no videos/annotated,
+ # output, or logs scaffolding for a bare import.
+ assert sorted(p.name for p in recording_path.iterdir()) == ["synchronized_videos"]
+
+ def test_import_auto_generates_recording_name_when_omitted(self, tmp_path, client):
+ source_dir = tmp_path / "source"
+ source_dir.mkdir()
+ video_a = _make_video_file(source_dir, "only_cam.mp4")
+ base_directory = tmp_path / "recordings"
+
+ response = client.post("/mocap/recording/import", json={
+ "videoPaths": [str(video_a)],
+ "baseDirectory": str(base_directory),
+ })
+
+ assert response.status_code == 200
+ body = response.json()
+ assert "imported" in body["recording_name"]
+
+ def test_import_rejects_empty_video_list(self, client):
+ response = client.post("/mocap/recording/import", json={"videoPaths": []})
+ assert response.status_code == 400
+
+ def test_import_rejects_missing_video_file(self, tmp_path, client):
+ base_directory = tmp_path / "recordings"
+ response = client.post("/mocap/recording/import", json={
+ "videoPaths": [str(tmp_path / "does_not_exist.mp4")],
+ "baseDirectory": str(base_directory),
+ })
+ assert response.status_code == 400
+
+ def test_import_rejects_unsynchronized_videos(self, tmp_path, client):
+ source_dir = tmp_path / "source"
+ source_dir.mkdir()
+ video_a = _make_video_file(source_dir, "cam0.mp4", num_frames=5)
+ video_b = _make_video_file(source_dir, "cam1.mp4", num_frames=10)
+ base_directory = tmp_path / "recordings"
+
+ response = client.post("/mocap/recording/import", json={
+ "videoPaths": [str(video_a), str(video_b)],
+ "baseDirectory": str(base_directory),
+ })
+
+ assert response.status_code == 400
+ assert not base_directory.exists()
+
+
+class TestCheckVideoSync:
+ def test_check_sync_reports_synchronized_when_frame_counts_match(self, tmp_path, client):
+ video_a = _make_video_file(tmp_path, "cam0.mp4", num_frames=5)
+ video_b = _make_video_file(tmp_path, "cam1.mp4", num_frames=5)
+
+ response = client.post("/mocap/recording/check_sync", json={
+ "videoPaths": [str(video_a), str(video_b)],
+ })
+
+ assert response.status_code == 200
+ body = response.json()
+ assert body["synchronized"] is True
+ assert body["detail"] is None
+ assert {v["frame_count"] for v in body["videos"]} == {5}
+
+ def test_check_sync_reports_unsynchronized_when_frame_counts_differ(self, tmp_path, client):
+ video_a = _make_video_file(tmp_path, "cam0.mp4", num_frames=5)
+ video_b = _make_video_file(tmp_path, "cam1.mp4", num_frames=10)
+
+ response = client.post("/mocap/recording/check_sync", json={
+ "videoPaths": [str(video_a), str(video_b)],
+ })
+
+ assert response.status_code == 200
+ body = response.json()
+ assert body["synchronized"] is False
+ assert body["detail"] is not None
+ assert len(body["videos"]) == 2
+
+ def test_check_sync_rejects_empty_video_list(self, client):
+ response = client.post("/mocap/recording/check_sync", json={"videoPaths": []})
+ assert response.status_code == 400
+
+ def test_check_sync_rejects_missing_video_file(self, tmp_path, client):
+ response = client.post("/mocap/recording/check_sync", json={
+ "videoPaths": [str(tmp_path / "does_not_exist.mp4")],
+ })
+ assert response.status_code == 400
diff --git a/uv.lock b/uv.lock
index ce3e8879..9fd296bd 100644
--- a/uv.lock
+++ b/uv.lock
@@ -371,7 +371,7 @@ wheels = [
[[package]]
name = "freemocap"
-version = "2.0.0a19"
+version = "2.0.0a20"
source = { editable = "." }
dependencies = [
{ name = "beartype" },
@@ -475,7 +475,7 @@ tracker-default = [
[[package]]
name = "freemocap-blender-addon"
version = "2026.4.1041"
-source = { git = "https://github.com/freemocap/freemocap_blender_addon?branch=main#980ae856b5575abfaae51bbfc2fd2158f07ecd12" }
+source = { git = "https://github.com/freemocap/freemocap_blender_addon?branch=main#32f49dd8c91f463f5a9b6335b47469bf091965f0" }
[[package]]
name = "h11"
@@ -1240,27 +1240,27 @@ wheels = [
[[package]]
name = "polars"
-version = "1.43.0"
+version = "1.43.2"
source = { registry = "https://pypi.org/simple" }
dependencies = [
{ name = "polars-runtime-32" },
]
-sdist = { url = "https://files.pythonhosted.org/packages/66/5b/5d0f0aa53c6e9a8ecbc99ff502edcf9584e5d08ab34ea407c086999103d5/polars-1.43.0.tar.gz", hash = "sha256:bb2c67553e4968c18dfe268a88ff9a5790d5c2e0b7ea7efe97640b9a90438c88", size = 749537, upload-time = "2026-07-21T04:30:25.966Z" }
+sdist = { url = "https://files.pythonhosted.org/packages/89/13/3873f213304bcbaaf39e63c8b905ceb460a0524448d57f86a829f6d4d0fd/polars-1.43.2.tar.gz", hash = "sha256:c699671b99eb71ff53334d237917aaa3db5ad4dda480abcb6c80e0eaee7b677b", size = 750312, upload-time = "2026-08-01T06:28:30.872Z" }
wheels = [
- { url = "https://files.pythonhosted.org/packages/76/28/a8eac2c1d1b2d2a4ba2eb745921616d863185d94b1afd91cbb07af9ef21a/polars-1.43.0-py3-none-any.whl", hash = "sha256:c49078b14e2d6b8ff5cc5b78b6d9638603ea5dffafb889d9204818822f55b813", size = 846493, upload-time = "2026-07-21T04:29:06.68Z" },
+ { url = "https://files.pythonhosted.org/packages/2b/fe/0888040a24e4504098b85d8ad486b14cb01cf6b030bbe479dfc2dcffc2ac/polars-1.43.2-py3-none-any.whl", hash = "sha256:22aa0cb92a1ee2d60d6a15a638b2e8e0dd99aea21ac0cd8fb29da8e382e075a9", size = 847150, upload-time = "2026-08-01T06:27:15.543Z" },
]
[[package]]
name = "polars-runtime-32"
-version = "1.43.0"
+version = "1.43.2"
source = { registry = "https://pypi.org/simple" }
-sdist = { url = "https://files.pythonhosted.org/packages/86/96/7e714cad082e9e6aaebb8886fcb1b0220d5c35149d4c8d3466bd7e7d581e/polars_runtime_32-1.43.0.tar.gz", hash = "sha256:5fb47a3a883402e62eab2fde5922f78c531d037aeece3640c15225f39228621e", size = 3090044, upload-time = "2026-07-21T04:30:27.185Z" }
+sdist = { url = "https://files.pythonhosted.org/packages/d4/06/11b578eeef05f867e3ee31b2a2fdd8e7684c2aa47822c49935d1be789c38/polars_runtime_32-1.43.2.tar.gz", hash = "sha256:d7b7c486bccee75a6af0158b87077da3d054657e3c60036b28644f4e1c7fdbf7", size = 3095669, upload-time = "2026-08-01T06:28:32.315Z" }
wheels = [
- { url = "https://files.pythonhosted.org/packages/0f/14/9b1f5eb1c5104ba1ceb380a7308ffcd979f3ce1df86e76293062698f2ff1/polars_runtime_32-1.43.0-cp310-abi3-macosx_10_12_x86_64.whl", hash = "sha256:6707193d30a7135bce0424304f76d8145270527444097548e794ad8d26823b70", size = 53059463, upload-time = "2026-07-21T04:29:09.194Z" },
- { url = "https://files.pythonhosted.org/packages/ca/14/73d77d1c0c928eb599d9516d874af0cd2b6225201e1327a6c4857e6776d0/polars_runtime_32-1.43.0-cp310-abi3-macosx_11_0_arm64.whl", hash = "sha256:78ca2f97740b2a6beb36eb112749280b5e08750c60f53c08d2feffebdba9d35a", size = 47499586, upload-time = "2026-07-21T04:29:13.229Z" },
- { url = "https://files.pythonhosted.org/packages/ab/7d/24ae73389aac03296925973c4e2cbe2e4982e859b9fad69eb1a72b9026fa/polars_runtime_32-1.43.0-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:3ecc8feaf04de5989a29245885921db612ef1ce9065e5cb6ec37495acfa55bba", size = 57266705, upload-time = "2026-07-21T04:29:19.288Z" },
- { url = "https://files.pythonhosted.org/packages/db/e2/047c7695f08a9b18614c0e1ec5e70a754455542a21a6d52955f7f05c6268/polars_runtime_32-1.43.0-cp310-abi3-musllinux_1_2_x86_64.whl", hash = "sha256:9cd8b813afe67d59e87027dedcaf5c6a06fe602472fd74e1a49f4bafea47259c", size = 55169401, upload-time = "2026-07-21T04:29:25.902Z" },
- { url = "https://files.pythonhosted.org/packages/92/dc/bfd2533c487563c7a21ab7d7af3d78f820b0236e14dc5ee63d46188cd275/polars_runtime_32-1.43.0-cp310-abi3-win_amd64.whl", hash = "sha256:41a75fb3cb4cc574eb21801383578f75cfc374597c22322ef457ab7bac8a3301", size = 52541527, upload-time = "2026-07-21T04:29:29.162Z" },
+ { url = "https://files.pythonhosted.org/packages/59/fc/12e6d4ca34d820297651134cfa35f86c33e898539fc6629cbb35d0089697/polars_runtime_32-1.43.2-cp310-abi3-macosx_10_12_x86_64.whl", hash = "sha256:91abf205d4ec93f92ba95386b7f8776559ae3dfce425ed2e527efa75d117d04a", size = 53088908, upload-time = "2026-08-01T06:27:18.268Z" },
+ { url = "https://files.pythonhosted.org/packages/32/81/833b0853551deb810854f96b43dea342b6e6c9b0ea1afcccf774157d519d/polars_runtime_32-1.43.2-cp310-abi3-macosx_11_0_arm64.whl", hash = "sha256:2cc3ff96fd44789b02eb5c15b98dfcb000101636b177d3034fae2feec19b118f", size = 47540529, upload-time = "2026-08-01T06:27:21.391Z" },
+ { url = "https://files.pythonhosted.org/packages/62/60/64deacb3abc70c52e2d88a808a052d1621c86a48fe9194f2c065579ab1cd/polars_runtime_32-1.43.2-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:6d5a7ae004a2723ebf4427f6d6a639f30f86af4cf077075f6b35d04711154fc3", size = 57304599, upload-time = "2026-08-01T06:27:27.875Z" },
+ { url = "https://files.pythonhosted.org/packages/b6/5a/2deb8eac70e9a2ac26d88a66ae7cf52612865026f4f4a5e7ab11ad9d52bf/polars_runtime_32-1.43.2-cp310-abi3-musllinux_1_2_x86_64.whl", hash = "sha256:452b400e59e7f56e4c6437f435e796903272a9388feee12de2bea049ae87025e", size = 55204471, upload-time = "2026-08-01T06:27:33.886Z" },
+ { url = "https://files.pythonhosted.org/packages/29/9e/647401ae8a607bc0cc40ed7b8592d5b1be90ded0dc9b9d6d3aeb03f9524b/polars_runtime_32-1.43.2-cp310-abi3-win_amd64.whl", hash = "sha256:00e33c28e321410c8d66e814a90043101e3bdd9ed2c6dabda07565aa8adbbdf1", size = 52572176, upload-time = "2026-08-01T06:27:37.048Z" },
]
[[package]]
@@ -1930,7 +1930,7 @@ wheels = [
[[package]]
name = "skellycam"
version = "2.0.0a6"
-source = { git = "https://github.com/freemocap/skellycam?branch=main#777b058ceafb578c55092179506cd8a925a38b50" }
+source = { git = "https://github.com/freemocap/skellycam?branch=main#d091ecef176a83bb1bc648bdf5f2ee702e2612da" }
dependencies = [
{ name = "av" },
{ name = "beartype" },