Skip to content

🎥 Make videos programmatically with React

show video in timeline

Jonny Burger68dafb094b42
diff --git a/packages/cli/src/editor/components/Timeline/TimelineSequence.tsx b/packages/cli/src/editor/components/Timeline/TimelineSequence.tsx
index d0ef0024e8..0f90ae47b6 100644
--- a/packages/cli/src/editor/components/Timeline/TimelineSequence.tsx
+++ b/packages/cli/src/editor/components/Timeline/TimelineSequence.tsx
@@ -10,9 +10,11 @@ import {RichTimelineContext} from '../../state/rich-timeline';
import {AudioWaveform} from '../AudioWaveform';
import {Thumbnail} from '../Thumbnail';
import {sliderAreaRef} from './timeline-refs';
+import {TimelineVideoInfo} from './TimelineVideoInfo';
const SEQUENCE_GRADIENT = 'linear-gradient(to bottom, #3697e1, #348AC7 60%)';
const AUDIO_GRADIENT = 'linear-gradient(rgb(16 171 58), rgb(43 165 63) 60%)';
+const VIDEO_GRADIENT = 'linear-gradient(to top, #8e44ad, #9b59b6)';
export const TimelineSequence: React.FC<{
s: TSequence;
@@ -43,7 +45,12 @@ export const TimelineSequence: React.FC<{
const style: React.CSSProperties = useMemo(() => {
return {
- background: s.type === 'audio' ? AUDIO_GRADIENT : SEQUENCE_GRADIENT,
+ background:
+ s.type === 'audio'
+ ? AUDIO_GRADIENT
+ : s.type === 'video'
+ ? VIDEO_GRADIENT
+ : SEQUENCE_GRADIENT,
border: SEQUENCE_BORDER_WIDTH + 'px solid rgba(255, 255, 255, 0.2)',
borderRadius: 4,
position: 'absolute',
@@ -100,6 +107,7 @@ export const TimelineSequence: React.FC<{
setMaxMediaDuration={setMaxMediaDuration}
/>
) : null}
+ {s.type === 'video' ? <TimelineVideoInfo src={s.src} /> : null}
</div>
);
};
diff --git a/packages/cli/src/editor/components/Timeline/TimelineVideoInfo.tsx b/packages/cli/src/editor/components/Timeline/TimelineVideoInfo.tsx
new file mode 100644
index 0000000000..e86c397d21
--- /dev/null
+++ b/packages/cli/src/editor/components/Timeline/TimelineVideoInfo.tsx
@@ -0,0 +1,64 @@
+import {getVideoMetadata} from '@remotion/media-utils';
+import {VideoMetadata} from '@remotion/media-utils/src/types';
+import React, {useEffect, useRef, useState} from 'react';
+import {TIMELINE_LAYER_HEIGHT} from '../../helpers/timeline-layout';
+
+const containerStyle: React.CSSProperties = {
+ height: TIMELINE_LAYER_HEIGHT,
+ width: TIMELINE_LAYER_HEIGHT,
+ backgroundColor: 'rgba(0, 0, 0, 0.3)',
+ display: 'flex',
+ justifyContent: 'center',
+ alignItems: 'center',
+ textAlign: 'center',
+ borderRadius: 2,
+ fontSize: 10,
+ fontFamily: 'Arial, Helvetica',
+};
+
+const svgStyle: React.CSSProperties = {
+ height: 20,
+ color: '#8e44ad',
+};
+
+export const TimelineVideoInfo: React.FC<{
+ src: string;
+}> = ({src}) => {
+ const mountState = useRef({isMounted: true});
+ const [videoMetadata, setVideoMetadata] = useState<VideoMetadata | null>(
+ null
+ );
+
+ useEffect(() => {
+ getVideoMetadata(src)
+ .then((data) => {
+ setVideoMetadata(data);
+ })
+ .catch((err) => {
+ console.log('Could not get video metadata', err);
+ });
+ }, [src]);
+
+ useEffect(() => {
+ const {current} = mountState;
+ current.isMounted = true;
+ return () => {
+ current.isMounted = false;
+ };
+ }, []);
+
+ if (!videoMetadata) {
+ return null;
+ }
+
+ return (
+ <div style={containerStyle}>
+ <svg style={svgStyle} role="img" viewBox="0 0 576 512">
+ <path
+ fill="currentColor"
+ d="M336.2 64H47.8C21.4 64 0 85.4 0 111.8v288.4C0 426.6 21.4 448 47.8 448h288.4c26.4 0 47.8-21.4 47.8-47.8V111.8c0-26.4-21.4-47.8-47.8-47.8zm189.4 37.7L416 177.3v157.4l109.6 75.5c21.2 14.6 50.4-.3 50.4-25.8V127.5c0-25.4-29.1-40.4-50.4-25.8z"
+ />
+ </svg>
+ </div>
+ );
+};