Security News
Fluent Assertions Faces Backlash After Abandoning Open Source Licensing
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
ffmpeg.js-hperrin
Advanced tools
Port of FFmpeg with Emscripten (With modifications by hperrin.)
This library provides FFmpeg builds ported to JavaScript using Emscripten project. Builds are optimized for in-browser use: minimal size for faster loading, asm.js, performance tunings, etc. Though they work in Node as well.
Currently available builds (additional builds may be added in future):
ffmpeg-webm.js
- WebM encoding (VP8 & Opus encoders, popular decoders).ffmpeg-worker-webm.js
- Web Worker version of ffmpeg-webm.js
.ffmpeg-mp4.js
- MP4 encoding (H.264 & AAC & MP3 encoders, popular decoders).ffmpeg-worker-mp4.js
- Web Worker version of ffmpeg-mp4.js
.Note: only NPM releases contain abovementioned files.
ffmpeg.js uses the following version pattern: major.minor.9ddd
, where:
Example: 2.7.9005
See documentation on Module object for the list of options that you can pass.
ffmpeg.js provides common module API, ffmpeg-webm.js
is the default module. Add its name after the slash if you need another build, e.g. require("ffmpeg.js/ffmpeg-mp4.js")
.
var ffmpeg = require("ffmpeg.js");
var stdout = "";
var stderr = "";
// Print FFmpeg's version.
ffmpeg({
arguments: ["-version"],
print: function(data) { stdout += data + "\n"; },
printErr: function(data) { stderr += data + "\n"; },
onExit: function(code) {
console.log("Process exited with code " + code);
console.log(stdout);
},
});
Use e.g. browserify in case of Browser.
ffmpeg.js also provides wrapper for main function with Web Worker interface to offload the work to a different process. Worker sends the following messages:
{type: "ready"}
- Worker loaded and ready to accept commands.{type: "run"}
- Worker started the job.{type: "stdout", data: "<line>"}
- FFmpeg printed to stdout.{type: "stderr", data: "<line>"}
- FFmpeg printed to stderr.{type: "exit", data: "<code>"}
- FFmpeg exited.{type: "done", data: "<result>"}
- Job finished with some result.{type: "error", data: "<error description>"}
- Error occurred.You can send the following messages to the worker:
{type: "run", ...opts}
- Start new job with provided options.var stdout = "";
var stderr = "";
var worker = new Worker("ffmpeg-worker-webm.js");
worker.onmessage = function(e) {
var msg = e.data;
switch (msg.type) {
case "ready":
worker.postMessage({type: "run", arguments: ["-version"]});
break;
case "stdout":
stdout += msg.data + "\n";
break;
case "stderr":
stderr += msg.data + "\n";
break;
case "exit":
console.log("Process exited with code " + msg.data);
console.log(stdout);
worker.terminate();
break;
}
};
This works in Browser as is, use e.g. webworker-threads Web Worker implementation in Node.
Empscripten supports several types of file systems. ffmpeg.js uses MEMFS to store the input/output files in FFmpeg's working directory. You need to pass Array of Object to MEMFS
option with the following keys:
ffmpeg.js resulting object has MEMFS
option with the same structure and contains files which weren't passed to the input, i.e. new files created by FFmpeg.
var ffmpeg = require("ffmpeg.js");
var fs = require("fs");
var testData = new Uint8Array(fs.readFileSync("test.webm"));
// Encode test video to VP8.
var result = ffmpeg({
MEMFS: [{name: "test.webm", data: testData}],
arguments: ["-i", "test.webm", "-c:v", "libvpx", "-an", "out.webm"],
// Ignore stdin read requests.
stdin: function() {},
});
// Write out.webm to disk.
var out = result.MEMFS[0];
fs.writeFileSync(out.name, Buffer(out.data));
You can also mount other FS by passing Array of Object to mounts
option with the following keys:
/tmp
, /home
, /dev
, /work
. Mount directory will be created automatically before mount.See documentation of FS.mount for more details.
var ffmpeg = require("ffmpeg.js");
ffmpeg({
// Mount /data inside application to the current directory.
mounts: [{type: "NODEFS", opts: {root: "."}, mountpoint: "/data"}],
arguments: ["-i", "/data/test.webm", "-c:v", "libvpx", "-an", "/data/out.webm"],
stdin: function() {},
});
// out.webm was written to the current directory.
Tips, use a docker container (basic ubuntu is good)
apt-get update
apt-get -y install wget python git automake libtool build-essential cmake libglib2.0-dev closure-compiler
cd /root # or /home/whatever
wget https://s3.amazonaws.com/mozilla-games/emscripten/releases/emsdk-portable.tar.gz
tar xzvf emsdk-portable.tar.gz
cd emsdk-portable
./emsdk update
./emsdk install latest
./emsdk activate latest
source ./emsdk_env.sh
cd /root # or /home/whatever
git clone https://github.com/Kagami/ffmpeg.js.git
cd ffmpeg.js
git submodule init
git submodule update --recursive
make all
Thanks to videoconverter.js for inspiration. And of course to all great projects which made this library possible: FFmpeg, Emscripten, asm.js, node.js and many others.
Own library code licensed under LGPL 2.1 or later.
This build uses LGPL version of FFmpeg and thus available under LGPL 2.1 or later. See here for more details and FFmpeg's license information.
Included libraries:
See LICENSE.WEBM for the full text of software licenses used in this build.
This build uses GPL version of FFmpeg and thus available under GPL 2.0. It also includes patent encumbered H.264, AAC and MP3 encoders. Make sure to contact lawyer before using it in your country.
Included libraries:
See LICENSE.MP4 for the full text of software licenses used in this build.
FAQs
Port of FFmpeg with Emscripten (With modifications by hperrin.)
The npm package ffmpeg.js-hperrin receives a total of 3 weekly downloads. As such, ffmpeg.js-hperrin popularity was classified as not popular.
We found that ffmpeg.js-hperrin demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
Research
Security News
Socket researchers uncover the risks of a malicious Python package targeting Discord developers.
Security News
The UK is proposing a bold ban on ransomware payments by public entities to disrupt cybercrime, protect critical services, and lead global cybersecurity efforts.