From 0353f7c5d787ac0d80d1d0876470429e0e34ce5e Mon Sep 17 00:00:00 2001 From: Maya Date: Thu, 4 Jun 2026 14:58:49 +0300 Subject: [PATCH] fix: audio to video conversion fixes all but 4 formats (amv, mpg, mpeg, vob) convert successfully from quick tests rn. took way too long to test and fix these. also remove video formats that do not like audio tracks from being shown for audio -> video conversions --- .../functional/FormatDropdown.svelte | 22 ++++++++++++++++--- src/lib/converters/ffmpeg/ffmpeg.svelte.ts | 2 -- src/lib/converters/ffmpeg/utils/ffmpeg.ts | 12 ++++++---- 3 files changed, 27 insertions(+), 9 deletions(-) diff --git a/src/lib/components/functional/FormatDropdown.svelte b/src/lib/components/functional/FormatDropdown.svelte index b3cd5e5..07f35d3 100644 --- a/src/lib/components/functional/FormatDropdown.svelte +++ b/src/lib/components/functional/FormatDropdown.svelte @@ -156,12 +156,23 @@ ); }); + // TODO: better hiddenFormats logic lol const filteredData = $derived.by(() => { const activeCategory = currentCategory && availableCategories.includes(currentCategory) ? currentCategory : availableCategories[0]; + const hiddenFormats: string[] = []; + + // if audio to video, hide these video formats (because they do not want audio tracks lol) + const nonAudioVideoFormats = [".gif", ".webp", ".apng", ".h264"]; + if ( + activeCategory === "video" && + categories["audio"]?.formats.includes(from ?? "") + ) + hiddenFormats.push(...nonAudioVideoFormats); + // if no query, return formats for current category if (!searchQuery) { const formats = getFormats(activeCategory ?? ""); @@ -182,7 +193,7 @@ return { categories: availableCategories, - formats, + formats: formats.filter((f) => !hiddenFormats.includes(f)), isFallback: false, resolvedCategory: activeCategory ?? currentCategory, }; @@ -192,7 +203,12 @@ const animatedFormats = [".webp", ".apng", ".gif"]; const matches = (f: string, cat?: string) => { - if (!normalize(f).includes(query) || shouldExclude(f)) return false; + if ( + !normalize(f).includes(query) || + shouldExclude(f) || + hiddenFormats.includes(f) + ) + return false; // if imageSequence and image category, only show animated formats if (imageSequence && (cat ?? activeCategory) === "image") { return animatedFormats.includes(f); @@ -232,7 +248,7 @@ // show categories with matches, formats from within resolved category return { categories: matchingCategories, - formats, + formats: formats.filter((f) => !hiddenFormats.includes(f)), isFallback: false, resolvedCategory, }; diff --git a/src/lib/converters/ffmpeg/ffmpeg.svelte.ts b/src/lib/converters/ffmpeg/ffmpeg.svelte.ts index 3a64ead..9bb5970 100644 --- a/src/lib/converters/ffmpeg/ffmpeg.svelte.ts +++ b/src/lib/converters/ffmpeg/ffmpeg.svelte.ts @@ -554,7 +554,6 @@ export class FFmpegConverter extends Converter { audioBitrateArgs, sampleRateArgs, channelsArgs, - tracksArgs, ); } else { this.log("Using solid color background"); @@ -565,7 +564,6 @@ export class FFmpegConverter extends Converter { audioBitrateArgs, sampleRateArgs, channelsArgs, - tracksArgs, ); } } diff --git a/src/lib/converters/ffmpeg/utils/ffmpeg.ts b/src/lib/converters/ffmpeg/utils/ffmpeg.ts index 74c7721..199e7db 100644 --- a/src/lib/converters/ffmpeg/utils/ffmpeg.ts +++ b/src/lib/converters/ffmpeg/utils/ffmpeg.ts @@ -56,7 +56,6 @@ export const avWithArt = ( audioBitrateArgs: string[], sampleRateArgs: string[], channelsArgs: string[], - tracksArgs: string[], ): string[] => { return [ "-loop", @@ -65,6 +64,8 @@ export const avWithArt = ( "cover.jpg", "-i", "input", + "-map", + "0:v:0", "-vf", "scale=trunc(iw/2)*2:trunc(ih/2)*2", "-shortest", @@ -72,12 +73,13 @@ export const avWithArt = ( "yuv420p", "-r", "1", + "-map", + "1:a:0", ...codecArgs, ...metadataArgs, ...audioBitrateArgs, ...sampleRateArgs, ...channelsArgs, - ...tracksArgs, "output" + to, ]; }; @@ -90,7 +92,6 @@ export const avWithBg = ( audioBitrateArgs: string[], sampleRateArgs: string[], channelsArgs: string[], - tracksArgs: string[], ): string[] => { return [ "-f", @@ -99,17 +100,20 @@ export const avWithBg = ( "color=c=black:s=512x512:rate=1", "-i", "input", + "-map", + "0:v:0", "-shortest", "-pix_fmt", "yuv420p", "-r", "1", + "-map", + "1:a:0", ...codecArgs, ...metadataArgs, ...audioBitrateArgs, ...sampleRateArgs, ...channelsArgs, - ...tracksArgs, "output" + to, ]; };