-
-
Notifications
You must be signed in to change notification settings - Fork 336
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
Asynchronous stdin #16
Comments
That's interesting question. There were discussions regarding live streams in #11 and #12 but using stdin for that haven't been considered. Theoretically it might work. post-worker.js code need to be changed in order to be able to accept Do you want to try to implement this? |
Related: Seems like |
Well... some months ago I tried it, but based in videoconverter.js code: I managed to change the command. As it's synchronous exactly this problem happened: it don't receive message calls until the ffmpeg process stops. I tried to find some way to make ffmpeg async, like Asyncify and Emterpreter, without success. After some time I gave up. As you're working actively on this I thought you already knew a way to fix this problem. Seems it's not that simple. 😕 |
What exactly did you try with Asyncify and Emterpreter? |
I wanted do this, but in fact I don't even managed Emscripten to compile videoconverter.js: I use Windows, so shell scripts don't work. I tried to set up it in a Ubuntu machine but it also failed. Then I tried to set it using ffmpeg source directly, so I could use it on Windows. After that, IIRC, I abandoned the idea, mostly because I was trying to implement it in Direct MEGA and after some problems I stopped working on this project. |
I can only suggest you to try to build ffmpeg.js in Ubuntu VM. You need to have emsdk installed (see here) and some basic dev packages. Then clone this project, checkout all submodules and type |
Understood. I will set up a VM and try it again. |
I tried in one of those lightweight Ubuntu distros, then it failed. I tried again with Ubuntu Server 16.04.1 i386 and I found that I was missing some steps and doing other wrong. But it still failed. This was the last error that I couldn't find a solution: https://i.imgur.com/JZLWvWP.png I only found bug reports for this problem. From some of those maybe the problem is the distro, so |
I haven't encountered issues with lame build. I'm using 64bit distro/compilers though, so yes, that might be the case. |
I tried without lame and in a 64bit distro (Cloud9). What I'm doing:
Is some step wrong? |
@qgustavor install pkg-config as well: |
I retried in a fresh Cloud9 Ubuntu x64 instance and it still failed. There are the log files for make ffmpeg-worker-mp4.js and make ffmpeg-worker-webm.js. |
You're still building lame, see my previous comment how to disable it. |
On some versions of Emscripten/configurations check for xmmintrin returns true but the vectorized code fails to build. See: #16
I made a custom build of ffmpeg.js with support for only rawvideo input, the pipe protocol, mp4 and null output, and the H.264 encoder. I works, but it looks like there's no way to send more than 1 byte on stdin at a time, so to read an 800x600 RGB frame, there are 1440000 calls to my stdin function, even though emscripten knows that ffmpeg wants 1440000 bytes. I profiled it and rendering the frame takes 13ms but the read syscall takes 28ms because of the iterative function call used to copy the buffer one byte at a time. Try it at https://benlubar.github.io/cmv2mp4/ - worker.js is not minified, so it should be pretty easy to read. Example input file: https://benlubar.github.io/cmvjs/ai_trade.cmv |
You could try throwing this in your ffmpeg command eg:
|
I have successfully implemented feeding frames via stdin. The main problem is that ffmpeg blocks the execution, so a worker can't process income messages. You have to use either ASYNCIFY (didn't compile in my case at all) or EMTERPRETIFY_ASYNC to interrupt the ffmpeg process. You need to empretify the whole stack from You can take a look the result in my fork. Kukunin@acca0c1#diff-b67911656ef5d18c4ae36cb6741b7965R347 Also, there is I implemented I plan to prepare a PR to the upstream, but don't know when. |
@Kukunin Do you have any client-side (javascript) code examples? I am trying to figure out how to handle IO (sending arguments, retrieving output) with your fork. |
take a look into |
as an example, how to use it, you can take a look to this code: opts = {}; // other options here
opts['stdinAsync'] = function(size, callback) {
getMyInputSomehow().then((data) => {
callback(data.subarray(0, size)) // ensure you pass not more than size
});
};
opts["stdoutBinary"] = function(data) {
const frame = Uint8Array.from(data);
self.postMessage({"type": "frame", "data": frame}, [frame.buffer]);
};
ffmpeg(opts); |
@Kukunin Thanks for the fork, I was able to build it. Is it possible to use your fork in an Any quick snippet for that? |
My fork doesn't break the current functionality (as far as I know), so you use the same configuration as you would do with the upstream. Configure stdinAsync or stdoutBinary according to your needs |
One note about my fork: it calls Not sure, if this behavior is a bug or a feature =) |
Look at the diff in his branch, it should show you |
Thanks @Kukunin, cool stuff! |
Asynchronous stdin support by @PaulKinlan using |
@Kukunin, is it possible to use both stdoutBinary and stdinAsync at the same time? I'm finding that it only lets me use one or the other, and wonder if that might be due to Module['HEAPU8'] ? |
they are independent so they work both at the same time. From your message, it's not clear for me, how exactly it lets you use only one of them. Is there any error? |
@Kukunin, oh that's interesting. I wonder if I'm doing something else wrong then? I think the only difference between my setup and yours is that I compiled using ASYNCIFY=1 and am using Asyncify.handleSleep, because EMTERPRETIFY_ASYNC wouldn't compile for me. Is there anything obvious here that I'm doing wrong here? Makefile:
library.js:
post-worker.js:
I'm finding that the console.log in emscripten_binary_write only writes 3 quick times at the beginning and then stops. But the emscripten_binary_read logs continue to write. |
@Kukunin would it be possible to update the readme/makefiles of your fork for it to work now ? |
@Kukunin @nanook21 @Kagami Hello people, i understand nothing about this issue, i need to know how to feed ffmpeg with webm chunks from mediarecorder blobs. i do not know which asm output i will use, can you guys explain me with basic code if possible ? i have mediarecorder chunks. please show me how to feed ffmpeg with webm chunks please. i need stdout chunks like nodejs spawn module mediaRecorder.ondataavailable=function(e) { mediaRecorder.start(1000) // i get chunks every 1 sec |
Can anyone help me hook up |
I meet the same issue. Anyone has an idea? |
On some versions of Emscripten/configurations check for xmmintrin returns true but the vectorized code fails to build. See: Kagami#16
With the use of Web Streams videos could be downloaded then converted to other format without too expensive memory usage. I don't know if Emscripten supports that, as seems it blocks its thread, but if it's possible would be interesting.
The text was updated successfully, but these errors were encountered: