A basic wrapper around FFmpeg for node.js.
$ npm i ffmkek
- FFmpeg (see FFmpeg instalation)
Options and inputs/outputs have to be added in the same order you would add them in your command line.
const FFmkek = require('ffmkek')
// ffmpeg -i some/video.mp4 -i some/audio.mp3 -shortest -vf "scale=300:-1, crop=150:150:0:0" out.mp4 -y
new FFmkek()
.addInput('some/video.mp4')
.addInput('some/audio.mp3')
.addOption('-shortest')
.addOption('-vf', 'scale=300:-1', 'crop=150:150:0:0')
.write('out.mp4')
// ffmpeg -i pipe:0 -c copy out.mp4 -y
new FFmkek()
.addInput(someReadableStream)
.addOption('-c', 'copy')
.write('out.mp4')
// ffmpeg -i pipe:0 -f h264 pipe:1 -y
new FFmkek()
.addInput(someReadableStream)
.addOption('-f', 'h264')
.write(someWriteableStream)
Adds a new input to the command.
Aliases: in
, input
Params:
- input:
string|Stream
The path to the input file or a readable stream.
Returns: FFmkek
The current command.
Adds a new output to the command.
Aliases: out
, output
, addOutput
Params:
- output:
string|Stream
The path to the ouput file or a writeable stream.
Returns: FFmkek
The current command.
Calls addOption
on the current Part
. See Part.prototype.addOption()
.
Aliases: opt
, option
Params:
- name:
string
- valueN:
string
Returns: FFmkek
The current command.
Controls whether to add the -y
option to the command or not. By default is set to true.
Params:
- flag:
boolean
Returns: FFmkek
The current command.
Formats the command arguments and returns them as an array.
Aliases: args
, arguments
Returns: Array<string>
The current command arguments.
Executes the current command. If no output is set, creates a PassThrough
stream.
Returns: Promise<string|Stream>
The path of the file or the Stream that was written to.
Shorthand for calling setOutput()
and run()
.
Aliases: save
Params:
- output:
string|Stream
The path to the ouput file or a writeable stream.
Returns: Promise<string|Stream>
The path of the file or the Stream that was written to.
Changes the path to ffmpeg. If not called simply ffmpeg
is used.
Params:
- path:
string
Returns: FFmkek
The current command.
A FFmkek instance usually contains multiple Part
s. Parts are abstractisations of an input or an output.
Each part has:
- name: The file path or pipe number. (
some/folder/input.mp4
orpipe:0
) - type:
input
oroutput
- options: The options that belong to this
Part
Upon calling FFmkek.prototype.addInput()
or FFmkek.prototype.setOutput()
, the current part is "closed", along with the options added prior to it, and pushed to the parts
array, which is a property of FFmkek instances.
If you happen to need to modify a Part
after calling those methods, you can just look them up in the parts
array and modify them. Here's an example:
const command = new FFmkek()
.addInput('some/file.mp4')
.setOutput('other/file.mp4')
// Currently our command yields:
// ffmpeg -i some/file.mp4 other/file.mp4
command.parts.find(part => part.name === 'some/file.mp4').addOption('-r', 1)
// Now our command looks like:
// ffmpeg -r 1 -i some/file.mp4 other/file.mp4
Here's a real world usage for this.
Sets the name of the part.
Params:
- name:
string
Returns: Part
self.
Sets the type of the part. Can only be input
or output
. You can use the Part.INPUT
and Part.OUTPUT
constants instead.
Params:
- type:
string
Returns: Part
self.
Adds an option to the Part
. Values are concatenated automatically.
Upon adding an option with the same name later on, the values are again concatenated, the option is not overwriten.
Params:
- name:
string
The name of the option. Does NOT prepend a hyphen automatically, you must add it yourself. - valueN:
string
The set of values to set the option to.
Returns: Part
self.
Pushes all its options and name to an array.
new Part()
.setName('some/file.mp4')
.addOption('-c', 'copy')
.addOption('-vf', 'scale=300:-2', 'crop=150:150:0:0')
.apply([]) // => ['-c', 'copy', '-vf', 'scale=300:-2, crop=150:150:0:0', '-i', 'some/file.mp4']
Params:
- args:
Array
Returns: Array
The new array.
Removes self from parent FFmkek command.
Returns: Part
self.
If there are things you don't agree with, or would like to have implemented, feel free to submit a pull request or file an issue.