Spaces:
Running
Running
Upload 51 files
Browse files
src/components/MultiSourceCaptioningView.tsx
CHANGED
@@ -88,6 +88,33 @@ export default function MultiSourceCaptioningView() {
|
|
88 |
const webcamStreamRef = useRef<MediaStream | null>(null);
|
89 |
const { isLoaded, isLoading, error: modelError, runInference } = useVLMContext();
|
90 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
91 |
const processVideoFrame = async () => {
|
92 |
if (!videoRef.current || !canvasRef.current) return;
|
93 |
const video = videoRef.current;
|
|
|
88 |
const webcamStreamRef = useRef<MediaStream | null>(null);
|
89 |
const { isLoaded, isLoading, error: modelError, runInference } = useVLMContext();
|
90 |
|
91 |
+
// Add this useEffect for overlay video synchronization
|
92 |
+
useEffect(() => {
|
93 |
+
const main = videoRef.current;
|
94 |
+
const overlay = overlayVideoRef.current;
|
95 |
+
if (!main || !overlay) return;
|
96 |
+
// Sync play/pause
|
97 |
+
const onPlay = () => { if (overlay.paused) overlay.play(); };
|
98 |
+
const onPause = () => { if (!overlay.paused) overlay.pause(); };
|
99 |
+
// Sync seeking and time
|
100 |
+
const onSeekOrTime = () => {
|
101 |
+
if (Math.abs(main.currentTime - overlay.currentTime) > 0.05) {
|
102 |
+
overlay.currentTime = main.currentTime;
|
103 |
+
}
|
104 |
+
};
|
105 |
+
main.addEventListener('play', onPlay);
|
106 |
+
main.addEventListener('pause', onPause);
|
107 |
+
main.addEventListener('seeked', onSeekOrTime);
|
108 |
+
main.addEventListener('timeupdate', onSeekOrTime);
|
109 |
+
// Clean up
|
110 |
+
return () => {
|
111 |
+
main.removeEventListener('play', onPlay);
|
112 |
+
main.removeEventListener('pause', onPause);
|
113 |
+
main.removeEventListener('seeked', onSeekOrTime);
|
114 |
+
main.removeEventListener('timeupdate', onSeekOrTime);
|
115 |
+
};
|
116 |
+
}, [videoRef, overlayVideoRef, uploadedUrl, videoUrl, mode]);
|
117 |
+
|
118 |
const processVideoFrame = async () => {
|
119 |
if (!videoRef.current || !canvasRef.current) return;
|
120 |
const video = videoRef.current;
|