1.0.1 โ€ข Published 1 year ago

dramadirector v1.0.1

Weekly downloads
-
License
ISC
Repository
github
Last release
1 year ago

DramaDirector

Nodejs video/lottie/audio/text/image schema composition service based on FFmpeg

๐Ÿพ Example

  • Start the demo
npm i
npm run build
npm run demo
  • ใ€optionalใ€‘By excuting npm run demo 1 , generate the video by stream mode.
  • Then you can see demo.mp4 in example folder.

๐Ÿ’ซ How to generate a schema for your own composition?

You can refer to the schema.js in the demo folde. The example in this file includes the basic attributes required for the basic elements in video composition.

Basically, the schema comprises basic info(name,width,height,duration) and layers info. And each layer comprises several or single items.

๐Ÿ’พ Layer

  • index: id of this layer
  • type: normal/audio/lottie/text
  • items:items in this layer

๐Ÿ’ฟ VideoItem

  • id : id of this layer
  • type : video
  • url : local path or network link of the resource
  • config : the basic info of the item

attrtypeusage
stnumber/srtingthe start time of the item in the whole production
etnumber/srtingthe end time of the item in the whole production
seeknumber/srtingfrom which second does the item start playing
xnumber/srtingposition x
ynumber/srtingposition y
  • effects : the effects on the items(filters like scale,blur, follow the rule of fluent-ffmpeg)

    attrtypeusage
    nmstringname of filter
    optionsstring/objectoption of filter

๐ŸŽ‡ ImageItem

  • id : id of this layer
  • type : image
  • url : local path or network link of the resource
  • config: the basic info of the item
  • effects : the effects on the items(filters like scale,blur, follow the rule of fluent-ffmpeg)

๐ŸŽŠ LottieItem

  • id : id of this layer
  • type : lottie
  • lottie : object of lottieJson
  • config: the basic info of the item

attrtypeusage
stnumber/srtingthe start time of the item in the whole production
etnumber/srtingthe end time of the item in the whole production
seeknumber/srtingfrom which second does the item start playing
xnumber/srtingposition x
ynumber/srtingposition y
fpsnumber/srtingframe rate
wnumber/srtingwidth, currently needed
hnumber/srtingheight, currently needed
  • effects : ใ€TODOใ€‘the effects on the items(filters like crop,blur, follow the rule of fluent-ffmpeg)

๐ŸŽผ TextItem

  • id : id of this layer
  • type : text
  • url : local path or network link of the resource
  • config: the basic info of the item

attrtypeusage
stnumber/srtingthe start time of the item in the whole production
etnumber/srtingthe end time of the item in the whole production
textstringtext
fontcolorstringcolor of text
fontsizenumber/stringsize of font
bordercolorstringcolor of inner border
borderwnumber/stringwidth of inner border
obcstringcolor of outer border
obwnumber/stringcolor of outer border
ttfPathstringlocal path of .ttf file
  • effects : the effects on the items(filters like scale, follow the rule of fluent-ffmpeg)

๐ŸŽผ AudioItem

  • id : id of this layer
  • type : lottie
  • url : local path or network link of the resource
  • config: the basic info of the item

attrtypeusage
stnumber/srtingthe start time of the item in the whole production
etnumber/srtingthe end time of the item in the whole production
seeknumber/srtingfrom which second does the item start playing
  • effects : the effects on the items(filters like volume, follow the rule of fluent-ffmpeg)

By using ffmpeg-utils in effects, you can even achieve the effect of keyframe animation.

Consume the schema

const DramaCore = require('../dist').default
// The schema described how the product is organized
const darmaSchema = require('./schema')
const path = require('path')
const fs = require('fs');
const [, , useStream] = process.argv;
async function run() {
    const saveFilePath=path.join(__dirname, 'demo.mp4');
    const director = new DramaCore(darmaSchema)
    console.time('task')
    if(useStream){
        const stream = director.getStream();
        const outputStream = fs.createWriteStream(saveFilePath);
        stream.pipe(outputStream);
        outputStream.on('finish', () => {
            console.timeEnd('task')
        })
    }else{
        director.save(saveFilePath).then(() => {
            console.timeEnd('task')
        }).catch(err => {
            console.log(err)
        });
    }
}
run()