yffmpeg
v3.0.1
Published
Simple ffmpeg API for nodejs
Downloads
3
Readme
Simple ffmpeg API for nodejs
- API Reference: https://y00066.github.io/yffmpeg
- Github Repo: https://github.com/y00066/yffmpeg
- NPM: https://www.npmjs.com/package/yffmpeg
Install
# yarn
yarn add yffmpeg@latest
# npm
npm install yffmpeg@latest
Usage
Transcoding Audio:
const { FFmpeg, Options } = require("yffmpeg")
new FFmpeg()
.setInput("./audio.mp3")
.setOutputOptions(
new Options()
.setAudioCodec("flac")
.setAudioBitrate("1411k")
.setAudioSamplingRate(44100)
.setAudioChannels(2)
.setCodecOptions("-compression_level", 11)
.setAudioFilter(
"aecho=0.8:0.88:1000:0.3",
"volume=0.2dB"
)
.ok()
)
.setOutput("./audio.flac")
.run()
Input/Output Stream:
Suport multiple input/output stream.
const { FFmpeg, Options } = require("yffmpeg")
const fs = require("fs")
new FFmpeg()
.setInput(fs.createReadStream("input-audio.m4a"))
.setInput(fs.createReadStream("input-video.mp4"))
.setOutputOptions(
new Options()
.setFormat("mp4")
.setAudioCodec("copy")
.setVideoCodec("copy")
.ok()
)
.setOutput(fs.createWriteStream("video.mp4"))
.run()
Multiple Input/Output:
const { FFmpeg } = require("yffmpeg")
new FFmpeg()
.setInputOptions()
.setInput()
.setInputOptions()
.setInput()
// and so on
.setOutputOptions()
.setOutput()
.setOutputOptions()
.setOutput()
// and so on
.run()
Listening to the event:
const { FFmpeg } = require("yffmpeg")
const ffmpeg = new FFmpeg().setInput().setOutput().run()
ffmpeg.on("error", (error) => console.log(error))
ffmpeg.on("close", (code) => console.log("ffmpeg exited with code: " + code))
ffmpeg.stderr.on("data", (data) => console.log("stderr: " + data))
ffmpeg.stdout.on("data", (data) => console.log("stdout: " + data))
Manually Set ffmpeg Binary Location:
const { FFmpeg } = require("yffmpeg")
new FFmpeg("/usr/bin/ffmpeg")