Skip to content

🎥 Make videos programmatically with React

bug fixes

Jonny Burgerafd30143a0ba
diff --git a/packages/cli/src/editor/components/AudioWaveform.tsx b/packages/cli/src/editor/components/AudioWaveform.tsx
index 2044e762c1..4ed39c5f49 100644
--- a/packages/cli/src/editor/components/AudioWaveform.tsx
+++ b/packages/cli/src/editor/components/AudioWaveform.tsx
@@ -4,6 +4,7 @@ import {
AudioContextMetadata,
getAudioMetadata,
} from '../helpers/get-audio-metadata';
+import {getAudioRangeFromStartFromAndDuration} from '../helpers/get-audio-range-from-start-from';
import {getWaveformSamples} from '../helpers/reduce-waveform';
import {TIMELINE_LAYER_HEIGHT} from '../helpers/timeline-layout';
import {
@@ -27,8 +28,20 @@ export const AudioWaveform: React.FC<{
fps: number;
startFrom: number;
duration: number;
-}> = ({src, fps, startFrom, duration, visualizationWidth}) => {
+}> = ({
+ src,
+ fps,
+ startFrom: baseStartFrom,
+ duration: baseDuration,
+ visualizationWidth,
+}) => {
const [metadata, setMetadata] = useState<AudioContextMetadata | null>(null);
+
+ const {startFrom, durationInFrames} = getAudioRangeFromStartFromAndDuration({
+ startFrom: baseStartFrom,
+ durationInFrames: baseDuration,
+ });
+
useEffect(() => {
getAudioMetadata(src)
.then((data) => {
@@ -52,7 +65,7 @@ export const AudioWaveform: React.FC<{
);
const endSample = Math.floor(
interpolate(
- startFrom + duration,
+ startFrom + durationInFrames,
[0, metadata.duration * fps],
[0, metadata.channelWaveforms[0].length]
)
@@ -69,7 +82,7 @@ export const AudioWaveform: React.FC<{
amplitude: w,
};
});
- }, [duration, fps, metadata, startFrom, visualizationWidth]);
+ }, [durationInFrames, fps, metadata, startFrom, visualizationWidth]);
if (!metadata) {
return null;
diff --git a/packages/cli/src/editor/components/Timeline/Timeline.tsx b/packages/cli/src/editor/components/Timeline/Timeline.tsx
index bb34d2554c..11edbb45f4 100644
--- a/packages/cli/src/editor/components/Timeline/Timeline.tsx
+++ b/packages/cli/src/editor/components/Timeline/Timeline.tsx
@@ -39,6 +39,7 @@ export const Timeline: React.FC = () => {
display: 'flex',
flex: 1,
minHeight: '100%',
+ overflowX: 'hidden',
};
}, [timeline.length]);
diff --git a/packages/cli/src/editor/helpers/calculate-timeline.ts b/packages/cli/src/editor/helpers/calculate-timeline.ts
index 7f49f6747f..9cd0cd3535 100644
--- a/packages/cli/src/editor/helpers/calculate-timeline.ts
+++ b/packages/cli/src/editor/helpers/calculate-timeline.ts
@@ -32,7 +32,7 @@ export const calculateTimeline = ({
parent: null,
type: 'sequence',
isThumbnail: false,
- rootId: 'hi',
+ rootId: '-',
},
depth: 0,
},
diff --git a/packages/cli/src/editor/helpers/get-audio-range-from-start-from.ts b/packages/cli/src/editor/helpers/get-audio-range-from-start-from.ts
new file mode 100644
index 0000000000..49ac7cb651
--- /dev/null
+++ b/packages/cli/src/editor/helpers/get-audio-range-from-start-from.ts
@@ -0,0 +1,13 @@
+export const getAudioRangeFromStartFromAndDuration = ({
+ startFrom,
+ durationInFrames,
+}: {
+ startFrom: number;
+ durationInFrames: number;
+}) => {
+ const negativeOffset = Math.min(startFrom, 0);
+ return {
+ startFrom: -negativeOffset,
+ durationInFrames: durationInFrames + negativeOffset,
+ };
+};
diff --git a/packages/cli/src/editor/helpers/reduce-waveform.ts b/packages/cli/src/editor/helpers/reduce-waveform.ts
index 064ea3dd7d..2dc4f4f546 100644
--- a/packages/cli/src/editor/helpers/reduce-waveform.ts
+++ b/packages/cli/src/editor/helpers/reduce-waveform.ts
@@ -1,5 +1,8 @@
const filterData = (audioBuffer: Float32Array, samples: number) => {
const blockSize = Math.floor(audioBuffer.length / samples); // the number of samples in each subdivision
+ if (blockSize === 0) {
+ return [];
+ }
const filteredData = [];
for (let i = 0; i < samples; i++) {
const blockStart = blockSize * i; // the location of the first sample in the block