🎥 Make videos programmatically with React
Docs: How to size a Player to fill a container
Jonny Burgerdf1ebf4ac49a
diff --git a/packages/docs/docs/player/scaling.mdx b/packages/docs/docs/player/scaling.mdxindex b7725a3008..d8420542f5 100644--- a/packages/docs/docs/player/scaling.mdx+++ b/packages/docs/docs/player/scaling.mdx@@ -1,16 +1,24 @@---image: /generated/articles-docs-player-scaling.pngid: scaling-title: "Sizing"-crumb: "@remotion/player"+title: 'Sizing'+crumb: '@remotion/player'---The following algorithm is used for calculating the size of the Player:-<Step>1</Step> By default, the Player is as big as the composition height, defined by the <code>compositionHeight</code> and <code>compositionWidth</code> props. <br/>-<Step>2</Step> If <code>height</code> and <code>width</code> is defined using the <code>style</code> property, the player will assume the dimensions you have passed. <br/>-<Step>3</Step> If a <code>height</code> is passed using the <code>style</code> property, the player will assume that height, and calculate the width based on the aspect ratio of the video. <br/>-<Step>4</Step> If <code>width</code> is passed using the <code>style</code> property, the player will assume that width and calculate the height based on the aspect ration of the video. <br/><br/>+<Step>1</Step> By default, the Player is as big as the composition height,+defined by the <code>compositionHeight</code> and <code>compositionWidth</code> props. <br />+<Step>2</Step> If <code>height</code> and <code>width</code> is defined using+the <code>style</code> property, the player will assume the dimensions you have+passed. <br />+<Step>3</Step> If a <code>height</code> is passed using the <code>style</code> property,+the player will assume that height, and calculate the width based on the aspect+ratio of the video. <br />+<Step>4</Step> If <code>width</code> is passed using the <code>style</code> property,+the player will assume that width and calculate the height based on the aspect+ration of the video. <br />+<br />:::noteBefore v3.3.43, if case <InlineStep>3</InlineStep> or <InlineStep>4</InlineStep> happened, a layout shift would occur during mounting because the element was measured. Using a newer version of Remotion will fix this, because it uses the `aspect-ratio` CSS property.@@ -28,10 +36,60 @@ The video will scale to the full width of the parent container, while the height## Fitting to a container-You can use+This is how you can make the Player fill out a container but keep the aspect ratio of the video:-```tsx-style={{ width: "100%", height: "100%" }}-```+<video playsInline src="/img/fullscreen.mp4" autoPlay loop muted />+<br />++```tsx twoslash title="Canvas.tsx"+import {Player} from '@remotion/player';+import React from 'react';+import {AbsoluteFill} from 'remotion';-to make the `<Player />` fit the whole container. Note that if the player size does not match the video aspect ratio, the video gets scaled down and centered in the player.+const MyComp: React.FC = () => {+ return <AbsoluteFill style={{backgroundColor: 'black'}} />;+};++export const FullscreenPlayer = () => {+ const compositionWidth = 300;+ const compositionHeight = 200;++ return (+ <div+ style={{+ width: '100vw',+ height: '100vh',+ backgroundColor: 'gray',+ // Any container with "position: relative" will work+ position: 'relative',+ }}+ >+ <div+ style={{+ position: 'absolute',+ top: 0,+ left: 0,+ right: 0,+ bottom: 0,+ margin: 'auto',+ aspectRatio: `${compositionWidth} / ${compositionHeight}`,+ maxHeight: '100%',+ maxWidth: '100%',+ }}+ >+ <Player+ controls+ component={MyComp}+ compositionWidth={compositionWidth}+ compositionHeight={compositionHeight}+ durationInFrames={200}+ fps={30}+ style={{+ width: '100%',+ }}+ />+ </div>+ </div>+ );+};+```diff --git a/packages/docs/static/img/fullscreen.mp4 b/packages/docs/static/img/fullscreen.mp4new file mode 100644index 0000000000..d7f3d5ec0cBinary files /dev/null and b/packages/docs/static/img/fullscreen.mp4 differdiff --git a/packages/player-example/src/FullscreenPlayer.tsx b/packages/player-example/src/FullscreenPlayer.tsxindex cd413fe160..25e3a1050b 100644--- a/packages/player-example/src/FullscreenPlayer.tsx+++ b/packages/player-example/src/FullscreenPlayer.tsx@@ -1,5 +1,10 @@import {Player} from '@remotion/player';-import CarSlideshow from './CarSlideshow';+import React from 'react';+import {AbsoluteFill} from 'remotion';++const MyComp: React.FC = () => {+ return <AbsoluteFill style={{backgroundColor: 'black'}} />;+};export const FullscreenPlayer = () => {const compositionWidth = 300;@@ -8,10 +13,11 @@ export const FullscreenPlayer = () => {return (<divstyle={{- width: '100%',- height: '100%',+ width: '100vw',+ height: '100vh',backgroundColor: 'gray',- position: 'absolute',+ // Any container with "position: relative" will work+ position: 'relative',}}><div@@ -25,21 +31,18 @@ export const FullscreenPlayer = () => {aspectRatio: `${compositionWidth} / ${compositionHeight}`,maxHeight: '100%',maxWidth: '100%',- background: 'black',}}><Playercontrols- component={CarSlideshow}+ component={MyComp}compositionWidth={compositionWidth}compositionHeight={compositionHeight}durationInFrames={200}fps={30}style={{width: '100%',- backgroundColor: 'black',}}- inputProps={{title: 'Hi there', bgColor: 'black', color: 'white'}}/></div></div>