summaryrefslogtreecommitdiff
path: root/apps/web/src
diff options
context:
space:
mode:
authorShubbu03 <thatcoderguyshubham@gmail.com>2025-06-23 22:22:43 +0530
committerShubbu03 <thatcoderguyshubham@gmail.com>2025-06-23 22:24:57 +0530
commit6a701ee8c064a4652db475c93ee89c3ffe112986 (patch)
treec34cff3637f5c26d7a93dadc641689c780531b7b /apps/web/src
parent7d1b5ceb0d79ab8428750f68e7f105bf662696b0 (diff)
downloadopencut-6a701ee8c064a4652db475c93ee89c3ffe112986.tar.gz
better error handling
Diffstat (limited to 'apps/web/src')
-rw-r--r--apps/web/src/lib/ffmpeg-utils.ts20
1 files changed, 14 insertions, 6 deletions
diff --git a/apps/web/src/lib/ffmpeg-utils.ts b/apps/web/src/lib/ffmpeg-utils.ts
index de203fd6..ae0c267b 100644
--- a/apps/web/src/lib/ffmpeg-utils.ts
+++ b/apps/web/src/lib/ffmpeg-utils.ts
@@ -108,18 +108,26 @@ export const getVideoInfo = async (videoFile: File): Promise<{
// Write input file
await ffmpeg.writeFile(inputName, new Uint8Array(await videoFile.arrayBuffer()));
- // Capture FFmpeg stderr output
+ // Capture FFmpeg stderr output with a one-time listener pattern
let ffmpegOutput = '';
+ let listening = true;
const listener = (data: string) => {
- ffmpegOutput += data;
+ if (listening) ffmpegOutput += data;
};
ffmpeg.on('log', ({ message }) => listener(message));
// Run ffmpeg to get info (stderr will contain the info)
- await ffmpeg.exec(['-i', inputName, '-f', 'null', '-']);
+ try {
+ await ffmpeg.exec(['-i', inputName, '-f', 'null', '-']);
+ } catch (error) {
+ listening = false;
+ await ffmpeg.deleteFile(inputName);
+ console.error('FFmpeg execution failed:', error);
+ throw new Error('Failed to extract video info. The file may be corrupted or in an unsupported format.');
+ }
- // Remove listener
- // (No off() method in ffmpeg.wasm, so this is a no-op, but included for clarity)
+ // Disable listener after exec completes
+ listening = false;
// Cleanup
await ffmpeg.deleteFile(inputName);
@@ -220,4 +228,4 @@ export const extractAudio = async (
await ffmpeg.deleteFile(outputName);
return blob;
-}; \ No newline at end of file
+}; \ No newline at end of file