Skip to content

Tiktok layout #10

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 14 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion config/layout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,18 @@ export type Dimensions = {
height: number;
};

export const canvasLayout = z.enum(["landscape", "square"]);
export const canvasLayout = z.enum(["landscape", "square", "portrait"]);
export type CanvasLayout = z.infer<typeof canvasLayout>;

export const DIMENSIONS: { [key in CanvasLayout]: Dimensions } = {
landscape: {
width: 1920,
height: 1080,
},
portrait: {
width: 1080,
height: 1920,
},
square: {
width: 1080,
height: 1080,
Expand Down
Binary file added public/safe.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
30 changes: 15 additions & 15 deletions public/tiktok/subs1708622884021.json
Original file line number Diff line number Diff line change
Expand Up @@ -1131,7 +1131,7 @@
"from": 16490,
"to": 16560
},
"text": " n",
"text": "` n`",
"tokens": [
{
"text": " n",
Expand All @@ -1158,7 +1158,7 @@
"from": 16560,
"to": 16770
},
"text": "px",
"text": "`px`",
"tokens": [
{
"text": "px",
Expand All @@ -1185,7 +1185,7 @@
"from": 16770,
"to": 17400
},
"text": " create",
"text": "` create`",
"tokens": [
{
"text": " create",
Expand All @@ -1212,7 +1212,7 @@
"from": 17400,
"to": 17500
},
"text": "-",
"text": "`-`",
"tokens": [
{
"text": "-",
Expand All @@ -1239,7 +1239,7 @@
"from": 17500,
"to": 17990
},
"text": "video",
"text": "`video`",
"tokens": [
{
"text": "video",
Expand All @@ -1266,7 +1266,7 @@
"from": 17990,
"to": 18330
},
"text": "-",
"text": "``",
"tokens": [
{
"text": "-",
Expand All @@ -1293,7 +1293,7 @@
"from": 18330,
"to": 18430
},
"text": "at",
"text": "`@`",
"tokens": [
{
"text": "at",
Expand All @@ -1320,7 +1320,7 @@
"from": 18430,
"to": 18450
},
"text": "-",
"text": "``",
"tokens": [
{
"text": "-",
Expand All @@ -1347,7 +1347,7 @@
"from": 18450,
"to": 19060
},
"text": "latest",
"text": "`latest`",
"tokens": [
{
"text": "latest",
Expand All @@ -1374,7 +1374,7 @@
"from": 19060,
"to": 19370
},
"text": " --",
"text": "` --`",
"tokens": [
{
"text": " --",
Expand All @@ -1401,7 +1401,7 @@
"from": 19370,
"to": 19470
},
"text": "t",
"text": "`t`",
"tokens": [
{
"text": "t",
Expand All @@ -1428,7 +1428,7 @@
"from": 19470,
"to": 19580
},
"text": "ik",
"text": "`ik`",
"tokens": [
{
"text": "ik",
Expand All @@ -1455,7 +1455,7 @@
"from": 19580,
"to": 19670
},
"text": "t",
"text": "`t`",
"tokens": [
{
"text": "t",
Expand All @@ -1482,7 +1482,7 @@
"from": 19670,
"to": 19960
},
"text": "ok",
"text": "`ok`",
"tokens": [
{
"text": "ok",
Expand Down Expand Up @@ -1542,4 +1542,4 @@
]
}
]
}
}
4 changes: 2 additions & 2 deletions public/tiktok/subs1708623779349.json
Original file line number Diff line number Diff line change
Expand Up @@ -2228,7 +2228,7 @@
"from": 24060,
"to": 24510
},
"text": "ions",
"text": "ioned",
"tokens": [
{
"text": "ions",
Expand Down Expand Up @@ -2518,4 +2518,4 @@
]
}
]
}
}
12 changes: 7 additions & 5 deletions remotion/Main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@ export const Main: React.FC<MainProps> = ({
return makeChapters({ scenes: scenesAndMetadata });
}, [scenesAndMetadata]);

const containerStyle: React.CSSProperties = useMemo(() => {
return {
background: COLORS[theme].BACKGROUND,
};
}, [theme]);

if (scenesAndMetadata.length === 0) {
return <NoDataScene theme={theme} />;
}
Expand All @@ -42,11 +48,7 @@ export const Main: React.FC<MainProps> = ({
lastSceneIndex.from + lastSceneIndex.durationInFrames - 1;

return (
<AbsoluteFill
style={{
background: COLORS[theme].BACKGROUND,
}}
>
<AbsoluteFill style={containerStyle}>
{scenesAndMetadata.map((sceneAndMetadata, i) => {
return (
<Scene
Expand Down
14 changes: 7 additions & 7 deletions remotion/Root.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2381,9 +2381,9 @@ export const Root = () => {
id="uber-for-coding"
schema={videoConf}
defaultProps={{
theme: "light",
canvasLayout: "square" as const,
platform: "x",
theme: "light" as const,
canvasLayout: "portrait" as const,
platform: "x" as const,
scenes: [
{
type: "videoscene" as const,
Expand Down Expand Up @@ -9314,8 +9314,8 @@ export const Root = () => {
schema={videoConf}
defaultProps={{
theme: "light" as const,
canvasLayout: "square" as const,
platform: "x",
canvasLayout: "portrait" as const,
platform: "x" as const,
scenes: [
{
type: "videoscene" as const,
Expand Down Expand Up @@ -9491,8 +9491,8 @@ export const Root = () => {
schema={videoConf}
defaultProps={{
theme: "light" as const,
canvasLayout: "square" as const,
platform: "x",
canvasLayout: "portrait" as const,
platform: "x" as const,
scenes: [
{
type: "videoscene" as const,
Expand Down
7 changes: 7 additions & 0 deletions remotion/animations/display-transitions/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import type {
import type { Layout, LayoutAndFade } from "../../layout/layout-types";
import { interpolateLayoutAndFade } from "../interpolate-layout";
import { getLandscapeDisplayEnterOrExit } from "./landscape";
import { getPortraitDisplayEnterOrExit } from "./portrait";
import { getSquareDisplayEnterOrExit } from "./square";

const getDisplayStartOrEndLayout = ({
Expand Down Expand Up @@ -37,6 +38,12 @@ const getDisplayStartOrEndLayout = ({
});
}

if (canvasLayout === "portrait") {
return getPortraitDisplayEnterOrExit({
currentScene,
});
}

throw new Error(`Unknown canvas layout: ${canvasLayout satisfies never}`);
};

Expand Down
20 changes: 20 additions & 0 deletions remotion/animations/display-transitions/portrait.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { VideoSceneAndMetadata } from "../../../config/scenes";
import { LayoutAndFade } from "../../layout/layout-types";

export const getPortraitDisplayEnterOrExit = ({
currentScene,
}: {
currentScene: VideoSceneAndMetadata;
}): LayoutAndFade => {
if (
currentScene.type !== "video-scene" ||
currentScene.layout.displayLayout === null
) {
throw new Error("no transitions on non-video scenes");
}

return {
layout: currentScene.layout.displayLayout,
shouldFadeRecording: false,
};
};
7 changes: 7 additions & 0 deletions remotion/animations/webcam-transitions/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import type {
import type { Layout, LayoutAndFade } from "../../layout/layout-types";
import { interpolateLayoutAndFade } from "../interpolate-layout";
import { getLandscapeWebCamStartOrEndLayout } from "./landscape";
import { getPortraitWebcamStartOrEndLayout } from "./portrait";
import { getSquareWebcamStartOrEndLayout } from "./square";

const getWebCamStartOrEndLayout = ({
Expand Down Expand Up @@ -37,6 +38,12 @@ const getWebCamStartOrEndLayout = ({
});
}

if (canvasLayout === "portrait") {
return getPortraitWebcamStartOrEndLayout({
currentScene,
});
}

throw new Error(`Unknown canvas layout: ${canvasLayout satisfies never}`);
};

Expand Down
16 changes: 16 additions & 0 deletions remotion/animations/webcam-transitions/portrait.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { VideoSceneAndMetadata } from "../../../config/scenes";
import { LayoutAndFade } from "../../layout/layout-types";

export const getPortraitWebcamStartOrEndLayout = ({
currentScene,
}: {
currentScene: VideoSceneAndMetadata;
}): LayoutAndFade => {
if (!currentScene || currentScene.type !== "video-scene") {
throw new Error("no transitions on non-video scenes");
}
return {
layout: currentScene.layout.webcamLayout,
shouldFadeRecording: false,
};
};
6 changes: 4 additions & 2 deletions remotion/calculate-metadata/add-metadata-to-scene.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ import {
SceneVideos,
SelectableScene,
} from "../../config/scenes";
import { calculateSrt } from "../captions/srt/helpers/calculate-srt";
import { MAX_SRT_CHARS_PER_LINE } from "../captions/srt/SrtPreviewAndEditor/srt-max-chars-per-line";
import { subtitleLines } from "../captions/srt/helpers/calculate-srt";
import { getBRollDimensions } from "../layout/get-broll-dimensions";
import { getVideoSceneLayout } from "../layout/get-layout";
import { PLACEHOLDER_DURATION_IN_FRAMES } from "./empty-place-holder";
Expand Down Expand Up @@ -64,9 +65,10 @@ export const addMetadataToScene = async ({
});

const srt = whisperCppOutput
? calculateSrt({
? subtitleLines({
startFrame: actualStartFrame,
whisperCppOutput,
maxCharsPerLine: MAX_SRT_CHARS_PER_LINE,
})
: [];

Expand Down
19 changes: 19 additions & 0 deletions remotion/captions/portrait/PortraitCaptions.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { StaticFile } from "@remotion/studio";
import React from "react";
import { Theme } from "../../../config/themes";
import { Layout } from "../../layout/layout-types";
import { CaptionOverlay } from "../editor/CaptionOverlay";
import { PortraitWords } from "./PortraitWords";

export const PortraitCaptions: React.FC<{
captions: StaticFile;
theme: Theme;
startFrame: number;
webcamLayout: Layout;
}> = ({ captions, startFrame, theme, webcamLayout }) => {
return (
<CaptionOverlay file={captions} theme={theme} trimStart={startFrame}>
<PortraitWords webcamLayout={webcamLayout} startFrame={startFrame} />
</CaptionOverlay>
);
};
Loading