Quazim0t0 commited on
Commit
73be173
·
verified ·
1 Parent(s): 7599655

Upload 37 files

Browse files
src/components/MultiSourceCaptioningView.tsx CHANGED
@@ -112,67 +112,52 @@ export default function MultiSourceCaptioningView() {
112
  };
113
  }, [mode]);
114
 
115
- // Replace setInterval-based frame processing with an async loop for all video modes
116
- // Example for webcam mode:
117
  useEffect(() => {
118
  if (mode !== "Webcam" || !isLoaded || !webcamActive) return;
119
- let running = true;
120
- async function processLoop() {
121
- while (running) {
122
- if (videoRef.current && !videoRef.current.paused && !videoRef.current.ended && videoRef.current.videoWidth > 0) {
123
- await processVideoFrame();
124
- }
125
- await new Promise(res => setTimeout(res, 1000)); // 1 FPS
126
- }
127
- }
128
- processLoop();
129
- return () => { running = false; };
130
  }, [mode, isLoaded, prompt, runInference, webcamActive]);
131
 
132
- // Repeat for URL, File video, Example video modes:
133
  useEffect(() => {
134
  if (mode !== "URL" || !isLoaded || !urlProcessing) return;
135
- let running = true;
136
- async function processLoop() {
137
- while (running) {
138
- if (videoRef.current && !videoRef.current.paused && !videoRef.current.ended && videoRef.current.videoWidth > 0) {
139
- await processVideoFrame();
140
- }
141
- await new Promise(res => setTimeout(res, 1000));
142
- }
143
- }
144
- processLoop();
145
- return () => { running = false; };
146
  }, [mode, isLoaded, prompt, runInference, urlProcessing]);
147
 
 
148
  useEffect(() => {
149
  if (mode !== "File" || !isLoaded || !uploadedFile || !isVideoFile(uploadedFile) || !videoProcessing) return;
150
- let running = true;
151
- async function processLoop() {
152
- while (running) {
153
- if (videoRef.current && !videoRef.current.paused && !videoRef.current.ended && videoRef.current.videoWidth > 0) {
154
- await processVideoFrame();
155
- }
156
- await new Promise(res => setTimeout(res, 1000));
157
- }
158
- }
159
- processLoop();
160
- return () => { running = false; };
161
  }, [mode, isLoaded, prompt, runInference, uploadedFile, videoProcessing]);
162
 
 
163
  useEffect(() => {
164
  if (mode !== "File" || uploadedFile || !isLoaded || !exampleProcessing) return;
165
- let running = true;
166
- async function processLoop() {
167
- while (running) {
168
- if (videoRef.current && !videoRef.current.paused && !videoRef.current.ended && videoRef.current.videoWidth > 0) {
169
- await processVideoFrame();
170
- }
171
- await new Promise(res => setTimeout(res, 1000));
172
- }
173
- }
174
- processLoop();
175
- return () => { running = false; };
176
  }, [mode, isLoaded, prompt, runInference, uploadedFile, exampleProcessing]);
177
 
178
  // File mode: process uploaded image (only on button click)
 
112
  };
113
  }, [mode]);
114
 
115
+ // Webcam mode: process frames with setInterval
 
116
  useEffect(() => {
117
  if (mode !== "Webcam" || !isLoaded || !webcamActive) return;
118
+ let interval: ReturnType<typeof setInterval> | null = null;
119
+ interval = setInterval(() => {
120
+ processVideoFrame();
121
+ }, 1000);
122
+ return () => {
123
+ if (interval) clearInterval(interval);
124
+ };
 
 
 
 
125
  }, [mode, isLoaded, prompt, runInference, webcamActive]);
126
 
127
+ // URL mode: process frames with setInterval
128
  useEffect(() => {
129
  if (mode !== "URL" || !isLoaded || !urlProcessing) return;
130
+ let interval: ReturnType<typeof setInterval> | null = null;
131
+ interval = setInterval(() => {
132
+ processVideoFrame();
133
+ }, 1000);
134
+ return () => {
135
+ if (interval) clearInterval(interval);
136
+ };
 
 
 
 
137
  }, [mode, isLoaded, prompt, runInference, urlProcessing]);
138
 
139
+ // File video mode: process frames with setInterval
140
  useEffect(() => {
141
  if (mode !== "File" || !isLoaded || !uploadedFile || !isVideoFile(uploadedFile) || !videoProcessing) return;
142
+ let interval: ReturnType<typeof setInterval> | null = null;
143
+ interval = setInterval(() => {
144
+ processVideoFrame();
145
+ }, 1000);
146
+ return () => {
147
+ if (interval) clearInterval(interval);
148
+ };
 
 
 
 
149
  }, [mode, isLoaded, prompt, runInference, uploadedFile, videoProcessing]);
150
 
151
+ // Example video mode: process frames with setInterval
152
  useEffect(() => {
153
  if (mode !== "File" || uploadedFile || !isLoaded || !exampleProcessing) return;
154
+ let interval: ReturnType<typeof setInterval> | null = null;
155
+ interval = setInterval(() => {
156
+ processVideoFrame();
157
+ }, 1000);
158
+ return () => {
159
+ if (interval) clearInterval(interval);
160
+ };
 
 
 
 
161
  }, [mode, isLoaded, prompt, runInference, uploadedFile, exampleProcessing]);
162
 
163
  // File mode: process uploaded image (only on button click)