Skip to content

Commit

Permalink
Merge branch 'master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
mifi authored Oct 10, 2022
2 parents 68ec9f8 + d3d3a71 commit 306234b
Show file tree
Hide file tree
Showing 26 changed files with 1,774 additions and 2,229 deletions.
15 changes: 0 additions & 15 deletions .eslintrc

This file was deleted.

20 changes: 20 additions & 0 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
module.exports = {
extends: 'airbnb-base',
parserOptions: {
ecmaVersion: 2022,
},
env: {
node: true,
},
settings: {
'import/extensions': ['.js'],
},
rules: {
'max-len': 0,
'no-console': 0,
'object-curly-newline': 0,
'no-await-in-loop': 0,
'no-promise-executor-return': 0,
'import/extensions': ['error', 'ignorePackages'],
},
};
12 changes: 12 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/.github/workflows/test.yml
/.eslintrc.cjs
/test.js
/Dockerfile
/docker-compose.yml
/logo.png
/examples
/.cache
/yarn-error.log
editly-tmp-*/
*.mp4
*.gif
9 changes: 3 additions & 6 deletions BoxBlur.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,11 @@ OTHER DEALINGS IN THE SOFTWARE.


var mul_table = [ 1,57,41,21,203,34,97,73,227,91,149,62,105,45,39,137,241,107,3,173,39,71,65,238,219,101,187,87,81,151,141,133,249,117,221,209,197,187,177,169,5,153,73,139,133,127,243,233,223,107,103,99,191,23,177,171,165,159,77,149,9,139,135,131,253,245,119,231,224,109,211,103,25,195,189,23,45,175,171,83,81,79,155,151,147,9,141,137,67,131,129,251,123,30,235,115,113,221,217,53,13,51,50,49,193,189,185,91,179,175,43,169,83,163,5,79,155,19,75,147,145,143,35,69,17,67,33,65,255,251,247,243,239,59,29,229,113,111,219,27,213,105,207,51,201,199,49,193,191,47,93,183,181,179,11,87,43,85,167,165,163,161,159,157,155,77,19,75,37,73,145,143,141,35,138,137,135,67,33,131,129,255,63,250,247,61,121,239,237,117,29,229,227,225,111,55,109,216,213,211,209,207,205,203,201,199,197,195,193,48,190,47,93,185,183,181,179,178,176,175,173,171,85,21,167,165,41,163,161,5,79,157,78,154,153,19,75,149,74,147,73,144,143,71,141,140,139,137,17,135,134,133,66,131,65,129,1];



var shg_table = [0,9,10,10,14,12,14,14,16,15,16,15,16,15,15,17,18,17,12,18,16,17,17,19,19,18,19,18,18,19,19,19,20,19,20,20,20,20,20,20,15,20,19,20,20,20,21,21,21,20,20,20,21,18,21,21,21,21,20,21,17,21,21,21,22,22,21,22,22,21,22,21,19,22,22,19,20,22,22,21,21,21,22,22,22,18,22,22,21,22,22,23,22,20,23,22,22,23,23,21,19,21,21,21,23,23,23,22,23,23,21,23,22,23,18,22,23,20,22,23,23,23,21,22,20,22,21,22,24,24,24,24,24,22,21,24,23,23,24,21,24,23,24,22,24,24,22,24,24,22,23,24,24,24,20,23,22,23,24,24,24,24,24,24,24,23,21,23,22,23,24,24,24,22,24,24,24,23,22,24,24,25,23,25,25,23,24,25,25,24,22,25,25,25,24,23,24,25,25,25,25,25,25,25,25,25,25,25,25,23,25,23,24,25,25,25,25,25,25,25,25,25,24,22,25,25,23,25,25,20,24,25,24,25,25,22,24,25,24,25,24,25,25,24,25,25,25,25,22,25,25,25,24,25,24,25,18];

function boxBlurImage( context, width, height, radius, blurAlphaChannel, iterations ){

export function boxBlurImage( context, width, height, radius, blurAlphaChannel, iterations ){
if ( isNaN(radius) || radius < 1 ) return;

if ( blurAlphaChannel )
Expand Down Expand Up @@ -319,5 +318,3 @@ function boxBlurCanvasRGB( context, top_x, top_y, width, height, radius, iterati
context.putImageData( imageData, top_x, top_y );

}

module.exports = { boxBlurImage };
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ See [examples](https://github.com/mifi/editly/tree/master/examples)
- [Node.js installed](https://nodejs.org/en/) (Use of the latest LTS version is recommended, [v12.16.2 or newer on MacOS](https://github.com/sindresorhus/meow/issues/144).)
- `ffmpeg` (and `ffprobe`) [installed](http://ffmpeg.org/) and available in `PATH`
- (Linux) may require some extra steps. See [headless-gl](https://github.com/stackgl/headless-gl#system-dependencies).
- **Editly is now ESM only**

## Installing

Expand Down Expand Up @@ -91,11 +92,10 @@ Without `--fast`, it will default to using the **width**, **height** and **frame
## JavaScript library

```js
const editly = require('editly');
import editly from 'editly';

// See editSpec documentation
await editly(editSpec)
.catch(console.error);
```

## Edit spec
Expand Down
15 changes: 7 additions & 8 deletions audio.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
const pMap = require('p-map');
const { join, basename, resolve } = require('path');
const execa = require('execa');
const flatMap = require('lodash/flatMap');
import pMap from 'p-map';
import { join, basename, resolve } from 'path';
import { execa } from 'execa';
import flatMap from 'lodash-es/flatMap.js';

const { getFfmpegCommonArgs, getCutFromArgs } = require('./ffmpeg');
const { readFileStreams } = require('./util');
import { getFfmpegCommonArgs, getCutFromArgs } from './ffmpeg.js';
import { readFileStreams } from './util.js';

module.exports = ({ ffmpegPath, ffprobePath, enableFfmpegLog, verbose, tmpDir }) => {
export default ({ ffmpegPath, ffprobePath, enableFfmpegLog, verbose, tmpDir }) => {
async function createMixedAudioClips({ clips, keepSourceAudio }) {
return pMap(clips, async (clip, i) => {
const { duration, layers, transition } = clip;
Expand Down Expand Up @@ -198,7 +198,6 @@ module.exports = ({ ffmpegPath, ffprobePath, enableFfmpegLog, verbose, tmpDir })
return mixedAudioPath;
}


async function editAudio({ keepSourceAudio, clips, arbitraryAudio, clipsAudioVolume, audioNorm, outputVolume }) {
// We need clips to process audio, because we need to know duration
if (clips.length === 0) return undefined;
Expand Down
21 changes: 11 additions & 10 deletions cli.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
#!/usr/bin/env node
const meow = require('meow');
const fs = require('fs');
const FileType = require('file-type');
const pMap = require('p-map');
const JSON5 = require('json5');
const assert = require('assert');
import meow from 'meow';
import { readFileSync } from 'fs';
import { fileTypeFromFile } from 'file-type';
import pMap from 'p-map';
import JSON5 from 'json5';
import assert from 'assert';

const editly = require('.');
import Editly from './index.js';

// See also readme
const cli = meow(`
Expand Down Expand Up @@ -47,6 +47,7 @@ const cli = meow(`
$ 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
$ editly my-editly.json5 --out output.gif
`, {
importMeta: import.meta,
flags: {
verbose: { type: 'boolean', alias: 'v' },
keepSourceAudio: { type: 'boolean' },
Expand All @@ -72,7 +73,7 @@ const cli = meow(`
};

if (json) {
params = JSON5.parse(fs.readFileSync(json, 'utf-8'));
params = JSON5.parse(readFileSync(json, 'utf-8'));
} else {
const clipsIn = cli.input;
if (clipsIn.length < 1) cli.showHelp();
Expand All @@ -84,7 +85,7 @@ const cli = meow(`
match = clip.match(/^https?:\/\/.*\.(jpg|jpeg|png|webp|gif|svg)$/); // todo improve
if (match) return { type: 'image', path: clip };

const fileType = await FileType.fromFile(clip);
const fileType = await fileTypeFromFile(clip);
if (!fileType) {
console.error('Invalid file for clip', clip);
cli.showHelp();
Expand Down Expand Up @@ -136,7 +137,7 @@ const cli = meow(`

if (!params.outPath) params.outPath = './editly-out.mp4';

await editly(params);
await Editly(params);
})().catch((err) => {
console.error('Caught error', err);
process.exitCode = 1;
Expand Down
11 changes: 3 additions & 8 deletions colors.js
Original file line number Diff line number Diff line change
Expand Up @@ -171,14 +171,14 @@ const gradientColors = [
],
]; */

function getRandomColor(colors = allColors) {
export function getRandomColor(colors = allColors) {
const index = Math.floor(Math.random() * colors.length);
const remainingColors = [...colors];
remainingColors.splice(index, 1);
return { remainingColors, color: colors[index] || allColors[0] };
}

function getRandomColors(num) {
export function getRandomColors(num) {
let colors = allColors;
const out = [];
for (let i = 0; i < Math.min(num, allColors.length); i += 1) {
Expand All @@ -189,11 +189,6 @@ function getRandomColors(num) {
return out;
}

function getRandomGradient() {
export function getRandomGradient() {
return gradientColors[Math.floor(Math.random() * gradientColors.length)];
}

module.exports = {
getRandomColors,
getRandomGradient,
};
2 changes: 1 addition & 1 deletion examples/customCanvas.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const editly = require('..');
import editly from '..';

async function func({ canvas }) {
async function onRender(progress) {
Expand Down
2 changes: 1 addition & 1 deletion examples/customFabric.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const editly = require('..');
import editly from '..';

/* eslint-disable spaced-comment,no-param-reassign */

Expand Down
9 changes: 5 additions & 4 deletions examples/renderSingleFrame.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
const JSON5 = require('json5');
const fs = require('fs-extra');
import { parse } from 'json5';
import fsExtra from 'fs-extra';

const { renderSingleFrame } = require('..');
// eslint-disable-next-line import/named
import { renderSingleFrame } from '..';

(async () => {
await renderSingleFrame({
time: 0,
clips: JSON5.parse(await fs.readFile('./videos.json5', 'utf-8')).clips,
clips: parse(await fsExtra.readFile('./videos.json5', 'utf-8')).clips,
});
})().catch(console.error);
29 changes: 10 additions & 19 deletions ffmpeg.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
const fs = require('fs-extra');
const execa = require('execa');
const assert = require('assert');
const compareVersions = require('compare-versions');
import fsExtra from 'fs-extra';
import { execa } from 'execa';
import assert from 'assert';
import compareVersions from 'compare-versions';

export const getFfmpegCommonArgs = ({ enableFfmpegLog }) => (enableFfmpegLog ? [] : ['-hide_banner', '-loglevel', 'error']);

const getFfmpegCommonArgs = ({ enableFfmpegLog }) => (enableFfmpegLog ? [] : ['-hide_banner', '-loglevel', 'error']);
export const getCutFromArgs = ({ cutFrom }) => (cutFrom ? ['-ss', cutFrom] : []);

const getCutFromArgs = ({ cutFrom }) => (cutFrom ? ['-ss', cutFrom] : []);
export const getCutToArgs = ({ cutTo, cutFrom, speedFactor }) => (cutTo ? ['-t', (cutTo - cutFrom) * speedFactor] : []);

const getCutToArgs = ({ cutTo, cutFrom, speedFactor }) => (cutTo ? ['-t', (cutTo - cutFrom) * speedFactor] : []);

async function createConcatFile(segments, concatFilePath) {
export async function createConcatFile(segments, concatFilePath) {
// https://superuser.com/questions/787064/filename-quoting-in-ffmpeg-concat
await fs.writeFile(concatFilePath, segments.map((seg) => `file '${seg.replace(/'/g, "'\\''")}'`).join('\n'));
await fsExtra.writeFile(concatFilePath, segments.map((seg) => `file '${seg.replace(/'/g, "'\\''")}'`).join('\n'));
}

async function testFf(exePath, name) {
export async function testFf(exePath, name) {
const minRequiredVersion = '4.3.1';

try {
Expand All @@ -30,11 +29,3 @@ async function testFf(exePath, name) {
console.error(`WARNING: ${name}:`, err.message);
}
}

module.exports = {
getFfmpegCommonArgs,
getCutFromArgs,
getCutToArgs,
createConcatFile,
testFf,
};
26 changes: 15 additions & 11 deletions glTransitions.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
const GL = require('gl');
const ndarray = require('ndarray');
const createBuffer = require('gl-buffer');
const transitions = require('gl-transitions');
const createTransition = require('gl-transition').default;
const createTexture = require('gl-texture2d');

module.exports = ({ width, height, channels }) => {
import GL from 'gl';
import ndarray from 'ndarray';
import createBuffer from 'gl-buffer';
import glTransitions from 'gl-transitions';
import glTransition from 'gl-transition';
import createTexture from 'gl-texture2d';

const { default: createTransition } = glTransition;

export default ({ width, height, channels }) => {
const gl = GL(width, height);

if (!gl) {
Expand All @@ -18,17 +20,19 @@ module.exports = ({ width, height, channels }) => {
return ndarray(buf, [width, height, channels], [channels, width * channels, 1]);
}

const buffer = createBuffer(gl,
const buffer = createBuffer(
gl,
[-1, -1, -1, 4, 4, -1],
gl.ARRAY_BUFFER,
gl.STATIC_DRAW);
gl.STATIC_DRAW,
);

let transition;

try {
const resizeMode = 'stretch';

const transitionSource = transitions.find((t) => t.name.toLowerCase() === transitionName.toLowerCase());
const transitionSource = glTransitions.find((t) => t.name.toLowerCase() === transitionName.toLowerCase());

transition = createTransition(gl, transitionSource, { resizeMode });

Expand Down
2 changes: 1 addition & 1 deletion index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1125,7 +1125,7 @@ declare namespace Editly {
/**
* Output path (`.mp4` or `.mkv`, can also be a `.gif`).
*/
outPath: string | undefined;
outPath: string;

/**
* Timestamp to render.
Expand Down
Loading

0 comments on commit 306234b

Please sign in to comment.