Skip to content

🎥 Make videos programmatically with React

Update slow-duration-fps.ts

Jonny Burgerdec965314f67
diff --git a/packages/media-parser/src/state/slow-duration-fps.ts b/packages/media-parser/src/state/slow-duration-fps.ts
index c59950de94..8c415705e2 100644
--- a/packages/media-parser/src/state/slow-duration-fps.ts
+++ b/packages/media-parser/src/state/slow-duration-fps.ts
@@ -8,9 +8,9 @@ export const slowDurationAndFpsState = () => {
let videoSamples = 0;
let audioSamples = 0;
- const getSlowDurationInSeconds = () => {
+ const getSlowVideoDurationInSeconds = () => {
let videoDuration: number | null = null;
- let audioDuration: number | null = null;
+
if (smallestVideoSample !== undefined && largestVideoSample !== undefined) {
const startingTimestampDifference =
largestVideoSample - smallestVideoSample;
@@ -19,6 +19,13 @@ export const slowDurationAndFpsState = () => {
videoDuration = timeBetweenSamples * videoSamples;
}
+ return videoDuration;
+ };
+
+ const getSlowDurationInSeconds = () => {
+ const videoDuration = getSlowVideoDurationInSeconds();
+ let audioDuration: number | null = null;
+
if (smallestAudioSample !== undefined && largestAudioSample !== undefined) {
const startingTimestampDifferenceAudio =
largestAudioSample - smallestAudioSample;
@@ -71,7 +78,12 @@ export const slowDurationAndFpsState = () => {
},
getSlowDurationInSeconds,
getFps: () => {
- return videoSamples / getSlowDurationInSeconds();
+ const videoDuration = getSlowVideoDurationInSeconds() ?? 0;
+ if (videoDuration === 0) {
+ return 0;
+ }
+
+ return videoSamples / videoDuration;
},
getSlowNumberOfFrames: () => videoSamples,
};