New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
generate webm from frames #18
Comments
Apologies ffmpeg returns |
Seems like |
The images are in memory as mountfs doesn't work in Cordova. Wouldn't I need to have the images on disk or would that work since the images are listed in memfs? As for PNG format, what does ffmpeg.js support, JPEG? I can convert the images (toDataUrl) before passing them. Thank you |
MEMFS should always work.
Currently there are no image decoders, only for video. |
Oh I see... would it be possible for you to point me towards how I can generate a build with image decoders (any)? |
@Kagami Apologies for asking again about this (it's very urgent for me), I've looked at Makefile and read the build docs of ffmpeg, couldn't find any reference on how to compile with specific image decoders I'm under the impression this is somehow build-it (?), yet when I pass the jpeg frames I get the error |
Should work with latest version, I added JPEG decoder. PNG currently doesn't work because of emscripten issue. |
@Kagami Wow!!! Thank you so much!! This part works now excepting that the app runs out of memory and terminates :( Going to play around see if I can append N frames at a time instead; thank you again |
@Kagami Ok I managed to work around this, the issue I'm facing is I'm still receiving var memfs = [];
var args = ['-framerate', '30'];
var len = images.length;
for (var i =0;i<len;i++) {
var n = 'img'+pad(i, 3)+'.jpg'
memfs.push({name: n, data:images[i]})
args.push('-i');
args.push(n);
}
args = _.concat(args, ['-c:v', 'libvpx', '-pix_fmt', 'yuv420p', 'out.webm']) And I'm using the worker version: worker.postMessage({
type: "run",
MEMFS: memfs,
arguments: args
}); Not sure what I'm missing on, I see you added jpeg decoding to the tests, could it be the worker version not updated or I'm incorrectly using memfs? |
Your command should be Try to start with simplest case, convert single JPEG image to WebM. |
The problem with var memfs = [{name:'img-001.png', data:images[0]}];
var args = ['-framerate', '30', '-i', 'img-001.png', '-c:v', 'libvpx', '-pix_fmt', 'yuv420p', 'out.webm']; With the image data being |
It shouldn't, try that with standalone ffmpeg. Or maybe try
Are you using latest version? Try different image. Also try it on node platform just in case. |
I have already tried Now going to try |
Ok this is weird... using var memfs = [{name:'img-001.jpg', data:images[0]}];
var args = ['-pattern_type', 'glob', '-framerate', '30', '-i', 'img-001.jpg', '-c:v', 'libvpx', '-pix_fmt', 'yuv420p', 'out.webm'];
var result = ffmpeg({
MEMFS: memfs,
arguments: args,
print: function(data) { stdout += data + "\n"; },
printErr: function(data) { stderr += data + "\n"; },
onExit: function(code) {
console.log("Process exited with code " + code);
console.log(stderr)
console.log(stdout);
}
}); |
Maybe latest Emscripten brought some breaking changes in case of browser environment. Will check that. |
@Kagami Yeah... sorry about the hassle... |
It was a stdin request… Probably worth to mute it by default in order to avoid confusion, it should be barely needed. Here is full browser example, works for me just fine: <script>var module = {};</script>
<script src="node_modules/ffmpeg.js/ffmpeg-webm.js"></script>
<script>var ffmpeg = module.exports;</script>
<script src="index.js"></script>
<video id="video" autoplay loop></video>
<br><a id="link" download>download</a> function fetchData(url) {
return new Promise(function(resolve, reject) {
var xhr = new XMLHttpRequest();
xhr.open("GET", url, true);
xhr.responseType = "arraybuffer";
xhr.onload = function() {
if (this.status >= 200 && this.status < 400) {
resolve(new Uint8Array(this.response));
} else {
reject(new Error(this.responseText));
}
};
xhr.onerror = reject;
xhr.send();
});
}
Promise.all([
fetchData("/1.jpg"),
fetchData("/2.jpg"),
]).then(blobs => {
var res = ffmpeg({
MEMFS: blobs.map((data, i) => ({name: `${i+1}.jpg`, data})),
stdin: function() {},
arguments: [
"-framerate", "1",
"-i", "%d.jpg",
"out.webm",
],
});
var videoBlob = new Blob([res.MEMFS[0].data]);
var videoUrl = URL.createObjectURL(videoBlob);
document.getElementById("video").src = videoUrl;
document.getElementById("link").href = videoUrl;
}); It's very basic and a bit hacky, but you got the idea. |
oh I see, thank you very much I'll check it right away |
It worked!!!! THANK YOU!!!!! Just one minor thing which I can't figure out is how to get the result with the worker version, it seems that msg.type worker.onmessage = function(e)
{
var msg = e.data;
switch (msg.type) {
case "ready":
console.log('**** worker ready, merge')
worker.postMessage({
type: "run",
MEMFS: memfs,
arguments: args
});
break;
case "stdout":
console.log(msg.data)
stdout += msg.data + "\n";
break;
case "stderr":
console.log(msg.data)
stderr += msg.data + "\n";
break;
case "done":
var mem = msg.data.MEMFS;
console.log('DONE!!', mem)
worker.terminate();
break;
case "exit":
console.log("Process exited with code " +msg.data);
console.log(stdout);
console.log(stderr)
worker.terminate();
break;
}
}; |
Yea, resulting files should be in data field of |
Wow!!! Works like a charm!!!! Thank you SO SO much for saving the day for me!! Please let me know if you ever swing by Sweden I owe you beer! |
Thanks for you work! It is awesome! Please create a wiki page detailing these workarounds, and how to use arraybuffers from jpeg files to pass them to ffmpeg. |
First thanks for the awesome work!
I'm trying to merge multiple frames (about 120) at 30fps into a single video but for some reason I'm not getting any feedback from the worker.
I'm sending the following arguments:
A simple
--version
works just fine, wondering if I'm doing something wrong here? would very much appreciate any help.The text was updated successfully, but these errors were encountered: