Update Remotion-app/src/HelloWorld/TextStream.jsx
Browse files
Remotion-app/src/HelloWorld/TextStream.jsx
CHANGED
@@ -1,11 +1,27 @@
|
|
1 |
import React, {useMemo} from 'react';
|
2 |
-
import {
|
|
|
|
|
|
|
|
|
|
|
|
|
3 |
import * as Fonts from '@remotion/google-fonts';
|
4 |
import transcriptData from './Assets/TextSequences.json';
|
5 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
6 |
const defaultText = {
|
7 |
fontFamily: 'Luckiest Guy',
|
8 |
-
fontSize:
|
9 |
textAlign: 'center',
|
10 |
textShadow:
|
11 |
'-10px -10px 0 #000, 0 -10px 0 #000, 10px -10px 0 #000, 10px 0 0 #000, 10px 10px 0 #000, 0 10px 0 #000, -10px 10px 0 #000, -10px 0 0 #000',
|
@@ -31,30 +47,40 @@ Fonts.getAvailableFonts()
|
|
31 |
|
32 |
const TextStream = React.memo(() => {
|
33 |
const {fps} = useVideoConfig();
|
34 |
-
|
35 |
const memoizedTranscriptData = useMemo(() => {
|
36 |
return transcriptData;
|
37 |
}, []);
|
38 |
-
|
39 |
return (
|
40 |
<AbsoluteFill
|
41 |
style={{
|
42 |
-
backgroundColor: '
|
43 |
justifyContent: 'center',
|
44 |
alignItems: 'center',
|
45 |
}}
|
46 |
>
|
47 |
<Series>
|
48 |
-
{
|
49 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
50 |
return (
|
51 |
<Series.Sequence
|
52 |
style={subtitle}
|
53 |
key={index}
|
54 |
-
from={
|
55 |
-
durationInFrames={fps *
|
56 |
>
|
57 |
-
<Letter style={subtitle}>
|
|
|
|
|
58 |
</Series.Sequence>
|
59 |
);
|
60 |
})}
|
@@ -63,8 +89,36 @@ const TextStream = React.memo(() => {
|
|
63 |
);
|
64 |
});
|
65 |
|
66 |
-
const Letter =
|
67 |
-
|
68 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
69 |
|
70 |
export default TextStream;
|
|
|
1 |
import React, {useMemo} from 'react';
|
2 |
+
import {
|
3 |
+
useVideoConfig,
|
4 |
+
AbsoluteFill,
|
5 |
+
TransitionSeries,
|
6 |
+
Series,
|
7 |
+
useCurrentFrame,
|
8 |
+
} from 'remotion';
|
9 |
import * as Fonts from '@remotion/google-fonts';
|
10 |
import transcriptData from './Assets/TextSequences.json';
|
11 |
+
|
12 |
+
function chunkArray(array, chunkSize) {
|
13 |
+
const chunks = [];
|
14 |
+
for (let i = 0; i < array.length; i += chunkSize) {
|
15 |
+
chunks.push(array.slice(i, i + chunkSize));
|
16 |
+
}
|
17 |
+
return chunks;
|
18 |
+
}
|
19 |
+
|
20 |
+
import {TransitionSeries} from '@remotion/transitions';
|
21 |
+
const Constants = {};
|
22 |
const defaultText = {
|
23 |
fontFamily: 'Luckiest Guy',
|
24 |
+
fontSize: 80,
|
25 |
textAlign: 'center',
|
26 |
textShadow:
|
27 |
'-10px -10px 0 #000, 0 -10px 0 #000, 10px -10px 0 #000, 10px 0 0 #000, 10px 10px 0 #000, 0 10px 0 #000, -10px 10px 0 #000, -10px 0 0 #000',
|
|
|
47 |
|
48 |
const TextStream = React.memo(() => {
|
49 |
const {fps} = useVideoConfig();
|
50 |
+
const frame = useCurrentFrame();
|
51 |
const memoizedTranscriptData = useMemo(() => {
|
52 |
return transcriptData;
|
53 |
}, []);
|
54 |
+
const chunks = chunkArray(memoizedTranscriptData, 3);
|
55 |
return (
|
56 |
<AbsoluteFill
|
57 |
style={{
|
58 |
+
//backgroundColor: 'red',
|
59 |
justifyContent: 'center',
|
60 |
alignItems: 'center',
|
61 |
}}
|
62 |
>
|
63 |
<Series>
|
64 |
+
{chunks.map((chunk, index) => {
|
65 |
+
let delta = 0;
|
66 |
+
if (chunk.length > 1) {
|
67 |
+
const end = chunk[chunk.length - 1].end;
|
68 |
+
const start = chunk[0].start;
|
69 |
+
delta = end - start;
|
70 |
+
} else {
|
71 |
+
delta = chunk[0].end - chunk[0].start;
|
72 |
+
}
|
73 |
+
|
74 |
return (
|
75 |
<Series.Sequence
|
76 |
style={subtitle}
|
77 |
key={index}
|
78 |
+
from={delta * fps}
|
79 |
+
durationInFrames={fps * delta}
|
80 |
>
|
81 |
+
<Letter frame={frame} style={subtitle}>
|
82 |
+
{chunk}
|
83 |
+
</Letter>
|
84 |
</Series.Sequence>
|
85 |
);
|
86 |
})}
|
|
|
89 |
);
|
90 |
});
|
91 |
|
92 |
+
const Letter = ({children, style, frame}) => {
|
93 |
+
const {fps} = useVideoConfig();
|
94 |
+
|
95 |
+
return (
|
96 |
+
<div style={style} className="flex space-x-5 justify-center flex-wrap">
|
97 |
+
{children.map((item, index) => {
|
98 |
+
const {text, start, end} = item;
|
99 |
+
console.log('text', text, start * fps, end * fps, frame);
|
100 |
+
return (
|
101 |
+
<div
|
102 |
+
key={index}
|
103 |
+
className=" rounded-3xl p-1"
|
104 |
+
style={{
|
105 |
+
backgroundColor: `${
|
106 |
+
frame >= start * fps && frame <= end * fps
|
107 |
+
? 'black'
|
108 |
+
: 'transparent'
|
109 |
+
}`,
|
110 |
+
// fontSize: style.fontSize,
|
111 |
+
// opacity: 1,
|
112 |
+
// transition: 'opacity 0.5s',
|
113 |
+
// transitionDelay: `${start}s`,
|
114 |
+
}}
|
115 |
+
>
|
116 |
+
{text}
|
117 |
+
</div>
|
118 |
+
);
|
119 |
+
})}
|
120 |
+
</div>
|
121 |
+
);
|
122 |
+
};
|
123 |
|
124 |
export default TextStream;
|