editly

repository·master·Indexed 26 days ago

https://github.com/mifi/editly

A declarative non-linear video editing (NLE) tool and framework built on Node.js and ffmpeg. It allows developers to programmatically generate videos from clips, images, and audio using a JavaScript API or a CLI. Features include support for various aspect ratios, text overlays, GL shaders, and custom HTML5 Canvas/Fabric.js screens. Version 0.15.0-rc.1 is ESM only.

Tokens
6.7K
Snippets
14
Records
35
Agent score
90%

What's inside editly

  1. Overview of Editly

    master
    Editly is a tool and framework for declarative non-linear video editing (NLE) using Node.js and ffmpeg. It allows you to programmatically create videos from clips, images, audio, and titles using a streaming editing approach. It supports various aspect ratios (e.g., 1:1, 9:16, 16:9), automatic scaling/letterboxing, and features like text overlays, custom HTML5 Canvas/Fabric.js screens, and GL shaders.
  2. Run editly using Docker

    master

    To use editly as a containerized CLI without managing local dependencies, you can use the provided Docker Compose setup. This involves cloning the repository, setting up assets, and running the container.

    $ git clone https://github.com/mifi/editly.git
    $ cd editly/examples
    $ git clone https://github.com/mifi/editly-assets.git assets
    $ cd ..
    $ docker-compose up
    $ docker-compose run editly bash -c "cd examples && editly audio1.json5 --out /outputs/audio1.mp4"
    $ docker cp editly:/outputs/audio1.mp4 .
  3. Use the Editly CLI for quick video assembly

    master

    You can use the Editly CLI to quickly assemble a video from a sequence of clips, images, and titles, or by providing a JSON/JSON5 edit specification file.

    Quick randomized edit

    Create a video by listing assets directly in the command:

    editly \
      title:'My video' \
      clip1.mov \
      clip2.mov \
      title:'My slideshow' \
      img1.jpg \
      img2.jpg \
      title:'THE END' \
      --fast \
      --audio-file-path /path/to/music.mp3

    Create video from an edit spec

    Use a JSON or JSON5 file to define a complex edit:

    editly my-spec.json5 --fast --keep-source-audio --out output.gif

    CLI Behavior

    • By default (without --fast), Editly uses the width, height, and frame rate from the first input video. All other clips will be converted to these dimensions.
    • Use --fast to skip certain processing steps.
  4. Requirements for Editly

    master

    To use Editly, ensure you meet the following requirements:

    • Operating System: Windows, MacOS, or Linux.
    • Node.js: Latest LTS version is recommended (v12.16.2 or newer on MacOS).
    • FFmpeg: ffmpeg and ffprobe must be installed and available in your PATH.
    • Linux Users: May require extra steps for headless-gl system dependencies.
    • Module System: Editly is ESM only.
  5. Define an Edit Spec

    master

    An Edit Spec is a JavaScript or JSON object that describes the entire video editing operation. It includes global settings (width, height, fps), default layer/transition settings, and a list of clips. Each clip contains one or more layers that are overlaid in sequence.

    {
      outPath,
      width,
      height,
      fps,
      allowRemoteRequests: false,
      defaults: {
        duration: 4,
        transition: {
          duration: 0.5,
          name: 'random',
          audioOutCurve: 'tri',
          audioInCurve: 'tri',
        },
        layer: {
          fontPath,
        },
        layerType: {
          'fill-color': {
            color: '#ff6666',
          }
        },
      },
      clips: [
        {
          transition,
          duration,
          layers: [
            {
              type,
            }
          ],
        }
      ],
      audioFilePath,
      loopAudio: false,
      keepSourceAudio: false,
      clipsAudioVolume: 1,
      outputVolume: 1,
      audioTracks: [
        {
          path,
          mixVolume: 1,
          cutFrom: 0,
          cutTo,
          start: 0,
        }
      ],
      audioNorm: {
        enable: false,
        gaussSize: 5,
        maxGain: 30,
      },
      enableFfmpegLog: false,
      verbose: false,
      fast: false,
    }
  6. Run Editly using Docker Compose

    master

    You can run Editly as a containerized service using Docker Compose. The service uses the editly/editly:latest image.

    To persist generated videos, the configuration uses a named volume outputs mapped to /outputs inside the container. It also maps a local directory ./examples/assets/ to /app/examples/assets/ inside the container to provide assets for editing tasks.

    services:
      editly:
        container_name: editly
        image: editly/editly:latest
        build:
          context: .
          dockerfile: Dockerfile
        volumes:
          - "outputs:/outputs"
          - ./examples/assets/:/app/examples/assets/
    
    volumes:
      outputs:
  7. Use the editly CLI to create videos

    master

    The editly command allows you to create videos from the command line using either a sequence of clips or a JSON/JSON5 edit specification file.

    Basic Usage (Clip Sequence)

    You can pass video files, images, or title screens directly as arguments. Title screens must be prefixed with title:.

    $ editly title:'My video' clip1.mov clip2.mov title:'My slideshow' img1.jpg

    Usage with JSON/JSON5

    You can provide a path to a JSON or JSON5 file containing a full edit specification.

    $ editly my-editly.json5 --out output.gif
    $ editly title:'My video' clip1.mov clip2.mov title:'My slideshow' img1.jpg img2.jpg title:'THE END' --audio-file-path /path/to/music.mp3 --font-path /path/to/my-favorite-font.ttf
  8. Troubleshoot editly installation and runtime errors

    master

    If you encounter issues while using editly, check the following common solutions:

    • Error: The specified module could not be found.: Reinstall editly by building from source: npm un -g editly && npm i -g --build-from-source editly.
    • Error: gl returning null: Review the project's Requirements section (check system dependencies like OpenGL/WebGL support).
    • Error: /bin/sh: pkg-config: command not found: Ensure you are using the newest Node.js LTS version.
  9. Use Video Layers

    master

    Video layers allow you to play video files within a clip. If the clip.duration is specified, the video will be automatically slowed or sped up to match that duration.

    Parameters:

    • type: Must be 'video'.
    • path: Path to the video file.
    • resizeMode: How to fit the video to the screen (contain, contain-blur, cover, stretch). Default is contain-blur.
    • cutFrom / cutTo: Time values (seconds) to segment the source video.
    • width / height: Relative size (0 to 1) compared to screen dimensions.
    • left / top: X/Y position relative to screen (0 to 1).
    • originX / originY: Anchor point (left/right and top/bottom).
    • mixVolume: Relative volume for this video's audio.
  10. Use Audio Layers and Tracks

    master

    There are three ways to handle audio:

    1. Layer type 'audio': Part of a clip. Audio is mixed with other layers. If cutFrom/cutTo is set, the audio is sped up/slowed down to fit the clip.duration (limit: 0.5x to 100x).
    2. Layer type 'detached-audio': Similar to audioTracks, but the start time is relative to the start of the clip it is placed in.
    3. audioTracks[]: Arbitrary audio tracks that can play across multiple clips. They use global video time for the start parameter.

    Audio Track Parameters:

    • path: File path.
    • mixVolume: Relative volume (default 1).
    • cutFrom / cutTo: Segment the source file.
    • start: Seconds into the video to start this track.
  11. Use Editly as a JavaScript library

    master

    Import editly and call it with an editSpec object. Since Editly is ESM only, ensure your environment supports ES modules.

    import editly from "editly";
    
    // See editSpec documentation
    await editly(editSpec);
    import editly from "editly";
    
    // See editSpec documentation
    await editly(editSpec);