Skip to content

🎥 Make videos programmatically with React

new way

Jonny Burger69ebeae93ece
diff --git a/packages/renderer/src/assets/ffmpeg-volume-expression.ts b/packages/renderer/src/assets/ffmpeg-volume-expression.ts
index 5e6f42cda7..976cd70363 100644
--- a/packages/renderer/src/assets/ffmpeg-volume-expression.ts
+++ b/packages/renderer/src/assets/ffmpeg-volume-expression.ts
@@ -22,12 +22,10 @@ const ffmpegIsOneOfFrames = ({
frames,
trimLeft,
fps,
- timestampMultiplier,
}: {
frames: number[];
trimLeft: number;
fps: number;
- timestampMultiplier: number;
}) => {
const consecutiveArrays: number[][] = [];
for (let i = 0; i < frames.length; i++) {
@@ -44,8 +42,8 @@ const ffmpegIsOneOfFrames = ({
.map((f) => {
const firstFrame = f[0];
const lastFrame = f[f.length - 1];
- const before = (firstFrame - 0.5) / fps / timestampMultiplier;
- const after = (lastFrame + 0.5) / fps / timestampMultiplier;
+ const before = (firstFrame - 0.5) / fps;
+ const after = (lastFrame + 0.5) / fps;
return `between(${FFMPEG_TIME_VARIABLE},${(before + trimLeft).toFixed(
4,
)},${(after + trimLeft).toFixed(4)})`;
@@ -57,12 +55,10 @@ const ffmpegBuildVolumeExpression = ({
arr,
delay,
fps,
- timestampMultiplier,
}: {
arr: VolumeArray;
delay: number;
fps: number;
- timestampMultiplier: number;
}): string => {
if (arr.length === 0) {
throw new Error('Volume array expression should never have length 0');
@@ -76,9 +72,9 @@ const ffmpegBuildVolumeExpression = ({
const [volume, frames] = first;
return ffmpegIfOrElse(
- ffmpegIsOneOfFrames({frames, trimLeft: delay, fps, timestampMultiplier}),
+ ffmpegIsOneOfFrames({frames, trimLeft: delay, fps}),
String(volume),
- ffmpegBuildVolumeExpression({arr: rest, delay, fps, timestampMultiplier}),
+ ffmpegBuildVolumeExpression({arr: rest, delay, fps}),
);
};
@@ -92,13 +88,13 @@ export const ffmpegVolumeExpression = ({
fps,
trimLeft,
allowAmplificationDuringRender,
- timestampMultiplier,
+ trimLeftOffset,
}: {
volume: AssetVolume;
trimLeft: number;
fps: number;
allowAmplificationDuringRender: boolean;
- timestampMultiplier: number;
+ trimLeftOffset: number;
}): FfmpegVolumeExpression => {
const maxVolume = allowAmplificationDuringRender ? Infinity : 1;
// If it's a static volume, we return it and tell
@@ -116,7 +112,7 @@ export const ffmpegVolumeExpression = ({
fps,
trimLeft,
allowAmplificationDuringRender,
- timestampMultiplier,
+ trimLeftOffset,
});
}
@@ -154,7 +150,6 @@ export const ffmpegVolumeExpression = ({
arr: volumeArray,
delay: trimLeft,
fps,
- timestampMultiplier,
});
return {
diff --git a/packages/renderer/src/stringify-ffmpeg-filter.ts b/packages/renderer/src/stringify-ffmpeg-filter.ts
index 949aaf4fc3..65dc0ec2d7 100644
--- a/packages/renderer/src/stringify-ffmpeg-filter.ts
+++ b/packages/renderer/src/stringify-ffmpeg-filter.ts
@@ -54,7 +54,6 @@ const trimAndSetTempo = ({
fps: number;
}): {
actualTrimLeft: number;
- timestampMultiplier: number;
filter: (string | null)[];
audibleDuration: number;
} => {
@@ -93,7 +92,6 @@ const trimAndSetTempo = ({
`atrim=${stringifyTrim(trimLeft)}:${stringifyTrim(trimRight)}`,
],
actualTrimLeft: trimLeft,
- timestampMultiplier: 1,
audibleDuration: trimRight - trimLeft,
};
}
@@ -121,7 +119,6 @@ const trimAndSetTempo = ({
calculateATempo(asset.playbackRate),
],
actualTrimLeft: trimLeft,
- timestampMultiplier: 1,
audibleDuration:
(trimRightOrAssetDuration - trimLeft) / asset.playbackRate,
};
@@ -182,7 +179,6 @@ export const stringifyFfmpegFilter = ({
actualTrimLeft,
audibleDuration,
filter: trimAndTempoFilter,
- timestampMultiplier,
} = trimAndSetTempo({
forSeamlessAacConcatenation,
assetDuration,
@@ -197,7 +193,7 @@ export const stringifyFfmpegFilter = ({
fps,
trimLeft: actualTrimLeft,
allowAmplificationDuringRender: asset.allowAmplificationDuringRender,
- timestampMultiplier,
+ trimLeftOffset,
});
const padAtEnd = chunkLengthInSeconds - audibleDuration - startInVideoSeconds;
diff --git a/packages/renderer/src/test/ffmpeg-volume-expression.test.ts b/packages/renderer/src/test/ffmpeg-volume-expression.test.ts
index 62dfd553c2..a32642d2af 100644
--- a/packages/renderer/src/test/ffmpeg-volume-expression.test.ts
+++ b/packages/renderer/src/test/ffmpeg-volume-expression.test.ts
@@ -9,7 +9,7 @@ test('Simple expression', () => {
fps: 30,
trimLeft: 0,
allowAmplificationDuringRender: false,
- timestampMultiplier: 1,
+ trimLeftOffset: 0,
}),
).toEqual({
eval: 'once',
@@ -24,7 +24,7 @@ test('Simple expression with volume multiplier', () => {
fps: 30,
trimLeft: 0,
allowAmplificationDuringRender: false,
- timestampMultiplier: 1,
+ trimLeftOffset: 0,
}),
).toEqual({
eval: 'once',
@@ -39,7 +39,7 @@ test('Complex expression with volume multiplier', () => {
fps: 30,
trimLeft: 0,
allowAmplificationDuringRender: false,
- timestampMultiplier: 1,
+ trimLeftOffset: 0,
}),
).toEqual({
eval: 'frame',
@@ -54,7 +54,7 @@ test('Should respect trimLeft multiplier', () => {
fps: 30,
trimLeft: 0.5,
allowAmplificationDuringRender: false,
- timestampMultiplier: 1,
+ trimLeftOffset: 0,
}),
).toEqual({
eval: 'frame',
@@ -72,7 +72,7 @@ test('Really complex volume expression', () => {
fps: 30,
trimLeft: 0,
allowAmplificationDuringRender: false,
- timestampMultiplier: 1,
+ trimLeftOffset: 0,
}),
).toEqual({
eval: 'frame',
@@ -87,7 +87,7 @@ test('Should use 0 as else statement', () => {
fps: 30,
allowAmplificationDuringRender: false,
trimLeft: 0,
- timestampMultiplier: 1,
+ trimLeftOffset: 0,
}),
).toEqual({
eval: 'frame',
@@ -102,7 +102,7 @@ test('Simple expression - should not be higher than 1', () => {
fps: 30,
trimLeft: 0,
allowAmplificationDuringRender: false,
- timestampMultiplier: 1,
+ trimLeftOffset: 0,
}),
).toEqual({
eval: 'once',
@@ -117,7 +117,7 @@ test('Complex expression - should be higher than 1 if allowed', () => {
fps: 30,
trimLeft: 0,
allowAmplificationDuringRender: true,
- timestampMultiplier: 1,
+ trimLeftOffset: 0,
}),
).toEqual({
eval: 'frame',
@@ -132,7 +132,7 @@ test('Should simplify an expression', () => {
fps: 30,
trimLeft: 0,
allowAmplificationDuringRender: false,
- timestampMultiplier: 1,
+ trimLeftOffset: 0,
}),
).toEqual({
eval: 'frame',
@@ -152,7 +152,7 @@ test('Should stay under half 8000 windows character limit', () => {
fps: 30,
trimLeft: 0,
allowAmplificationDuringRender: false,
- timestampMultiplier: 1,
+ trimLeftOffset: 0,
});
expect(expression.value.length).toBeLessThan(4000);
@@ -168,7 +168,7 @@ test('Last volume should be default case', () => {
fps: 30,
trimLeft: 0,
allowAmplificationDuringRender: false,
- timestampMultiplier: 1,
+ trimLeftOffset: 0,
});
expect(expression).toEqual({
eval: 'frame',