Skip to content

🎥 Make videos programmatically with React

new test composition: OffthreadRemoteSeries

Jonny Burger5377cfdf4e09
diff --git a/packages/example/src/OffthreadRemoteVideo/OffthreadRemoteSeries.tsx b/packages/example/src/OffthreadRemoteVideo/OffthreadRemoteSeries.tsx
new file mode 100644
index 0000000000..5f37bec1ae
--- /dev/null
+++ b/packages/example/src/OffthreadRemoteVideo/OffthreadRemoteSeries.tsx
@@ -0,0 +1,98 @@
+import {parseMedia} from '@remotion/media-parser';
+import {StudioInternals} from '@remotion/studio';
+import {
+ CalculateMetadataFunction,
+ OffthreadVideo,
+ Series,
+ staticFile,
+} from 'remotion';
+
+const fps = 30;
+const sources = [
+ staticFile('bigbuckbunny.mp4'),
+ 'https://parser.media/video.mp4',
+];
+
+type Props = {
+ durations: number[] | null;
+};
+
+export const calculateMetadataFn: CalculateMetadataFunction<
+ Props
+> = async () => {
+ const all = await Promise.all(
+ sources.map(async (src) => {
+ const {slowDurationInSeconds, dimensions} = await parseMedia({
+ src,
+ acknowledgeRemotionLicense: true,
+ fields: {
+ slowDurationInSeconds: true,
+ dimensions: true,
+ },
+ });
+ return {
+ src,
+ slowDurationInSeconds,
+ dimensions,
+ };
+ }),
+ );
+
+ const allDurations = all
+ .map((a) => a.slowDurationInSeconds)
+ .reduce((a, b) => a + b, 0);
+ // get biggest dimension
+ const biggestDimension = all.reduce((a, b) => {
+ if (a.dimensions === null) {
+ return b;
+ }
+ if (b.dimensions === null) {
+ return a;
+ }
+
+ return a.dimensions.width * a.dimensions.height >
+ b.dimensions.width * b.dimensions.height
+ ? a
+ : b;
+ }, all[0]);
+
+ return {
+ durationInFrames: Math.round(allDurations * fps),
+ fps,
+ width: Math.floor(biggestDimension.dimensions!.width / 2) * 2,
+ height: Math.floor(biggestDimension.dimensions!.height / 2) * 2,
+ props: {
+ durations: all.map((a) => a.slowDurationInSeconds),
+ },
+ };
+};
+
+const Component: React.FC<{
+ durations: number[] | null;
+}> = ({durations}) => {
+ if (durations === null) {
+ throw new Error('Durations are null');
+ }
+
+ return (
+ <>
+ <Series>
+ {sources.map((src, index) => (
+ <Series.Sequence durationInFrames={100} layout="none" key={index}>
+ <OffthreadVideo src={src} />
+ </Series.Sequence>
+ ))}
+ </Series>
+ </>
+ );
+};
+
+export const OffthreadRemoteSeries = StudioInternals.createComposition({
+ component: Component,
+ id: 'OffthreadRemoteSeries',
+ calculateMetadata: calculateMetadataFn,
+ defaultProps: {
+ durations: null,
+ },
+ fps,
+});
diff --git a/packages/example/src/Root.tsx b/packages/example/src/Root.tsx
index aa58566fcd..73764e4505 100644
--- a/packages/example/src/Root.tsx
+++ b/packages/example/src/Root.tsx
@@ -125,6 +125,7 @@ import {
import {EdgeBlur} from './EdgeBlur/EdgeBlur';
import {Empty} from './Empty';
import {LoopedOffthreadRemoteVideo} from './OffthreadRemoteVideo/LoopedOffthreadRemoteVideo';
+import {OffthreadRemoteSeries} from './OffthreadRemoteVideo/OffthreadRemoteSeries';
import {ParseAndDownloadMedia} from './ParseAndDownloadMedia';
import {PremountOnTransitionSeries} from './PremountOnTransitionSeries';
import {PrintProps} from './PrintProps';
@@ -690,6 +691,7 @@ export const Index: React.FC = () => {
}}
/>
<OffthreadRemoteVideo />
+ <OffthreadRemoteSeries />
<LoopedOffthreadRemoteVideo />
<Composition
id="OffthreadVideoToCanvas"