3.11.96 • Published 10 months ago

@taktikorg/adipisci-quia v3.11.96

Weekly downloads
-
License
MIT
Repository
github
Last release
10 months ago

@taktikorg/adipisci-quia

Experimental JSON to FFmpeg command line tool for video editing. Because of JSON it's much easier to create and edit video timeline and it's much easier to integrate it with other tools.

npm version License: MIT

Features

  • Supports video, audio and image sources
  • Clip transformation: scale, position, rotation, opacity
  • Clip transitions from/to and cross-fade: fade, smoothup, smoothdown, circlecrop, squeezev, squeezeh and more
  • For non-linear video editing with multiple tracks and clips
  • Minimalistic JSON format
  • No direct ffmpeg or node dependency required

Usage

Install package:

npm install @taktikorg/adipisci-quia

# or 

yarn add @taktikorg/adipisci-quia

# or

pnpm add @taktikorg/adipisci-quia

Import and use it:

import { parseSchema } from '@taktikorg/adipisci-quia';

const ffmpegCommand = parseSchema(schema);

or if you need filter complex part only:

const filter = parseSchema(schema, true);

Example

Tool translates video description from JSON to complex FFmpeg command including all required preprocessing steps, filters and transitions.

timeline

The timeline can be passed either as a JSON string or as a JS object. For example this JSON represent the timeline shown above:

{
  "version": 1,
  "inputs": {
    "source1": {
      "type": "video",
      "file": "samples/bee1920.mp4",
      "hasAudio": false,
      "hasVideo": true,
      "duration": 40
    },
    "source2": {
      "type": "video",
      "file": "samples/book1920.mp4",
      "hasAudio": false,
      "hasVideo": true,
      "duration": 13
    },
    "source3": {
      "type": "video",
      "file": "samples/cows1920.mp4",
      "hasAudio": true,
      "hasVideo": true,
      "duration": 15
    },
    "source4": {
      "type": "video",
      "file": "samples/flowers1920.mp4",
      "hasAudio": true,
      "hasVideo": true,
      "duration": 21
    },
    "audio1": {
      "type": "audio",
      "file": "samples/ever.mp3",
      "hasAudio": true,
      "hasVideo": false,
      "duration": 181
    },
    "audio2": {
      "type": "audio",
      "file": "samples/weekend.mp3",
      "hasAudio": true,
      "hasVideo": false,
      "duration": 208
    },
    "watermark": {
      "type": "image",
      "file": "samples/flower.png",
      "hasAudio": false,
      "hasVideo": true,
      "duration": 0
    }
  },
  "tracks": {
    "track_with_some_videos": {
      "type": "video",
      "clips": [
        {
          "name": "clip1",
          "source": "source1",
          "timelineTrackStart": 3,
          "duration": 2,
          "sourceStartOffset": 10,
          "clipType": "video",
          "transform": {
            "x": 0,
            "y": 0,
            "width": 1920,
            "height": 1080,
            "rotation": 0,
            "opacity": 1
          }
        },
        {
          "name": "clip2",
          "source": "source2",
          "timelineTrackStart": 5,
          "duration": 1,
          "sourceStartOffset": 5,
          "clipType": "video",
          "transform": {
            "x": 0,
            "y": 0,
            "width": 1920,
            "height": 1080,
            "rotation": 0,
            "opacity": 1
          }
        },
        {
          "name": "clip3",
          "source": "source3",
          "timelineTrackStart": 10,
          "duration": 5,
          "sourceStartOffset": 3,
          "clipType": "video",
          "transform": {
            "x": 480,
            "y": 270,
            "width": 960,
            "height": 540,
            "rotation": 45,
            "opacity": 0.5
          }
        },
        {
          "name": "clip4",
          "source": "source1",
          "timelineTrackStart": 15,
          "duration": 5,
          "sourceStartOffset": 27,
          "clipType": "video",
          "transform": {
            "x": 0,
            "y": 0,
            "width": 1920,
            "height": 1080,
            "rotation": 0,
            "opacity": 1
          }
        },
        {
          "name": "clip5",
          "source": "source2",
          "timelineTrackStart": 19,
          "duration": 5,
          "sourceStartOffset": 0,
          "clipType": "video",
          "transform": {
            "x": 50,
            "y": 50,
            "width": 400,
            "height": 300,
            "rotation": 0,
            "opacity": 1
          }
        },
        {
          "name": "clip6",
          "source": "source4",
          "timelineTrackStart": 23,
          "duration": 5,
          "sourceStartOffset": 15,
          "clipType": "video",
          "transform": {
            "x": 0,
            "y": 0,
            "width": 1920,
            "height": 1080,
            "rotation": 0,
            "opacity": 1
          }
        },
        {
          "name": "clip7",
          "source": "source3",
          "timelineTrackStart": 28,
          "duration": 5,
          "sourceStartOffset": 0,
          "clipType": "video",
          "transform": {
            "x": 0,
            "y": 0,
            "width": 1920,
            "height": 1080,
            "rotation": 0,
            "opacity": 1
          }
        },
        {
          "name": "clip8",
          "source": "source1",
          "timelineTrackStart": 33,
          "duration": 5,
          "sourceStartOffset": 0,
          "clipType": "video",
          "transform": {
            "x": 0,
            "y": 0,
            "width": 1920,
            "height": 1080,
            "rotation": 0,
            "opacity": 1
          }
        }
      ]
    },
    "track_with_watermark": {
      "type": "video",
      "clips": [
        {
          "name": "watermark_clip",
          "source": "watermark",
          "timelineTrackStart": 0,
          "duration": 30,
          "sourceStartOffset": 0,
          "clipType": "image",
          "transform": {
            "x": 1610,
            "y": 10,
            "width": 300,
            "height": 150,
            "rotation": 0,
            "opacity": 1
          }
        }
      ]
    },
    "track2": {
      "type": "audio",
      "clips": [
        {
          "name": "audio_clip1",
          "source": "audio1",
          "timelineTrackStart": 5,
          "duration": 10,
          "sourceStartOffset": 0,
          "clipType": "audio",
          "volume": 1
        },
        {
          "name": "audio_clip2",
          "source": "audio2",
          "timelineTrackStart": 20,
          "duration": 15,
          "sourceStartOffset": 0,
          "clipType": "audio",
          "volume": 1
        }
      ]
    }
  },
  "transitions": [
    {
      "type": "smoothup",
      "duration": 0.5,
      "from": null,
      "to": "clip1"
    },
    {
      "type": "smoothdown",
      "duration": 0.5,
      "from": "clip1",
      "to": null
    },
    {
      "type": "fade",
      "duration": 0.5,
      "from": null,
      "to": "clip2"
    },
    {
      "type": "circlecrop",
      "duration": 0.5,
      "from": "clip2",
      "to": null
    },
    {
      "type": "squeezev",
      "duration": 0.5,
      "from": "clip3",
      "to": null
    },
    {
      "type": "squeezeh",
      "duration": 0.5,
      "from": "watermark_clip",
      "to": null
    },
    {
      "type": "fade",
      "duration": 1,
      "from": "clip4",
      "to": "clip5"
    },
    {
      "type": "smoothdown",
      "duration": 1,
      "from": "clip5",
      "to": "clip6"
    },
    {
      "type": "smoothdown",
      "duration": 0.5,
      "from": "clip8",
      "to": null
    }
  ],
  "output": {
    "tempDir": "./tmp",
    "file": "output.mp4",
    "videoCodec": "libx264",
    "audioCodec": "aac",
    "width": 1920,
    "height": 1080,
    "audioBitrate": "320k",
    "preset": "veryfast",
    "crf": 23,
    "framerate": 30,
    "flags": [
      "-pix_fmt",
      "yuv420p"
    ],
    "startPosition": 0,
    "endPosition": 38,
    "scaleRatio": 0.2
  }
}

will be translated into command like this:

#!/bin/bash
mkdir -p ./tmp
ffmpeg -y -i samples/bee1920.mp4 -ss 10 -t 2 -r 30 ./tmp/clip1.mp4
ffmpeg -y -i samples/book1920.mp4 -ss 5 -t 1 -r 30 ./tmp/clip2.mp4
ffmpeg -y -i samples/cows1920.mp4 -ss 3 -t 5 -r 30 ./tmp/clip3.mp4
ffmpeg -y -i samples/bee1920.mp4 -ss 27 -t 5 -r 30 ./tmp/clip4.mp4
ffmpeg -y -i samples/book1920.mp4 -ss 0 -t 5 -r 30 ./tmp/clip5.mp4
ffmpeg -y -i samples/flowers1920.mp4 -ss 15 -t 5 -r 30 ./tmp/clip6.mp4
ffmpeg -y -i samples/cows1920.mp4 -ss 0 -t 5 -r 30 ./tmp/clip7.mp4
ffmpeg -y -i samples/bee1920.mp4 -ss 0 -t 5 -r 30 ./tmp/clip8.mp4
ffmpeg -y \
-i ./tmp/clip1.mp4 \
-i ./tmp/clip2.mp4 \
-i ./tmp/clip3.mp4 \
-i ./tmp/clip4.mp4 \
-i ./tmp/clip5.mp4 \
-i ./tmp/clip6.mp4 \
-i ./tmp/clip7.mp4 \
-i ./tmp/clip8.mp4 \
-i samples/ever.mp3 \
-i samples/weekend.mp3 \
-i samples/flower.png \
-filter_complex "color=c=black:s=384x216:d=38[base];
color=c=black@0.0:s=384x216:d=3[gap_xbPT0R2D];
color=black@0.0:s=384x216:d=2[cMu1AeAv_base];
[0:v]scale=384:216,format=rgba,colorchannelmixer=aa=1[Tqb8V30z_clip];
[cMu1AeAv_base][Tqb8V30z_clip]overlay=0:0:format=auto,rotate=0,fps=30[clip1];
color=black@0.0:s=384x216:d=1[nwjCLeBf_base];
[1:v]scale=384:216,format=rgba,colorchannelmixer=aa=1[Jt2Ow3z7_clip];
[nwjCLeBf_base][Jt2Ow3z7_clip]overlay=0:0:format=auto,rotate=0,fps=30[clip2];
color=c=black@0.0:s=384x216:d=4[gap_wGJMg2Xy];
color=black@0.0:s=384x216:d=5[nbl0GdNN_base];
[2:v]scale=192:108,format=rgba,colorchannelmixer=aa=0.5[fuMgQH1R_clip];
[nbl0GdNN_base][fuMgQH1R_clip]overlay=96:54:format=auto,rotate=45,fps=30[clip3];
color=black@0.0:s=384x216:d=5[KWL95Ced_base];
[3:v]scale=384:216,format=rgba,colorchannelmixer=aa=1[tiuMabCa_clip];
[KWL95Ced_base][tiuMabCa_clip]overlay=0:0:format=auto,rotate=0,fps=30[clip4];
color=black@0.0:s=384x216:d=5[DYDR0Q6x_base];
[4:v]scale=80:60,format=rgba,colorchannelmixer=aa=1[52NAZxII_clip];
[DYDR0Q6x_base][52NAZxII_clip]overlay=10:10:format=auto,rotate=0,fps=30[clip5];
color=black@0.0:s=384x216:d=5[nG4pXmLO_base];
[5:v]scale=384:216,format=rgba,colorchannelmixer=aa=1[CgOJcTIJ_clip];
[nG4pXmLO_base][CgOJcTIJ_clip]overlay=0:0:format=auto,rotate=0,fps=30[clip6];
color=black@0.0:s=384x216:d=5[occJwxJK_base];
[6:v]scale=384:216,format=rgba,colorchannelmixer=aa=1[varB8t9b_clip];
[occJwxJK_base][varB8t9b_clip]overlay=0:0:format=auto,rotate=0,fps=30[clip7];
color=black@0.0:s=384x216:d=5[3q2VQ9Fn_base];
[7:v]scale=384:216,format=rgba,colorchannelmixer=aa=1[TnMfX5QP_clip];
[3q2VQ9Fn_base][TnMfX5QP_clip]overlay=0:0:format=auto,rotate=0,fps=30[clip8];
color=c=black@0.0:s=384x216:d=0.5[void_clip1];
[void_clip1]fps=30[fps_void_clip1_cpX1K4oW];
[clip1]fps=30[fps_clip1_9yaTMQSH];
[fps_void_clip1_cpX1K4oW][fps_clip1_9yaTMQSH]xfade=transition=smoothup:duration=0.43333333333333335:offset=0,fps=30[start_xfade_wvuFc7bn];
color=c=black@0.0:s=384x216:d=0.5[void_start_xfade_wvuFc7bn];
[start_xfade_wvuFc7bn]fps=30[fps_start_xfade_wvuFc7bn_XxZrJa0B];
[void_start_xfade_wvuFc7bn]fps=30[fps_void_start_xfade_wvuFc7bn_hwY2KZxJ];
[fps_start_xfade_wvuFc7bn_XxZrJa0B][fps_void_start_xfade_wvuFc7bn_hwY2KZxJ]xfade=transition=smoothdown:duration=0.43333333333333335:offset=1.5,fps=30[end_xfade_6MnYQ2ds];
color=c=black@0.0:s=384x216:d=0.5[void_clip2];
[void_clip2]fps=30[fps_void_clip2_vSBFpXYV];
[clip2]fps=30[fps_clip2_j3pJwJ6G];
[fps_void_clip2_vSBFpXYV][fps_clip2_j3pJwJ6G]xfade=transition=fade:duration=0.43333333333333335:offset=0,fps=30[start_xfade_gCAkUPK2];
color=c=black@0.0:s=384x216:d=0.5[void_start_xfade_gCAkUPK2];
[start_xfade_gCAkUPK2]fps=30[fps_start_xfade_gCAkUPK2_ZnLBlAtD];
[void_start_xfade_gCAkUPK2]fps=30[fps_void_start_xfade_gCAkUPK2_mLqar0Ah];
[fps_start_xfade_gCAkUPK2_ZnLBlAtD][fps_void_start_xfade_gCAkUPK2_mLqar0Ah]xfade=transition=circlecrop:duration=0.43333333333333335:offset=0.5,fps=30[end_xfade_aKd3UWQt];
color=c=black@0.0:s=384x216:d=0.5[void_clip3];
[clip3]fps=30[fps_clip3_3Ga4ugVG];
[void_clip3]fps=30[fps_void_clip3_5aVt3xnR];
[fps_clip3_3Ga4ugVG][fps_void_clip3_5aVt3xnR]xfade=transition=squeezev:duration=0.43333333333333335:offset=4.5,fps=30[end_xfade_s7Ol6uli];
color=c=black@0.0:s=384x216:d=0.5[void_clip8];
[clip8]fps=30[fps_clip8_4ZkGxZrd];
[void_clip8]fps=30[fps_void_clip8_ylXk9DHa];
[fps_clip8_4ZkGxZrd][fps_void_clip8_ylXk9DHa]xfade=transition=smoothdown:duration=0.43333333333333335:offset=4.5,fps=30[end_xfade_xAKXZo2d];
[gap_xbPT0R2D][end_xfade_6MnYQ2ds]concat=n=2:v=1:a=0,fps=30[between_concat_xlCW8OEt];
[between_concat_xlCW8OEt][end_xfade_aKd3UWQt]concat=n=2:v=1:a=0,fps=30[between_concat_FQfoDU4F];
[between_concat_FQfoDU4F][gap_wGJMg2Xy]concat=n=2:v=1:a=0,fps=30[between_concat_TVD5hCH9];
[between_concat_TVD5hCH9][end_xfade_s7Ol6uli]concat=n=2:v=1:a=0,fps=30[between_concat_xTjAkdon];
[between_concat_xTjAkdon][clip4]concat=n=2:v=1:a=0,fps=30[between_concat_m0OYCgp8];
[between_concat_m0OYCgp8]fps=30[fps_between_concat_m0OYCgp8_noaEdyvP];
[clip5]fps=30[fps_clip5_kQ745of1];
[fps_between_concat_m0OYCgp8_noaEdyvP][fps_clip5_kQ745of1]xfade=transition=fade:duration=1:offset=19,fps=30[between_xfade_HVZF1EvG];
[between_xfade_HVZF1EvG]fps=30[fps_between_xfade_HVZF1EvG_YWChbdii];
[clip6]fps=30[fps_clip6_6MbjfU2H];
[fps_between_xfade_HVZF1EvG_YWChbdii][fps_clip6_6MbjfU2H]xfade=transition=smoothdown:duration=1:offset=23,fps=30[between_xfade_3RlWNvho];
[between_xfade_3RlWNvho][clip7]concat=n=2:v=1:a=0,fps=30[between_concat_OxLtEhr7];
[between_concat_OxLtEhr7][end_xfade_xAKXZo2d]concat=n=2:v=1:a=0,fps=30[track_with_some_videos];
color=black@0.0:s=384x216:d=30[CYKVVqgc_base];
[10:v]loop=loop=900:size=900,setpts=PTS-STARTPTS,fps=30,scale=60:30,format=rgba,colorchannelmixer=aa=1[VvcI98fO_clip];
[CYKVVqgc_base][VvcI98fO_clip]overlay=322:2:format=auto,rotate=0,fps=30[watermark_clip];
color=c=black@0.0:s=384x216:d=8[gap_eOcpsLfb];
color=c=black@0.0:s=384x216:d=0.5[void_watermark_clip];
[watermark_clip]fps=30[fps_watermark_clip_fRSzmFrO];
[void_watermark_clip]fps=30[fps_void_watermark_clip_fhdBGNa7];
[fps_watermark_clip_fRSzmFrO][fps_void_watermark_clip_fhdBGNa7]xfade=transition=squeezeh:duration=0.43333333333333335:offset=29.5,fps=30[end_xfade_imi5OETb];
[end_xfade_imi5OETb][gap_eOcpsLfb]concat=n=2:v=1:a=0,fps=30[track_with_watermark];
anullsrc=channel_layout=stereo:sample_rate=44100:d=5[gap_9ROKhKdt];
[8:a]atrim=0:10,asetpts=PTS-STARTPTS,volume=1[audio_clip1];
anullsrc=channel_layout=stereo:sample_rate=44100:d=5[gap_fV2D5e8A];
[9:a]atrim=0:15,asetpts=PTS-STARTPTS,volume=1[audio_clip2];
anullsrc=channel_layout=stereo:sample_rate=44100:d=3[gap_4fwsUHt5];
[gap_9ROKhKdt][audio_clip1][gap_fV2D5e8A][audio_clip2][gap_4fwsUHt5]concat=n=5:v=0:a=1[track2];
[base][track_with_some_videos]overlay=0:0[gE0LAoGU_combined_track];
[gE0LAoGU_combined_track][track_with_watermark]overlay=0:0[video_output];
[track2]volume=1[audio_output];" \
-map '[video_output]' -map '[audio_output]' -c:v libx264 -c:a aac -b:a 320k -r 30 -s 384x216 -ss 0 -t 38 -crf 23 -preset veryfast -pix_fmt yuv420p output.mp4

Video, audio and image test samples

All samples are from Pixabay. All samples are licensed under Pixabay License.

License

MIT

3.11.96

10 months ago

3.11.95

10 months ago

3.11.94

10 months ago

2.11.94

10 months ago

2.11.93

10 months ago

2.11.92

10 months ago

2.11.91

11 months ago

2.11.90

11 months ago

2.11.89

11 months ago

2.11.88

11 months ago

2.10.88

11 months ago

2.9.88

11 months ago

2.9.87

11 months ago

2.9.86

11 months ago

2.9.85

11 months ago

2.8.85

11 months ago

2.8.84

11 months ago

2.8.83

11 months ago

2.8.82

11 months ago

2.8.81

11 months ago

2.8.80

11 months ago

2.8.79

11 months ago

2.8.78

11 months ago

2.8.77

11 months ago

2.8.76

11 months ago

2.8.75

11 months ago

2.7.75

11 months ago

2.7.74

11 months ago

2.7.73

11 months ago

2.7.72

11 months ago

2.7.71

11 months ago

2.7.70

11 months ago

2.7.69

11 months ago

2.7.68

11 months ago

2.7.67

11 months ago

2.6.67

11 months ago

2.5.67

12 months ago

2.5.66

12 months ago

2.5.65

12 months ago

2.5.64

12 months ago

2.5.63

12 months ago

2.5.62

12 months ago

2.5.61

12 months ago

2.5.60

12 months ago

2.5.59

12 months ago

2.5.58

12 months ago

2.5.57

12 months ago

2.5.56

12 months ago

2.5.55

12 months ago

2.5.54

12 months ago

2.5.53

12 months ago

2.5.52

12 months ago

2.5.51

12 months ago

2.5.50

12 months ago

2.5.49

12 months ago

2.5.48

12 months ago

2.5.47

1 year ago

2.5.46

1 year ago

2.5.45

1 year ago

2.5.44

1 year ago

2.4.44

1 year ago

2.4.43

1 year ago

2.4.42

1 year ago

2.4.41

1 year ago

2.4.40

1 year ago

2.4.39

1 year ago

2.4.38

1 year ago

2.4.37

1 year ago

2.4.36

1 year ago

2.4.35

1 year ago

2.4.34

1 year ago

2.3.34

1 year ago

2.3.33

1 year ago

2.3.32

1 year ago

2.3.31

1 year ago

2.3.30

1 year ago

2.3.29

1 year ago

2.3.28

1 year ago

2.3.27

1 year ago

2.2.27

1 year ago

2.2.26

1 year ago

2.2.25

1 year ago

2.1.25

1 year ago

1.1.25

1 year ago

1.1.24

1 year ago

1.1.23

1 year ago

1.1.22

1 year ago

1.1.21

1 year ago

1.1.20

1 year ago

1.1.19

1 year ago

1.1.18

1 year ago

1.1.17

1 year ago

1.0.17

1 year ago

1.0.16

1 year ago

1.0.15

1 year ago

1.0.14

1 year ago

1.0.13

1 year ago

1.0.12

1 year ago

1.0.11

1 year ago

1.0.10

1 year ago

1.0.9

1 year ago

1.0.8

1 year ago

1.0.7

1 year ago

1.0.6

1 year ago

1.0.5

1 year ago

1.0.4

1 year ago

1.0.3

1 year ago

1.0.2

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago