Skip to content

Record your screen, ship a demo. Free and open-source, GPU-accelerated, no watermarks, no subscriptions. Windows, macOS, Linux. Actively maintained.

fix(timeline): correct waveform vertical alignment and silent baseline

Davide Mendoliaabb4413932bd
diff --git a/src/components/video-editor/timeline/BackgroundWaveform.tsx b/src/components/video-editor/timeline/BackgroundWaveform.tsx
index 815b472d1..970a83d3e 100644
--- a/src/components/video-editor/timeline/BackgroundWaveform.tsx
+++ b/src/components/video-editor/timeline/BackgroundWaveform.tsx
@@ -105,25 +105,32 @@ export default function BackgroundWaveform({
colAmp[x] = absMax;
}
- // Filled polygon: bottom-left → top silhouette → bottom-right.
- ctx.beginPath();
- ctx.moveTo(0, bottomY);
- for (let x = 0; x < W; x++) {
- ctx.lineTo(x, bottomY - colAmp[x] * amp);
- }
- ctx.lineTo(W, bottomY);
- ctx.closePath();
+ // Draw one filled bar per column. Silent columns (height < 0.5 px) are
+ // skipped entirely so no flat baseline appears in quiet sections.
ctx.fillStyle = "rgba(74, 222, 128, 0.55)";
- ctx.fill();
+ ctx.strokeStyle = "rgba(74, 222, 128, 0.85)";
+ ctx.lineWidth = 1;
- // Crisp top-edge stroke for the sharp silhouette.
ctx.beginPath();
- ctx.moveTo(0, bottomY - colAmp[0] * amp);
- for (let x = 1; x < W; x++) {
- ctx.lineTo(x, bottomY - colAmp[x] * amp);
+ let edgeOpen = false;
+
+ for (let x = 0; x < W; x++) {
+ const barH = colAmp[x] * amp;
+ if (barH < 0.5) {
+ edgeOpen = false;
+ continue;
+ }
+ // Filled bar
+ ctx.fillRect(x, bottomY - barH, 1, barH);
+ // Top-edge stroke — lift pen on gaps, continue on runs
+ const topPx = bottomY - barH;
+ if (!edgeOpen) {
+ ctx.moveTo(x, topPx);
+ edgeOpen = true;
+ } else {
+ ctx.lineTo(x, topPx);
+ }
}
- ctx.strokeStyle = "rgba(74, 222, 128, 0.85)";
- ctx.lineWidth = 1;
ctx.stroke();
}, [peaks, range, canvasSize, videoDurationMs, topInset, bottomInset]);
diff --git a/src/components/video-editor/timeline/TimelineEditor.tsx b/src/components/video-editor/timeline/TimelineEditor.tsx
index 2bca08a84..81cbf9d62 100644
--- a/src/components/video-editor/timeline/TimelineEditor.tsx
+++ b/src/components/video-editor/timeline/TimelineEditor.tsx
@@ -806,8 +806,8 @@ function Timeline({
<BackgroundWaveform
peaks={peaks}
videoDurationMs={videoDurationMs}
- topInset={0}
- bottomInset={6}
+ topInset={3}
+ bottomInset={3}
/>
) : undefined
}