Capítulo 8 de 988
You may change the duration of the video based on some asynchronously determined data. The same goes for the width, height and framerate of the video.
<Player>// @filename: get-media-metadata.ts
export const getMediaMetadata = async (src: string) => {
const input = new Input({
formats: ALL_FORMATS,
source: new UrlSource(src, {
getRetryDelay: () => null,
}),
});
const durationInSeconds = await input.computeDuration();
const videoTrack = await input.getPrimaryVideoTrack();
const dimensions = videoTrack
? {
width: videoTrack.displayWidth,
height: videoTrack.displayHeight,
}
: null;
const frameRateMetrics = videoTrack
? await videoTrack.computeFrameRateMetrics()
: null;
const fps =
frameRateMetrics === null || frameRateMetrics.probedPacketCount < 2
? null
: frameRateMetrics.bestGuessFrameRate;
return {
durationInSeconds,
dimensions,
fps,
};
};
// @filename: index.tsx
type MyCompProps = {
src: string;
};
const MyComp: React.FC<MyCompProps> = ({src}) => {
return <Video src={src} />;
};
export const Root: React.FC = () => {
return (
<Composition
id="MyComp"
component={MyComp}
durationInFrames={300}
fps={30}
width={1920}
height={1080}
defaultProps={{
src: 'https://remotion.media/BigBuckBunny.mp4',
}}
calculateMetadata={async ({props}) => {
const {durationInSeconds, fps} = await getMediaMetadata(props.src);
const compositionFps = fps ?? 30;
// ...(truncated)