Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 51 additions & 0 deletions src/components/ExportSettings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,57 @@ export default function ExportSettings({
</span>
</div>
</div>
<div>
<div className="flex items-center justify-between mb-1">
<label
htmlFor="denoise-toggle"
className="text-sm font-heading font-semibold uppercase tracking-wider text-[var(--muted)] flex items-center gap-2"
>
<SlidersHorizontal size={10} />
Reduce noise

<span
className="cursor-help"
title="Reduces video noise. May slow down export slightly."
>
<InfoIcon size={14} />
</span>
</label>

<span className="flex text-sm font-heading font-bold text-film-600">
<input
id="denoise-toggle"
type="checkbox"
checked={recipe.denoise}
onChange={(e) =>
onChange({
denoise: e.target.checked,
})
}
aria-label="Enable noise reduction"
aria-checked={recipe.denoise}
className="w-full accent-film-600 cursor-pointer"
/>
</span>
</div>

<p className="text-xs text-[var(--muted)] mb-1">
Reduce low-light video grain
</p>

<div className="flex justify-end">
<span
className={cn(
"text-xs",
recipe.denoise
? "text-red-700 font-medium"
: "text-[var(--muted)]"
)}
>
May slightly increase export time.
</span>
</div>
</div>
</>
);
}
3 changes: 2 additions & 1 deletion src/lib/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ export const DEFAULT_RECIPE: EditRecipe = {
contrast: 1,
saturation: 1,
stabilization: false,
denoise: false,
soundOnCompletion: false,
normalizeAudio: false,
version: RECIPE_VERSION,
};
};
19 changes: 12 additions & 7 deletions src/lib/ffmpeg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export class FFmpegLoadError extends Error {
}

export async function loadFFmpeg(
signal?: AbortSignal,
signal?: AbortSignal,
onProgress?: (percent: number) => void
): Promise<FFmpeg> {
if (ffmpegInstance?.loaded) {
Expand Down Expand Up @@ -96,7 +96,7 @@ function buildVideoFilter(recipe: EditRecipe, targetW: number, targetH: number):
filters.push("setpts=PTS-STARTPTS");
}


if (recipe.stabilization) {
filters.push("deshake");
}
Expand All @@ -122,9 +122,14 @@ function buildVideoFilter(recipe: EditRecipe, targetW: number, targetH: number):
}

if (recipe.speed !== 1) {
const pts = (1 / recipe.speed).toFixed(4);
filters.push(`setpts=${pts}*PTS`);
const pts = (1 / recipe.speed).toFixed(4);
filters.push(`setpts=${pts}*PTS`);
}

if (recipe.denoise) {
filters.push("hqdn3d=1.5:1.5:6:6");
}

filters.push(
`eq=brightness=${recipe.brightness}:contrast=${recipe.contrast}:saturation=${recipe.saturation}`
);
Expand Down Expand Up @@ -177,7 +182,7 @@ function buildArguments(
): string[] {
const vf = buildVideoFilter(recipe, targetW, targetH);
const audioTrim = hasOriginalAudio ? buildAudioTrimFilter(recipe) : "";
const audioSpeed = hasOriginalAudio ? buildAudioFilter(recipe.speed, recipe.normalizeAudio ?? false) : "";
const audioSpeed = hasOriginalAudio ? buildAudioFilter(recipe.speed, recipe.normalizeAudio ?? false) : "";
const afParts = [audioTrim, audioSpeed].filter(Boolean);
const af = afParts.join(",");

Expand Down Expand Up @@ -328,7 +333,7 @@ export async function exportVideo(
onProgress(Math.min(99, Math.round(progress * 100)));
};


try {
await ffmpeg.writeFile(inputName, await fetchFile(file), { signal });

Expand Down Expand Up @@ -477,4 +482,4 @@ export async function exportVideo(
export function formatBytes(bytes: number): string {
if (bytes < 1024 * 1024) return `${(bytes / 1024).toFixed(1)} KB`;
return `${(bytes / (1024 * 1024)).toFixed(1)} MB`;
}
}
4 changes: 3 additions & 1 deletion src/lib/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export interface EditRecipe {
quality: number;
format: "mp4" | "webm" | "mkv" | "gif";
stabilization: boolean;
denoise: boolean;
brightness: number;
contrast: number;
saturation: number;
Expand Down Expand Up @@ -81,6 +82,7 @@ export const DEFAULT_RECIPE: EditRecipe = {
quality: 23,
format: "mp4",
stabilization: false,
denoise: false,
brightness: 0,
contrast: 0,
saturation: 0,
Expand Down Expand Up @@ -118,4 +120,4 @@ export function isValidRecipe(value: unknown): value is EditRecipe {
if (typeof v.soundOnCompletion !== "boolean") return false;

return true;
}
}
Loading