Skip to content

🎥 Make videos programmatically with React

almost there

Jonny Burgerff9d860ba89a
diff --git a/packages/example/simulate-lambda.ts b/packages/example/simulate-lambda.ts
index d94af0b9d0..27c791bd23 100644
--- a/packages/example/simulate-lambda.ts
+++ b/packages/example/simulate-lambda.ts
@@ -24,10 +24,11 @@ const framesPerLambda = 24;
console.log(filelistDir);
for (let i = 0; i < dur / framesPerLambda; i++) {
+ const outputLocation = path.join(filelistDir, 'out/there' + i + '.aac');
await renderMedia({
- codec: 'h264',
+ codec: 'aac',
composition,
- outputLocation: path.join(filelistDir, 'out/there' + i + '.mkv'),
+ outputLocation,
serveUrl: bundled,
frameRange: [i * framesPerLambda, (i + 1) * framesPerLambda - 1],
concurrency: 1,
@@ -36,14 +37,15 @@ for (let i = 0; i < dur / framesPerLambda; i++) {
verbose: false,
enforceAudioTrack: true,
});
+ await $`ffmpeg -i ${outputLocation} -y ${i}.wav`;
console.log({i});
}
await RenderInternals.combineVideos({
- codec: 'h264',
+ codec: 'aac',
filelistDir,
files: new Array(dur / framesPerLambda).fill(true).map((_, i) => {
- return path.join(filelistDir, 'out/there' + i + '.mkv');
+ return path.join(filelistDir, 'out/there' + i + '.aac');
}),
fps: 30,
numberOfFrames: dur,
@@ -60,5 +62,5 @@ await RenderInternals.combineVideos({
RenderInternals.deleteDirectory(bundled);
await $`ffmpeg -i ${path.join(__dirname, 'out/combined.mp4')} -y ${path.join(
__dirname,
- 'out/combined.wav',
+ 'combined.wav',
)}`;
diff --git a/packages/example/src/OffthreadRemoteVideo/OffthreadRemoteVideo.tsx b/packages/example/src/OffthreadRemoteVideo/OffthreadRemoteVideo.tsx
index ec0fb62d09..a0ad3b5bb3 100644
--- a/packages/example/src/OffthreadRemoteVideo/OffthreadRemoteVideo.tsx
+++ b/packages/example/src/OffthreadRemoteVideo/OffthreadRemoteVideo.tsx
@@ -1,9 +1,9 @@
-import {Loop, OffthreadVideo, staticFile} from 'remotion';
+import {Audio, Loop, OffthreadVideo, staticFile} from 'remotion';
export const OffthreadRemoteVideo: React.FC = () => {
return (
- <Loop durationInFrames={15 * 30}>
- <OffthreadVideo src={staticFile('vid1.mp4')} />
+ <Loop durationInFrames={20 * 30}>
+ <Audio src={staticFile('sine.wav')} />
</Loop>
);
};
diff --git a/packages/renderer/src/combine-audio.ts b/packages/renderer/src/combine-audio.ts
index d934e17e70..d75bcb28e7 100644
--- a/packages/renderer/src/combine-audio.ts
+++ b/packages/renderer/src/combine-audio.ts
@@ -10,9 +10,9 @@ import {parseFfmpegProgress} from './parse-ffmpeg-progress';
import {DEFAULT_SAMPLE_RATE} from './sample-rate';
import {truthy} from './truthy';
-const durationOf1Frame = (1024 / DEFAULT_SAMPLE_RATE) * 1_000_000;
+export const durationOf1Frame = (1024 / DEFAULT_SAMPLE_RATE) * 1_000_000;
-const getClosestAlignedTime = (targetTime: number) => {
+export const getClosestAlignedTime = (targetTime: number) => {
const decimalFramesToTargetTime = targetTime / durationOf1Frame;
const nearestFrameIndexForTargetTime = Math.round(decimalFramesToTargetTime);
return nearestFrameIndexForTargetTime * durationOf1Frame;
@@ -103,8 +103,6 @@ const combineAudioSeamlessly = async ({
}) => {
const fileList = files
.map((p, i) => {
- const isLast = i === files.length - 1;
-
const targetStart = i * chunkDurationInSeconds * 1_000_000;
const endStart = (i + 1) * chunkDurationInSeconds * 1_000_000;
@@ -113,30 +111,30 @@ const combineAudioSeamlessly = async ({
const realDuration = endTime - startTime;
+ console.log({realDuration});
+
let inpoint = 0;
if (i > 0) {
// Although we only asked for two frames of padding, ffmpeg will add an
// additional 2 frames of silence at the start of the segment. When we slice out
// our real data with inpoint and outpoint, we'll want remove both the silence
// and the extra frames we asked for.
- inpoint = durationOf1Frame * 4;
+ inpoint = durationOf1Frame * 5;
}
// inpoint is inclusive and outpoint is exclusive. To avoid overlap, we subtract
// the duration of one frame from the outpoint.
// we don't have to subtract a frame if this is the last segment.
- const outpoint = realDuration + inpoint - durationOf1Frame;
+ const outpoint = realDuration + inpoint;
- return [
- `file '${p}'`,
- `inpoint ${inpoint}us`,
- isLast ? null : `outpoint ${outpoint}us`,
- ]
+ return [`file '${p}'`, `inpoint ${inpoint}us`, `outpoint ${outpoint}us`]
.filter(truthy)
.join('\n');
})
.join('\n');
+ console.log(fileList);
+
const fileListTxt = join(filelistDir, 'audio-files.txt');
writeFileSync(fileListTxt, fileList);
@@ -174,7 +172,8 @@ const combineAudioSeamlessly = async ({
await task;
return output;
} catch (e) {
- rmSync(filelistDir, {recursive: true});
+ // rmSync(filelistDir, {recursive: true});
+ console.log(e);
throw e;
}
};
diff --git a/packages/renderer/src/combine-videos.ts b/packages/renderer/src/combine-videos.ts
index 19d714b014..47221946e9 100644
--- a/packages/renderer/src/combine-videos.ts
+++ b/packages/renderer/src/combine-videos.ts
@@ -117,7 +117,7 @@ export const combineVideos = async (options: Options) => {
videoOutput,
});
onProgress(numberOfFrames);
- rmSync(filelistDir, {recursive: true});
+ // rmSync(filelistDir, {recursive: true});
} catch (err) {
rmSync(filelistDir, {recursive: true});
throw err;