fix: adapt to vertical resolution and fix flickering

This commit is contained in:
sai80082 committed 2024-12-02 12:44:28 +05:30
1 parent 7f359c10d7
commit 8312fc183d
5 files changed
+341 -270

No files matched your search

+62 -71
View File
@@ -1,51 +1,61 @@
/* eslint-disable @next/next/no-img-element */ import React, { useMemo } from 'react';
import React, { useMemo, useRef } from 'react' import { Img, spring, useCurrentFrame, useVideoConfig } from 'remotion';
import { spring, useCurrentFrame, useVideoConfig } from 'remotion';
interface AlbumsSceneProps { interface AlbumSceneProps {
message: string; message: string;
emoji: string; emoji: string;
data: { data: {
photos: number;
albums: { albums: {
name: string; name: string;
cover: string; cover: string;
}[]; }[];
}; };
} }
export default function AlbumsScene({ message, emoji, data }: AlbumsSceneProps) {
const albums = useMemo(() => data.albums.map((album, index) => ({ export default function AlbumScene({ message, emoji, data }: AlbumSceneProps) {
name: album.name,
cover: album.cover,
})), [data.albums]);
const frame = useCurrentFrame(); const frame = useCurrentFrame();
const { fps } = useVideoConfig(); const { fps } = useVideoConfig();
const initialDelay = useRef(frame);
const albums = useMemo(() => data.albums, [data.albums]);
return ( return (
<div style={{ <div style={{
display: "flex", display: "flex",
flexDirection: "column", flexDirection: "column",
alignItems: "center", alignItems: "center",
justifyContent: "center", justifyContent: "center",
animation: "zoomIn 1s ease forwards", height: "100%",
padding: "20px",
gap: 40
}}> }}>
<p style={{ <div style={{
fontSize: 70, display: "flex",
padding: "0 70px", flexDirection: "column",
color: "lightblue", alignItems: "center",
marginTop: 40, gap: 20
textAlign: "center",
transition: "opacity 1s ease",
}}> }}>
{message} <span style={{ fontSize: 80 }}>{emoji}</span>
</p> <h1 style={{
fontSize: 50,
color: "white",
textAlign: "center",
margin: 0,
maxWidth: "80%"
}}>
{message}
</h1>
</div>
<div style={{ <div style={{
display: "grid", display: "grid",
gridTemplateColumns: "repeat(4, 1fr)", gridTemplateColumns: "repeat(2, 1fr)",
gap: 20, gap: 20,
width: "100%",
maxWidth: 600
}}> }}>
{albums.map((album, index) => { {albums.map((album, index) => {
const delay = (initialDelay.current) + (index * 0.1 * fps); const delay = index * 5;
const scale = spring({ const scale = spring({
frame: frame - delay, frame: frame - delay,
fps, fps,
@@ -57,56 +67,37 @@ export default function AlbumsScene({ message, emoji, data }: AlbumsSceneProps)
}); });
return ( return (
<div key={index} style={{ <div
border: "1px solid lightblue", key={album.name}
borderRadius: 10, style={{
padding: 10,
}}>
<img
key={index}
src={album.cover}
alt="memory"
style={{
width: 200,
height: 200,
objectFit: "cover",
borderRadius: 10,
margin: 10,
transform: `scale(${scale})`, transform: `scale(${scale})`,
}} opacity: scale,
/> }}
<p style={{ >
fontSize: 20, <Img
textAlign: "center", src={album.cover}
marginTop: 10, alt={album.name}
color: "lightblue", style={{
}}> width: "100%",
{album.name} height: 200,
</p> objectFit: "cover",
borderRadius: 15,
boxShadow: "0 4px 8px rgba(0,0,0,0.2)",
}}
/>
<p style={{
color: "white",
fontSize: 18,
textAlign: "center",
margin: "10px 0",
fontWeight: "bold"
}}>
{album.name}
</p>
</div> </div>
) );
})} })}
</div> </div>
</div> </div>
) );
} }
// Add this CSS to your global styles or a CSS-in-JS solution
const styles = `
@keyframes zoomIn {
from {
transform: scale(0.5);
opacity: 0;
}
to {
transform: scale(1);
opacity: 1;
}
}
`;
// Inject styles into the document
const styleSheet = document.createElement("style");
styleSheet.type = "text/css";
styleSheet.innerText = styles;
document.head.appendChild(styleSheet);
+48 -52
View File
@@ -1,55 +1,59 @@
import React from 'react' import React, { useMemo } from 'react';
import { spring, useCurrentFrame, useVideoConfig, interpolate } from 'remotion'; import { spring, useCurrentFrame, useVideoConfig } from 'remotion';
interface CountrySceneProps { interface CountrySceneProps {
message: string; message: string;
emoji: string; emoji: string;
data: any; data: {
countries: string[];
};
} }
export default function CountryScene({ message, emoji, data }: CountrySceneProps) { export default function CountryScene({ message, emoji, data }: CountrySceneProps) {
const frame = useCurrentFrame(); const frame = useCurrentFrame();
const { fps } = useVideoConfig(); const { fps } = useVideoConfig();
const countries = data.countries as string[];
const countries = useMemo(() => data.countries, [data.countries]);
// Message animation (takes 1 second to appear)
const messageOpacity = interpolate(
frame,
[240, 260],
[0, 1],
{ extrapolateRight: 'clamp' }
);
return ( return (
<div style={{ <div style={{
display: "flex", display: "flex",
flexDirection: "column", flexDirection: "column",
alignItems: "center", alignItems: "center",
justifyContent: "center", justifyContent: "center",
height: "100%",
gap: 40
}}> }}>
<p style={{
fontSize: 40,
color: "lightblue",
marginTop: 40,
textAlign: "center",
padding: "0 20px",
opacity: messageOpacity,
}}>
{message}
</p>
<div style={{ <div style={{
display: "flex", display: "flex",
flexDirection: "row", flexDirection: "column",
flexWrap: "wrap",
alignItems: "center", alignItems: "center",
justifyContent: "center", gap: 20
padding: 20,
gap: 10,
width: "70%",
}}> }}>
{countries.map((country: string, index: number) => { <span style={{
// Start countries after message (1 second) with 0.3 second delay between each fontSize: 100
const delay = (240) + (index * 0.1 * fps); }}>
{emoji}
</span>
<h1 style={{
fontSize: 70,
color: "white",
textAlign: "center",
margin: 0
}}>
{message}
</h1>
</div>
<div style={{
display: "flex",
flexWrap: "wrap",
gap: 20,
justifyContent: "center",
maxWidth: "80%"
}}>
{countries.map((country, index) => {
const delay = index * 5;
const scale = spring({ const scale = spring({
frame: frame - delay, frame: frame - delay,
fps, fps,
@@ -61,29 +65,21 @@ export default function CountryScene({ message, emoji, data }: CountrySceneProps
}); });
return ( return (
<div key={country} style={{ <div
borderColor: "lightblue", key={country}
borderRadius: "25px", style={{
height: 50, backgroundColor: "rgba(255,255,255,0.1)",
display: "flex", padding: "10px 20px",
alignItems: "center", borderRadius: 15,
justifyContent: "center", transform: `scale(${scale})`,
color: "lightblue", opacity: scale,
padding: "0px 20px", }}
fontSize: 20, >
textAlign: "center", <span style={{ color: "white", fontSize: 24 }}>{country}</span>
borderWidth: 1,
borderStyle: "solid",
transform: `scale(${scale})`,
opacity: scale,
}}>
<div>
<p style={{ margin: 0 }}>{country}</p>
</div>
</div> </div>
); );
})} })}
</div> </div>
</div> </div>
) );
} }
+98 -70
View File
@@ -1,6 +1,5 @@
/* eslint-disable @next/next/no-img-element */ import React from 'react';
import React, { useMemo, useRef } from 'react' import { Img, spring, useCurrentFrame, useVideoConfig } from 'remotion';
import { spring, useCurrentFrame, useVideoConfig } from 'remotion';
interface FriendsSceneProps { interface FriendsSceneProps {
message: string; message: string;
@@ -12,100 +11,129 @@ interface FriendsSceneProps {
}[]; }[];
}; };
} }
export default function FriendsScene({ message, emoji, data }: FriendsSceneProps) { export default function FriendsScene({ message, emoji, data }: FriendsSceneProps) {
const friends = useMemo(() => data.friends.map((friend, index) => ({
name: friend.name,
cover: friend.cover,
})), [data.friends]);
const frame = useCurrentFrame(); const frame = useCurrentFrame();
const { fps } = useVideoConfig(); const { fps } = useVideoConfig();
const initialDelay = useRef(frame);
return ( return (
<div style={{ <div style={{
display: "flex", display: "flex",
flexDirection: "column", flexDirection: "column",
alignItems: "center", alignItems: "center",
justifyContent: "center", justifyContent: "center",
animation: "zoomIn 1s ease forwards", height: "100%",
padding: "20px"
}}> }}>
<p style={{
fontSize: 70,
padding: "0 70px",
color: "lightblue",
marginTop: 40,
textAlign: "center",
transition: "opacity 1s ease",
}}>
{message}
</p>
<div style={{ <div style={{
display: "flex", display: "flex",
flexDirection: "row", flexDirection: "column",
alignItems: "center",
gap: 20, gap: 20,
marginBottom: 40,
opacity: spring({
frame,
fps,
from: 0,
to: 1,
config: {
mass: 0.5,
damping: 20,
}
})
}}> }}>
{friends.map((friend, index) => { <span style={{
const delay = (initialDelay.current) + (index * 0.1 * fps); fontSize: 80,
transform: `translateY(${spring({
frame,
fps,
from: 0,
to: -10,
config: {
mass: 0.3,
damping: 10,
stiffness: 100
}
})}px)`
}}>{emoji}</span>
<h1 style={{
fontSize: 50,
color: "white",
textAlign: "center",
margin: 0,
maxWidth: "80%",
textShadow: "2px 2px 4px rgba(0,0,0,0.2)"
}}>
{message}
</h1>
</div>
<div style={{
display: "flex",
gap: 30,
justifyContent: "center",
width: "100%"
}}>
{data.friends.map((friend, index) => {
const delay = index * 5;
const scale = spring({ const scale = spring({
frame: frame - delay, frame: frame - delay,
fps, fps,
from: 0, from: 0,
to: 1, to: 1,
config: { config: {
damping: 12, mass: 0.8,
damping: 15,
stiffness: 100
},
});
const rotation = spring({
frame: frame - delay,
fps,
from: 0,
to: index % 2 === 0 ? 8 : -8,
config: {
mass: 0.5,
damping: 20,
stiffness: 80
}, },
}); });
return ( return (
<div key={index} style={{ <div
borderRadius: 10, key={friend.name}
padding: 10, style={{
}}> transform: `scale(${scale}) rotate(${rotation}deg)`,
<img opacity: scale
key={index} }}
src={friend.cover} >
alt="memory" <Img
style={{ src={friend.cover}
width: 200, alt={friend.name}
height: 200, style={{
objectFit: "cover", width: 200,
borderRadius: "100%", height: 200,
margin: 10, objectFit: "cover",
transform: `scale(${scale})`, borderRadius: "50%",
}} border: "8px solid white",
/> boxShadow: "0 8px 16px rgba(0,0,0,0.2)",
<p style={{ }}
fontSize: 20, />
textAlign: "center", <p style={{
marginTop: 10, color: "white",
color: "lightblue", fontSize: 24,
}}> textAlign: "center",
margin: "15px 0",
fontWeight: "bold",
textShadow: "1px 1px 2px rgba(0,0,0,0.2)"
}}>
{friend.name} {friend.name}
</p> </p>
</div> </div>
) );
})} })}
</div> </div>
</div> </div>
) );
} }
// Add this CSS to your global styles or a CSS-in-JS solution
const styles = `
@keyframes zoomIn {
from {
transform: scale(0.5);
opacity: 0;
}
to {
transform: scale(1);
opacity: 1;
}
}
`;
// Inject styles into the document
const styleSheet = document.createElement("style");
styleSheet.type = "text/css";
styleSheet.innerText = styles;
document.head.appendChild(styleSheet);
+81 -48
View File
@@ -1,5 +1,5 @@
import React, { useMemo, useRef } from 'react' import React, { useMemo, useRef } from 'react'
import { spring, useCurrentFrame, useVideoConfig } from 'remotion'; import { Img, spring, useCurrentFrame, useVideoConfig } from 'remotion';
interface MemoriesSceneProps { interface MemoriesSceneProps {
message: string; message: string;
@@ -11,60 +11,113 @@ interface MemoriesSceneProps {
export default function MemoriesScene({ message, emoji, data }: MemoriesSceneProps) { export default function MemoriesScene({ message, emoji, data }: MemoriesSceneProps) {
const images = useMemo(() => data.images.map((image, index) => ({ const images = useMemo(() => data.images.map((image, index) => ({
src: image, src: image,
rotate: `${(index % 2 === 0 ? 1 : -1) * Math.random() * 10}deg`, rotate: (index % 2 === 0 ? 1 : -1) * 8,
})), [data.images]); })), [data.images]);
const frame = useCurrentFrame(); const frame = useCurrentFrame();
const { fps } = useVideoConfig(); const { fps } = useVideoConfig();
const initialDelay = useRef(frame);
const messageOpacity = spring({
frame,
fps,
from: 0,
to: 1,
config: {
mass: 0.5,
damping: 20,
stiffness: 100
}
});
const messageY = spring({
frame,
fps,
from: -20,
to: 0,
config: {
mass: 0.5,
damping: 20,
stiffness: 100
}
});
return ( return (
<div style={{ <div style={{
display: "flex", display: "flex",
flexDirection: "column", flexDirection: "column",
alignItems: "center", alignItems: "center",
justifyContent: "center", justifyContent: "center",
animation: "zoomIn 1s ease forwards", height: "100%",
padding: "20px 0"
}}> }}>
<p style={{
fontSize: 70,
padding: "0 70px",
color: "lightblue",
marginTop: 40,
textAlign: "center",
transition: "opacity 1s ease",
}}>
{message}
</p>
<div style={{ <div style={{
display: "flex", opacity: messageOpacity,
flexDirection: "row", transform: `translateY(${messageY}px)`,
gap: 10,
}}> }}>
{images.map((image, index) => { <span style={{
const delay = (initialDelay.current) + (index * 0.1 * fps); fontSize: 80,
display: "block",
textAlign: "center",
marginBottom: 20
}}>{emoji}</span>
<p style={{
fontSize: 50,
padding: "0 40px",
color: "white",
marginBottom: 40,
textAlign: "center",
textShadow: "2px 2px 4px rgba(0,0,0,0.2)"
}}>
{message}
</p>
</div>
<div style={{
display: "grid",
gridTemplateColumns: "repeat(2, 1fr)",
gap: 30,
maxWidth: "90%",
placeItems: "center",
}}>
{images.slice(0, 4).map((image, index) => {
const delay = index * 5;
const scale = spring({ const scale = spring({
frame: frame - delay, frame: frame - delay,
fps, fps,
from: 0, from: 0,
to: 1, to: 1,
config: { config: {
damping: 12, mass: 0.8,
damping: 15,
stiffness: 100
},
});
const rotation = spring({
frame: frame - delay,
fps,
from: 0,
to: image.rotate, // Use the stable rotation value directly
config: {
mass: 0.5,
damping: 20,
stiffness: 80
}, },
}); });
return ( return (
<img <Img
key={index} key={index}
src={image.src} src={image.src}
alt="memory" alt="memory"
style={{ style={{
width: 200, width: 280,
height: 200, height: 280,
objectFit: "cover", objectFit: "cover",
borderRadius: 10, borderRadius: 15,
margin: 10, transform: `scale(${scale}) rotate(${rotation}deg)`,
rotate: image.rotate, opacity: scale,
transform: `scale(${scale})`, boxShadow: "0 8px 16px rgba(0,0,0,0.3)",
border: "8px solid white"
}} }}
/> />
) )
@@ -73,23 +126,3 @@ export default function MemoriesScene({ message, emoji, data }: MemoriesScenePro
</div> </div>
) )
} }
// Add this CSS to your global styles or a CSS-in-JS solution
const styles = `
@keyframes zoomIn {
from {
transform: scale(0.5);
opacity: 0;
}
to {
transform: scale(1);
opacity: 1;
}
}
`;
// Inject styles into the document
const styleSheet = document.createElement("style");
styleSheet.type = "text/css";
styleSheet.innerText = styles;
document.head.appendChild(styleSheet);
+52 -29
View File
@@ -1,58 +1,81 @@
import React from 'react' import React from 'react'
import { spring, useCurrentFrame, useVideoConfig, interpolate } from 'remotion'
interface WelcomeSceneProps { interface WelcomeSceneProps {
message: string; message: string;
emoji: string; emoji: string;
} }
export default function WelcomeScene({ message, emoji }: WelcomeSceneProps) { export default function WelcomeScene({ message, emoji }: WelcomeSceneProps) {
const frame = useCurrentFrame();
const { fps } = useVideoConfig();
const scale = spring({
frame,
fps,
from: 0.5,
to: 1,
config: { damping: 12 }
});
const opacity = spring({
frame,
fps,
from: 0,
to: 1,
config: { damping: 12 }
});
const rotation = spring({
frame,
fps,
from: -5,
to: 0,
config: { damping: 12 }
});
const hue = interpolate(
frame,
[0, 60],
[180, 240],
{ extrapolateRight: 'clamp' }
);
return ( return (
<div style={{ <div style={{
display: "flex", display: "flex",
flexDirection: "column", flexDirection: "column",
alignItems: "center", alignItems: "center",
justifyContent: "center", justifyContent: "center",
animation: "zoomIn 1s ease forwards", transform: `scale(${scale})`,
opacity: opacity,
background: `radial-gradient(circle, rgba(0,0,0,0) 0%, rgba(0,0,0,0.3) 100%)`,
padding: 40,
borderRadius: 20,
}}> }}>
<p style={{ <p style={{
fontSize: 100, fontSize: 120,
color: "lightblue",
marginTop: 40, marginTop: 40,
marginBottom: 0, marginBottom: 0,
textAlign: "center", textAlign: "center",
transition: "opacity 1s ease", transform: `translateY(${Math.sin(frame / 30) * 10}px) rotate(${rotation}deg)`,
textShadow: '0 0 20px rgba(255,255,255,0.5)',
}}> }}>
{emoji} {emoji}
</p> </p>
<p style={{ <p style={{
fontSize: 70, fontSize: 80,
padding: "0 70px", padding: "0 70px",
color: "lightblue", color: `hsl(${hue}, 80%, 75%)`,
marginTop: 0, marginTop: 20,
textAlign: "center", textAlign: "center",
transition: "opacity 1s ease", fontWeight: "bold",
textShadow: '0 0 15px rgba(255,255,255,0.3)',
letterSpacing: "2px",
lineHeight: 1.2
}}> }}>
{message} {message}
</p> </p>
</div> </div>
) )
} }
// Add this CSS to your global styles or a CSS-in-JS solution
const styles = `
@keyframes zoomIn {
from {
transform: scale(0.5);
opacity: 0;
}
to {
transform: scale(1);
opacity: 1;
}
}
`;
// Inject styles into the document
const styleSheet = document.createElement("style");
styleSheet.type = "text/css";
styleSheet.innerText = styles;
document.head.appendChild(styleSheet);