Skip to content

🎥 Make videos programmatically with React

audiowaveform

Jonny Burger78e7c7b3172f
diff --git a/packages/convert/app/components/AudioWaveform.tsx b/packages/convert/app/components/AudioWaveform.tsx
index 07057adce9..c9eff7f5b5 100644
--- a/packages/convert/app/components/AudioWaveform.tsx
+++ b/packages/convert/app/components/AudioWaveform.tsx
@@ -17,9 +17,11 @@ export const AudioWaveForm: React.FC<{readonly bars: number[]}> = ({bars}) => {
style={{
height: THUMBNAIL_HEIGHT,
}}
- className=" bg-slate-100 border-b-2 border-black justify-center items-center flex flex-row gap-[1px]"
+ className="bg-slate-100 border-b-2 border-black justify-center items-center flex flex-row gap-[1px]"
>
{padded.map((bar, i) => {
+ const height = ((bar ?? 0) / 255) * 40;
+
return (
<div
// eslint-disable-next-line react/no-array-index-key
@@ -27,8 +29,8 @@ export const AudioWaveForm: React.FC<{readonly bars: number[]}> = ({bars}) => {
data-notnull={bar !== null}
className="rounded bg-slate-200 inline-block w-[4px] data-[notnull=true]:bg-slate-600"
style={{
- height: Math.max(6, ((bar ?? 0) / 255) * 40),
- transition: 'height 0.1s ease, color 0.1s ease',
+ height: Math.max(6, height),
+ transition: 'height 0.2s ease, color 0.2s ease',
}}
/>
);
diff --git a/packages/convert/app/components/ConvertProgress.tsx b/packages/convert/app/components/ConvertProgress.tsx
index ab63fc360e..925d243533 100644
--- a/packages/convert/app/components/ConvertProgress.tsx
+++ b/packages/convert/app/components/ConvertProgress.tsx
@@ -60,18 +60,23 @@ export const ConvertProgress: React.FC<{
mirrorVertical={false}
/>
) : null}
- {duration ? <AudioWaveForm bars={bars} /> : null}
- <div className="h-5 overflow-hidden">
- {state.millisecondsWritten || done ? (
- <div
- className="w-[50%] h-5 bg-brand"
- style={{
- width: (progress ?? 0) * 100 + '%',
- }}
- />
- ) : null}
- </div>
- <div className="border-b-2 border-black" />
+ {duration ? (
+ <AudioWaveForm bars={bars} />
+ ) : (
+ <>
+ <div className="h-5 overflow-hidden">
+ {state.millisecondsWritten || done ? (
+ <div
+ className="w-[50%] h-5 bg-brand"
+ style={{
+ width: (progress ?? 0) * 100 + '%',
+ }}
+ />
+ ) : null}
+ </div>
+ <div className="border-b-2 border-black" />
+ </>
+ )}
<div className="p-2">
<div>
{name ? (
diff --git a/packages/convert/app/components/ConvertUi.tsx b/packages/convert/app/components/ConvertUi.tsx
index f2f52ae9bd..8fd3ab1b18 100644
--- a/packages/convert/app/components/ConvertUi.tsx
+++ b/packages/convert/app/components/ConvertUi.tsx
@@ -365,7 +365,7 @@ export default function ConvertUI({
userRotation,
]);
- const hasAudio = useMemo(() => {
+ const isAudioExclusively = useMemo(() => {
return (tracks?.videoTracks.length ?? 0) === 0;
}, [tracks?.videoTracks.length]);
@@ -399,7 +399,7 @@ export default function ConvertUI({
})
}
bars={bars}
- isAudioOnly={hasAudio}
+ isAudioOnly={isAudioExclusively}
/>
<div className="h-2" />
<Button className="block w-full" type="button" onClick={cancel}>
@@ -427,7 +427,7 @@ export default function ConvertUI({
})
}
bars={bars}
- isAudioOnly={hasAudio}
+ isAudioOnly={isAudioExclusively}
/>
<div className="h-2" />
<ConversionDone
@@ -491,6 +491,10 @@ export default function ConvertUI({
}
if (section === 'mirror') {
+ if (isAudioExclusively) {
+ return null;
+ }
+
return (
<div key="mirror">
<ConvertUiSection
@@ -513,6 +517,10 @@ export default function ConvertUI({
}
if (section === 'rotate') {
+ if (isAudioExclusively) {
+ return null;
+ }
+
return (
<div key="rotate">
<ConvertUiSection
@@ -533,6 +541,10 @@ export default function ConvertUI({
}
if (section === 'resize') {
+ if (isAudioExclusively) {
+ return null;
+ }
+
return (
<div key="resize">
<ConvertUiSection