ffprobe.wasm
See original GitHub issueIs your feature request related to a problem? Please describe.
Implement ffprobe
wasm version.
Describe the solution you’d like
ffprobe
is the necessary companion of ffmpeg
, needed to analyze media file before processing .
Describe alternatives you’ve considered
In this simple case I’m using the command line ffprobe
via execFile
to probe the file
probe = function (fpath) {
var self = this;
return new Promise((resolve, reject) => {
var loglevel = self.logger.isDebug() ? 'debug' : 'warning';
const args = [
'-v', 'quiet',
'-loglevel', loglevel,
'-print_format', 'json',
'-show_format',
'-show_streams',
'-i', fpath
];
const opts = {
cwd: self._options.tempDir
};
const cb = (error, stdout) => {
if (error)
return reject(error);
try {
const outputObj = JSON.parse(stdout);
return resolve(outputObj);
} catch (ex) {
self.logger.error("MediaHelper.probe failed %s", ex);
return reject(ex);
}
};
cp.execFile('ffprobe', args, opts, cb)
.on('error', reject);
});
}//probe
or in this case to seek
to position in the media file:
seek = function (fpath, seconds) {
var self = this;
return new Promise((resolve, reject) => {
var loglevel = self.logger.isDebug() ? 'debug' : 'panic';
const args = [
'-hide_banner',
'-loglevel', loglevel,
'-show_frames',//Display information about each frame
'-show_entries', 'frame=pkt_pos',// Display only information about byte position
'-of', 'default=noprint_wrappers=1:nokey=1',//Don't want to print the key and the section header and footer
'-read_intervals', seconds + '%+#1', //Read only 1 packet after seeking to position 01:23
'-print_format', 'json',
'-v', 'quiet',
'-i', fpath
];
const opts = {
cwd: self._options.tempDir
};
const cb = (error, stdout) => {
if (error)
return reject(error);
try {
const outputObj = JSON.parse(stdout);
return resolve(outputObj);
} catch (ex) {
self.logger.error("MediaHelper.probe failed %s", ex);
return reject(ex);
}
};
cp.execFile('ffprobe', args, opts, cb)
.on('error', reject);
});
}//seek
Additional context Probe media files before processing; seek to media position;
Issue Analytics
- State:
- Created 3 years ago
- Reactions:22
- Comments:13
Top Results From Across the Web
alfg/ffprobe-wasm - GitHub
ffprobe -wasm uses emscripten to compile FFmpeg's libav to Web Assembly via Docker. Emscripten is also used to create and compile the Wasm...
Read more >ffprobe-wasm - npm
Gather information from multimedia streams. Works on the browser and Node.js. Uses the code at alfg/ffprobe-wasm, but in a packaged format, so ...
Read more >FFMPEG.WASM
ffmpeg.wasm is a pure WebAssembly / JavaScript port of FFmpeg. It enables video & audio record, convert and stream right inside browsers.
Read more >FFmpeg + WebAssembly - DEV Community
Tagged with ffmpeg, webassembly, cpp, tutorial. ... I also have a more advanced example of using FFProbe via Wasm:
Read more >ffprobe-wasm vs ffmpeg.wasm - compare differences and reviews ...
Posts with mentions or reviews of ffprobe-wasm. We have used some of these posts to build our list of alternatives and similar projects....
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Recently I had a use case where I needed to perform a duration check on media files on the browser before uploading to the server. I’ll put my approach here while I built my POC as it is somewhat related.
Use case For context, my use case is as follows:
ffprobe-wasm is not the full ffprobe program
ffprobe-wasm
, but I quickly discovered that the program that is being executed is not actuallyffprobe
, butffprobe-wasm-wrapper.cpp
which is essentially an attempt to rewriteffprobe
to be more emscripten friendly, but only contains a fraction of the utility thatffprobe
offers. The application as-is was insufficient for my use case as I needed to verify audio files as well.ffprobe-wasm-wrapper.cpp
at the time because it would essentially mean manually portingffprobe
to wasm, something I lacked both the time and expertise to do. What I instead explored is to compile the entire ffprobe into wasm, something which I managed to successfully accomplish. My fork of the ffprobe-wasm repo can be found here: https://github.com/crazoter/ffprobe-wasm. The messy & uncleaned steps I took are as follows:docker-compose run ffprobe-wasm make
.emmake make build
to build everything.my-dist
.ffmpeg-wasm
as the logs are async and there is no indicator to specify when the application has finished running.typeof SharedArrayBuffer !== "undefined"
to prevent the code from failing if you intended to use ffprobe without having to change your https headers.What I ended up using
ffmpeg-wasm
instead.ffmpeg-wasm
, but instead caused by how the emscripten file system is used. After all, we’d have to somehow bring the file into MEMFS before ffmpeg can even start processing it, and normally we just bring the whole file into MEMFS. What if we just bring in a slice of that?maxSlicedLength / file.size
.Invalid data found when processing input
For these types of files, there are 2 options currently available:MediaInfo
as it introduces complexity, so I decided to employ a much easier solution: audio tags which works well for mp4.Hopefully this write-up will benefit someone looking for a similar solution, or someone hoping to port ffprobe to wasm.
Any plan on support that? It would be awesome to get format and stream metadata on browser. Something like that:
ffprobe -hide_banner -loglevel fatal -show_error -show_format -show_streams -print_format json video.mp4
ffprobe is so much faster than ffmpeg because it don’t try to read the entire file.