-
-
Notifications
You must be signed in to change notification settings - Fork 335
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
On the fly transcoding #11
Comments
What type of stream do you mean? In browser you have same-origin enforcement and basically can do only HTTP and WebSocket requests. In case of HTTP same-origin media stream it might be possible, though you'll need to patch ffmpeg in order to use Emscripten HTTP calls, see here. In case of TCP, UDP, streams without CORS headers, etc. you will need some proxy and to wrap stream data into HTTP/WebSocket in order to read that in the browser. See discussion here. You may also try Virtual XHR Backed FS: create lazy file for HTTP stream on the JS side and open it in ffmpeg as regular file. Though I'm not sure how good that would work. |
I think this was answered, feel free to ask additional questions. Transcoding might be possible on the fly (via patching or XHR FS) in some cases (e.g. same-origin HTTP), but I don't think there is a sane way to play intermediate results in main process. There is SharedArrayBuffer but it's experimental and it's a bad idea to start playing a file while ffmpeg transcodes it. |
Hey can you please tell how to patch or use xhr fs for transcoding on the fly. i want to encode file uploaded by my user from mp4 to .264 format for later using it for mp4box.js for segmenting it which is also going to be done on the fly . Any help will be appreciated thankyou!! |
@Kagami Hello, a use case I'm interested in: Raspberry Pi's Edit: these streams would be continuous/infinite, the practical use case is surveillance camera footage viewing in the browser. |
In case someone finds this issue in the feature, I'd like to point out that it is possible to do this using Asyncify. However, I had to go through quite a bit of trouble while doing it myself, so I'd like to leave some tips for people who might want to do it. First thing's first, TL;DR, here's a Dockerfile which will build an "async" ffmpeg.wasm. You will need to edit or create your own ffmpeg.js to use it, as the default would not do anything async.
You can use it like this:
The important parts here:
After this, the JS needs to be created. As stated, beautifying the existing JS helps a lot. But it still leaves a lot of work left. Here's some landmines I stepped on:
Hopefully this will help any people in the future to not be stuck on the same things I was stuck on. |
@SlugFiller It would be nice if you could publish the async version and provide examples in a fork for others to use and improve upon. |
@deepesh-agarwal It's not really a fork. It's just the above Dockerfile, edited JS worker, and the calling app. The JS worker is somewhat of a hackjob made in a rush, which could certainly be made better by someone actually spending time on it from scratch. And the calling app uses a very my-style app-specific API, which isn't likely to make sense to a third party. If I was bothering to make something worth showing, I'd have at least subclassed node's Stream. And if I had the time, I'd reimplement the worker with 0 Emscripten code lines. What I ended up with is mostly the product of time constraints. A person making those latter two from scratch using my above tips could probably get much better results. Someone going the extra mile might even asyncify other methods, like enabling net access. |
Thanks @SlugFiller, that's really interesting! |
Did anyone manage to reproduce/make a stream-able ffmpeg version based on @SlugFiller instructions/tips ? |
@SlugFiller - trying to reproduce your effort and I have to say that even the code you're afraid about posting would help speed things up significantly, seeing as it's 10 months past now and a lot has changed. |
@dinedal - You're right that a lot has changed, namely in that the system that was using the code has been mostly phased out of use, due to underperforming. It was a lightweight SIP server that would stream audio from HTTP (or compatible) to the caller. The problem is that the RTP stream timing wasn't stable enough, and the stream would sound, while recognizable, quite distorted. Anyway, since the code is no longer in use, I figure it wouldn't harm to let others have a look, and maybe you can figure out what was wrong with the RTP timing. I've temporarily put the code here: Grab it while it's hot. It's temporary hosting, which is probably a good thing, because pre-compiled ffmpeg is probably a violation of the license. This code will automatically CnD itself in 30 days. Compiling it yourself can be done using the above Dockerfile anyway. |
Grabbing now, thanks @SlugFiller ! |
I have on-the-fly transcoding using asyncify working in #166 |
Is it possible to use ffmpeg.js for realtime (on-the-fly) transcoding and playing of media stream (e.g. online radio or online TV) in the browser (without needing to download the entire media file before it can start playing)?
The text was updated successfully, but these errors were encountered: