Browse Source

Expose ffmpeg child-process

pull/61/head
Johnathan Amit-Kanarek 6 years ago
parent
commit
19817ddf1f
  1. 5
      README.md
  2. 9
      index.js

5
README.md

@ -132,6 +132,9 @@ Edit specs are JavaScript / JSON objects describing the whole edit operation wit
enableFfmpegLog: false, enableFfmpegLog: false,
verbose: false, verbose: false,
fast: false, fast: false,
onStart: (cmd) => console.log('Command:', cmd),
onProcessStart: (subprocess) => subprocess.stdout.pipe(process.stdout),
} }
``` ```
@ -156,6 +159,8 @@ Edit specs are JavaScript / JSON objects describing the whole edit operation wit
| `clips[].transition` | | Specify transition at the **end** of this clip. See `defaults.transition` | `defaults.transition` | | | `clips[].transition` | | Specify transition at the **end** of this clip. See `defaults.transition` | `defaults.transition` | |
| `clips[].layers[]` | | List of layers within the current clip that will be overlaid in their natural order (last layer on top) | | | | `clips[].layers[]` | | List of layers within the current clip that will be overlaid in their natural order (last layer on top) | | |
| `clips[].layers[].type` | | Layer type, see below | | | | `clips[].layers[].type` | | Layer type, see below | | |
| `onStart` | | Callback function, called before ffmpeg process start with command line as string argument | | |
| `onProcessStart` | | Callback function, called after ffmpeg process start with subprocess argument | | |
### Transition types ### Transition types

9
index.js

@ -39,8 +39,15 @@ module.exports = async (config = {}) => {
ffmpegPath = 'ffmpeg', ffmpegPath = 'ffmpeg',
ffprobePath = 'ffprobe', ffprobePath = 'ffprobe',
onStart,
onProcessStart,
} = config; } = config;
assert(!onStart || typeof onStart === 'function', 'Callback onStart expected to be a function');
assert(!onProcessStart || typeof onProcessStart === 'function', 'Callback onProcessStart expected to be a function');
const isGif = outPath.toLowerCase().endsWith('.gif'); const isGif = outPath.toLowerCase().endsWith('.gif');
const audioFilePath = isGif ? undefined : audioFilePathIn; const audioFilePath = isGif ? undefined : audioFilePathIn;
@ -314,6 +321,7 @@ module.exports = async (config = {}) => {
...outputArgs, ...outputArgs,
]; ];
if (verbose) console.log('ffmpeg', args.join(' ')); if (verbose) console.log('ffmpeg', args.join(' '));
if (onStart) onStart(`ffmpeg ${args.join(' ')}`);
return execa(ffmpegPath, args, { encoding: null, buffer: false, stdin: 'pipe', stdout: process.stdout, stderr: process.stderr }); return execa(ffmpegPath, args, { encoding: null, buffer: false, stdin: 'pipe', stdout: process.stdout, stderr: process.stderr });
} }
@ -323,6 +331,7 @@ module.exports = async (config = {}) => {
try { try {
outProcess = startFfmpegWriterProcess(); outProcess = startFfmpegWriterProcess();
if (onProcessStart) onProcessStart(outProcess);
let outProcessError; let outProcessError;
// If we don't catch it here, the whole process will crash and we cannot process the error // If we don't catch it here, the whole process will crash and we cannot process the error

Loading…
Cancel
Save