Giter Club home page Giter Club logo

ffmpeg-template-assembly's Introduction

FFmpeg Template Assembly

ffmpeg-template-assembly is a tool designed to streamline the process of video compilation using FFmpeg. It allows for dynamic template generation and video rendering, making it an ideal solution for creating personalized videos programmatically.

Description

This project leverages FFmpeg for video processing, providing an interface to compile videos based on a template descriptor and project configuration. It simplifies the process of generating custom videos by handling complex FFmpeg commands and configurations internally.

Getting Started

Dependencies

Ensure you have the following prerequisites installed:

  • Node.js (v18.x or higher)

Installing

NPM

Install the project dependencies using npm, yarn or pnpm:

pnpm add ffmpeg-template-assembly

Clone Repository

Clone the repository and install the dependencies:

git clone https://github.com/heristop/ffmpeg-template-assembly.git
cd ffmpeg-template-assembly
pnpm i

Configuration

Create a JSON file (e.g., sample.json in the src/shared/templates directory) with your template descriptor.

Usage

Command Line Interface

To use the ffmpeg-template-assembly, you can run the compile command with the path to your template JSON file as an argument:

pnpm compile src/shared/templates/sample.json

This will generate a video named sample_output.mp4 in the build directory.

Importing the Package

Import the compile function from the package and provide a project configuration object:

import { compile, loadConfig } from 'ffmpeg-template-assembly';

// Project Configuration
const projectConfig = {
  assetsDir: './assets',
  currentLocale: 'en',
  fields: {
    form_1_firstname: 'Firsname',
    form_1_lastname: 'Lastname',
  },
};

You might provide a template descriptor to the compile function to generate a video:

compile(projectConfig, {
  global: {
    variables: {
      videoDemo: 'https://github.com/heristop/ffmpeg-template-assembly/raw/develop/src/shared/assets/videos/earth.mp4',
      colorsList: ['#FFFFFF', '#000000'],
    },
    music: {
      name: 'default',
      url: 'https://github.com/heristop/ffmpeg-template-assembly/raw/develop/src/shared/assets/musics/point_being_-_go_by_ocean___ryan_mccaffrey.mp3',
    },
    orientation: 'landscape',
    musicEnabled: true,
    transitionDuration: 0.5,
  },
  sections: [
    {
      name: 'intertitle_1',
      type: 'color_background',
      visibility: ['video_segment'],
      options: {
        backgroundColor: '{{ color2 }}@0.1',
        videoUrl: '{{ videoDemo }}',
        duration: 3,
        musicVolumeLevel: 0.4,
      },
      filters: [
        {
          type: 'drawbox',
          values: {
            x: 0,
            y: 0,
            w: 1280,
            h: 360,
            c: '{{ color1 }}@1',
            t: 'fill',
          },
        },
        {
          type: 'drawtext',
          values: {
            text: {
              en: '{{ form_1_firstname }} {{ form_1_lastname }}',
            },
            fontcolor: '{{ color1 }}',
            fontsize: 40,
            x: '(w-text_w)/2',
            y: '(h-text_h)/1.4',
            fontfile: 'Quicksand.ttf',
            alpha: "'if(lt(t,0.5),0,if(lt(t,1.5),(t-0.5)/1,if(lt(t,5),1,if(lt(t,7),(1-(t-6))/1,0))))'",
          },
        },
      ],
    },
    {
      name: 'video_1',
      type: 'video',
      visibility: ['video_segment'],
      options: {
        videoUrl: '{{ videoDemo }}',
        duration: 4,
        musicVolumeLevel: 1,
      },
      filters: [
        {
          type: 'fadein',
          values: {
            color: '{{ color2 }}',
          },
        },
        {
          type: 'fadeout',
          values: {
            color: '{{ color2 }}',
          },
        },
      ],
    },
  ],
});

Or you might provide a path to the template descriptor JSON file:

await compile(projectConfig, await loadConfig('./src/shared/templates/sample.json'));

Running Tests

To run tests, use the following command:

pnpm test

Architecture

Architecture

Contributing

Contributions are welcome! For major changes, please open an issue first to discuss what you would like to change. Ensure to update tests as appropriate.

License

This project is licensed under the MIT License - see the LICENSE file for details.

ffmpeg-template-assembly's People

Contributors

heristop avatar

Stargazers

 avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.