0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

RemotionをつかってReactで動画を作成してみる

Last updated at Posted at 2024-12-19

はじめに

こんにちは、エンジニアのkeitaMaxです。

Remotionを使用してみる

インストール

以下コマンドでインストールします。

npm i --save-exact remotion@4.0.240 @remotion/cli@4.0.240

一緒にESLintのプラグインもインストールします。

npm i @remotion/eslint-plugin

以下のように.eslintrc.jsonに追加しました。

  "plugins": [
    "react",
    "tailwindcss",
    "@remotion"
  ],
  "overrides": [
    {
      "files": ["remotion/*.{ts,tsx}"],
      "extends": ["plugin:@remotion/recommended"]
    }
  ],

ファイル

公式通りにやっていきます。以下のようにフォルダを作成しました。

/
└─ remotion
   ├─ Composition.tsx
   ├─ Root.tsx
   └─ index.tsx

それぞれ以下のように公式通りに行なっていきます。

Composition.tsx
export const MyComposition = () => {
  return null
}
Root.tsx
import React from 'react'
import { Composition } from 'remotion'
import { MyComposition } from './Composition'

export const RemotionRoot: React.FC = () => {
  return (
    <>
      <Composition
        id="Empty"
        component={MyComposition}
        durationInFrames={60}
        fps={30}
        width={1280}
        height={720}
      />
    </>
  )
}
index.tsx
import { registerRoot } from "remotion"
import { RemotionRoot } from "./Root"

registerRoot(RemotionRoot)

実行

以下のコマンドで実行してみます。

npx remotion studio remotion/index.ts

するとブラウザが開き以下のような画面が表示されます。

スクリーンショット 2024-12-18 20.15.20.png

# 少しいじってみる

Root.tsx
import React from 'react'
import { Composition } from 'remotion'
import { MyComposition } from './Composition'

export const RemotionRoot: React.FC = () => {
  return (
    <>
      <Composition
        id="Test" // 変更
        component={MyComposition}
        durationInFrames={60}
        fps={30}
        width={1280}
        height={720}
      />
    </>
  )
}
Composition.tsx

export const MyComposition = () => {
  return (
    <div>
      <h1>テスト</h1>
    </div>
  )
}

こんな感じにすると以下のように出てきます。

スクリーンショット 2024-12-18 20.24.56.png

もう少しいじってみる

テストという文字をだんだん消したいと思います。

以下のように修正しました。

Composition.tsx
import { interpolate, useCurrentFrame } from "remotion"

export const MyComposition = () => {
  const frame = useCurrentFrame()
  const opacity = interpolate(frame, [0, 30], [1, 0], {
    extrapolateLeft: "clamp",
    extrapolateRight: "clamp",
  })

  return (
    <h1
      style={{
        opacity,
      }}
    >
      テスト
    </h1>
  )
}

すると、以下のように時間経過で消えていくものができます!

gif.gif

おわりに

この記事での質問や、間違っている、もっといい方法があるといったご意見などありましたらご指摘していただけると幸いです。

最後まで読んでいただきありがとうございました!

参考

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?