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
41 changes: 41 additions & 0 deletions src/components/ExportSettings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -196,10 +196,19 @@ export default function ExportSettings({
<span
className="cursor-help"
title="Reduces video noise. May slow down export slightly."
htmlFor="noise-reduction-toggle"
className="text-sm font-heading font-semibold uppercase tracking-wider text-[var(--muted)] flex items-center gap-2"
>
<SlidersHorizontal size={10} />
Noise Reduction
<span
className="cursor-help"
title="Reduces grain in low-light videos using FFmpeg hqdn3d filter."
>
<InfoIcon size={14} />
</span>
</label>
<<<<<<< HEAD

<span className="flex text-sm font-heading font-bold text-film-600">
<input
Expand Down Expand Up @@ -234,6 +243,38 @@ export default function ExportSettings({
May slightly increase export time.
</span>
</div>
=======
</div>

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

<div className="flex gap-2">
{(['off', 'light', 'medium', 'heavy'] as const).map((level) => (
<button
key={level}
onClick={() => onChange({ noiseReduction: level })}
className={cn(
"flex-1 py-1 text-xs font-heading font-semibold uppercase rounded border transition-colors",
recipe.noiseReduction === level
? "bg-film-600 text-white border-film-600"
: "text-[var(--muted)] border-[var(--muted)] hover:border-film-600 hover:text-film-600"
)}
>
{level}
</button>
))}
</div>

{recipe.noiseReduction !== 'off' && (
<div className="flex justify-end mt-2">
<span className="text-xs text-red-700 font-medium">
⚠ Note: significantly increases processing time.
</span>
</div>
)}
>>>>>>> 92b9083 (feat: add noise reduction filter with Light/Medium/Heavy presets (closes #129))
</div>
</>
);
Expand Down
Empty file.
3 changes: 1 addition & 2 deletions src/lib/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,5 @@ export const DEFAULT_RECIPE: EditRecipe = {
denoise: false,
soundOnCompletion: false,
normalizeAudio: false,
textOverlays: [],
version: RECIPE_VERSION,
noiseReduction: 'off',
};
13 changes: 10 additions & 3 deletions src/lib/ffmpeg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,15 @@ export function buildVideoFilter(recipe: EditRecipe, targetW: number, targetH: n
if (recipe.stabilization) {
filters.push("deshake");
}

// Noise reduction using hqdn3d filter
if (recipe.noiseReduction && recipe.noiseReduction !== 'off') {
const noiseMap = {
light: 'hqdn3d=2.0:1.5:3.0:2.5',
medium: 'hqdn3d=4.0:3.0:6.0:4.5',
heavy: 'hqdn3d=6.0:5.0:9.0:6.5',
}
filters.push(noiseMap[recipe.noiseReduction])
}
if (recipe.rotate === 90) {
filters.push("transpose=1");
} else if (recipe.rotate === 180) {
Expand Down Expand Up @@ -392,8 +400,7 @@ export function buildVideoFilter(recipe: EditRecipe, targetW: number, targetH: n
return filters.join(",");
}

export function buildAudioFilter(speed: number, normalizeAudio: boolean): string {
if (speed <= 0) return "";
export function buildAudioFilter(speed: number, normalizeAudio: boolean = false): string {
const filters: string[] = [];

let remaining = speed;
Expand Down
21 changes: 9 additions & 12 deletions src/lib/tests/ffmpeg.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,36 +5,30 @@ describe("buildAudioFilter", () => {
it("should return an empty string for 1.0x speed", () => {
expect(buildAudioFilter(1, false)).toBe("");
});

it("should chain two 0.5x filters for 0.25x speed", () => {
expect(buildAudioFilter(0.25, false)).toBe("atempo=0.5,atempo=0.5");
});

it("should chain two 2.0x filters for 4.0x speed", () => {
expect(buildAudioFilter(4, false)).toBe("atempo=2.0,atempo=2");
});

it("should chain multiple 0.5x filters and a remainder for 0.1x speed", () => {
// 0.1 / 0.5 = 0.2
// 0.2 / 0.5 = 0.4
// 0.4 / 0.5 = 0.8
// Result should be three 0.5s and one 0.8
expect(buildAudioFilter(0.1, false)).toBe("atempo=0.5,atempo=0.5,atempo=0.5,atempo=0.8");
});

it("should chain multiple 2.0x filters and a remainder for 3.0x speed", () => {
// 3.0 / 2.0 = 1.5
expect(buildAudioFilter(3, false)).toBe("atempo=2.0,atempo=1.5");
});

it("should handle boundary values inside the 0.5x-2.0x range without chaining", () => {
expect(buildAudioFilter(0.5, false)).toBe("atempo=0.5");
<<<<<<< HEAD
expect(buildAudioFilter(2.0, false)).toBe("atempo=2"); // Note: Number(2.0.toFixed(4)) -> 2
=======
expect(buildAudioFilter(2.0, false)).toBe("atempo=2");
>>>>>>> 286e9fb (fix: add noiseReduction to EditRecipe type and fix test argument counts)
expect(buildAudioFilter(1.5, false)).toBe("atempo=1.5");
expect(buildAudioFilter(0.75, false)).toBe("atempo=0.75");
});

it("should chain properly for very large speeds", () => {
<<<<<<< HEAD
// 10 / 2.0 = 5
// 5 / 2.0 = 2.5
// 2.5 / 2.0 = 1.25
Expand All @@ -44,5 +38,8 @@ describe("buildAudioFilter", () => {
it("should append loudnorm filter when normalizeAudio is true", () => {
const result = buildAudioFilter(1, true);
expect(result).toContain("loudnorm");
=======
expect(buildAudioFilter(10, false)).toBe("atempo=2.0,atempo=2.0,atempo=2.0,atempo=1.25");
>>>>>>> 286e9fb (fix: add noiseReduction to EditRecipe type and fix test argument counts)
});
});
});
34 changes: 34 additions & 0 deletions src/lib/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export interface EditRecipe {
format: "mp4" | "webm" | "mkv" | "gif";
stabilization: boolean;
denoise: boolean;
noiseReduction: 'off' | 'light' | 'medium' | 'heavy';
brightness: number;
contrast: number;
saturation: number;
Expand Down Expand Up @@ -75,6 +76,39 @@ export type ExportStatus =
| "done"
| "error";

export const SPEED_STEPS = [
0.25,
0.5,
0.75,
1,
1.25,
1.5,
2,
4,
] as const;

export const DEFAULT_RECIPE: EditRecipe = {
preset: "vertical-9-16",
customWidth: 1920,
customHeight: 1080,
framing: "fit",
trimStart: 0,
trimEnd: null,
rotate: 0,
keepAudio: true,
normalizeAudio: false,
speed: 1,
quality: 23,
format: "mp4",
stabilization: false,
noiseReduction: 'off',
brightness: 0,
contrast: 0,
saturation: 0,
soundOnCompletion: false,
};

>>>>>>> 92b9083 (feat: add noise reduction filter with Light/Medium/Heavy presets (closes #129))
export const MAX_FILE_SIZE =
2 * 1024 * 1024 * 1024;

Expand Down
Loading