Skip to content

Commit 91e06ba

Browse files
committed
Allow custom output args #27 #36
1 parent 9edb1e4 commit 91e06ba

File tree

3 files changed

+25
-8
lines changed

3 files changed

+25
-8
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,7 @@ Edit specs are JavaScript / JSON objects describing the whole edit operation wit
176176
| `width` | `--width` | Width which all media will be converted to | `640` | |
177177
| `height` | `--height` | Height which all media will be converted to | auto based on `width` and aspect ratio of **first video** | |
178178
| `fps` | `--fps` | FPS which all videos will be converted to | First video FPS or `25` | |
179+
| `customOutputArgs` | | Specify custom output codec/format arguments for ffmpeg (See [example](https://github.com/mifi/editly/blob/master/examples/customOutputArgs.json5)) | auto (h264) | |
179180
| `allowRemoteRequests` | `--allow-remote-requests` | Allow remote URLs as paths | `false` | |
180181
| `fast` | `--fast`, `-f` | Fast mode (low resolution and FPS, useful for getting a quick preview ⏩) | `false` | |
181182
| `defaults.layer.fontPath` | `--font-path` | Set default font to a .ttf | System font | |

examples/customOutputArgs.json5

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
outPath: './customOutputArgs.webp',
3+
clips: [
4+
{ duration: 2, layers: [{ type: 'title-background', text: 'Custom output args' }] },
5+
],
6+
customOutputArgs: ['-compression_level', '5', '-qscale', '60', '-vcodec', 'libwebp'],
7+
}

index.js

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ const Editly = async (config = {}) => {
4040
allowRemoteRequests,
4141
audioNorm,
4242
outputVolume,
43+
customOutputArgs,
4344

4445
ffmpegPath = 'ffmpeg',
4546
ffprobePath = 'ffprobe',
@@ -177,13 +178,16 @@ const Editly = async (config = {}) => {
177178
return runGlTransitionOnFrame({ fromFrame, toFrame, progress, transitionName, transitionParams });
178179
}
179180

180-
function startFfmpegWriterProcess() {
181+
function getOutputArgs() {
182+
if (customOutputArgs) {
183+
assert(Array.isArray(customOutputArgs), 'customOutputArgs must be an array of arguments');
184+
return customOutputArgs;
185+
}
186+
181187
// https://superuser.com/questions/556029/how-do-i-convert-a-video-to-gif-using-ffmpeg-with-reasonable-quality
182-
const outputArgs = isGif ? [
183-
'-vf',
184-
`format=rgb24,fps=${fps},scale=${width}:${height}:flags=lanczos,split[s0][s1];[s0]palettegen[p];[s1][p]paletteuse`,
188+
const videoOutputArgs = isGif ? [
189+
'-vf', `format=rgb24,fps=${fps},scale=${width}:${height}:flags=lanczos,split[s0][s1];[s0]palettegen[p];[s1][p]paletteuse`,
185190
'-loop', 0,
186-
'-y', outPath,
187191
] : [
188192
'-vf', 'format=yuv420p',
189193
'-vcodec', 'libx264',
@@ -192,9 +196,14 @@ const Editly = async (config = {}) => {
192196
'-crf', '18',
193197

194198
'-movflags', 'faststart',
195-
'-y', outPath,
196199
];
197200

201+
const audioOutputArgs = audioFilePath ? ['-acodec', 'aac', '-b:a', '128k'] : [];
202+
203+
return [...audioOutputArgs, ...videoOutputArgs];
204+
}
205+
206+
function startFfmpegWriterProcess() {
198207
const args = [
199208
...(enableFfmpegLog ? [] : ['-hide_banner', '-loglevel', 'error']),
200209

@@ -210,9 +219,9 @@ const Editly = async (config = {}) => {
210219
...(!isGif ? ['-map', '0:v:0'] : []),
211220
...(audioFilePath ? ['-map', '1:a:0'] : []),
212221

213-
...(audioFilePath ? ['-acodec', 'aac', '-b:a', '128k'] : []),
222+
...getOutputArgs(),
214223

215-
...outputArgs,
224+
'-y', outPath,
216225
];
217226
if (verbose) console.log('ffmpeg', args.join(' '));
218227
return execa(ffmpegPath, args, { encoding: null, buffer: false, stdin: 'pipe', stdout: process.stdout, stderr: process.stderr });

0 commit comments

Comments
 (0)