MCPcopy Index your code
hub / github.com/CapSoftware/Cap / convertFile

Function convertFile

apps/web/components/tools/MediaFormatConverter.tsx:323–381  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

321 };
322
323 const convertFile = async () => {
324 if (!file || !mediaEngineLoaded || !config) return;
325
326 setIsConverting(true);
327 setError(null);
328 setProgress(0);
329
330 if (parserControllerRef.current) {
331 parserControllerRef.current.abort();
332 }
333 parserControllerRef.current = { abort: () => {} };
334
335 trackEvent(`${conversionPath}_conversion_started`, {
336 fileSize: file.size,
337 fileName: file.name,
338 });
339
340 try {
341 console.log(`Starting conversion: ${conversionPath}`);
342 console.log(`Input file: ${file.name}, size: ${file.size} bytes`);
343
344 if (currentTargetFormat === "mp3" && currentSourceFormat === "mp4") {
345 await extractAudioFromVideo(file);
346 } else if (
347 currentTargetFormat === "gif" &&
348 currentSourceFormat === "mp4"
349 ) {
350 await convertVideoToGif(file);
351 } else {
352 await convertVideoFormat(file);
353 }
354 } catch (err: any) {
355 console.error("Detailed conversion error:", err);
356
357 if (MediaParser.hasBeenAborted?.(err)) {
358 setError("Conversion was cancelled");
359 } else {
360 let errorMessage = "Conversion failed: ";
361 if (err.message) {
362 errorMessage += err.message;
363 } else if (typeof err === "string") {
364 errorMessage += err;
365 } else {
366 errorMessage += "Unknown error occurred during conversion";
367 }
368
369 setError(errorMessage);
370
371 trackEvent(`${conversionPath}_conversion_failed`, {
372 fileSize: file.size,
373 fileName: file.name,
374 error: err.message || "Unknown error",
375 });
376 }
377 } finally {
378 setIsConverting(false);
379 parserControllerRef.current = null;
380 }

Callers

nothing calls this directly

Calls 5

trackEventFunction · 0.90
extractAudioFromVideoFunction · 0.85
convertVideoToGifFunction · 0.85
convertVideoFormatFunction · 0.85
abortMethod · 0.80

Tested by

no test coverage detected