mux.js
mux.js copied to clipboard
How to Transmux NAL Units Stream to fragmented mp4
I have a stream of NAL packets coming in through the websocket. I would like to know how to setup so sent the NAL units into the Transmuxer so it output is a mp4. I was trying like this but i did not see any events getting triggered
let muxer = new muxjs.Transmuxer();
muxer.init();
muxer.on( 'data', segment =>
{
console.log( segment );
}
function onNalUnitReceived( nalUnit )
{
muxer.push( nalUnit );
}
How do i convert the nalUnit i receive in onNalUnitReceived
callback to an mp4
After you've pushed some data to the transmuxer, youll want to call muxer.flush()
to finish processing the data youve pushed, otherwise you'll never see a data
event
I called muxer.flush
that raised the event but segment.data
is an empty array.. What am i doing wrong.
Am i feeding in wrong data to the muxer ??
The data i am feeding is NAL Units [ h264 packets encoding using the main profile ].
Each packet starts with the default 00 00 00 01
I suspect your case is like mine: mux.js is expecting access unit delimiters at the start of an access unit but I do not think this is required by the spec.
Hi, I'm facing a similar problem. I receive mpeg-ts stream over WebSocket and try to transmux it using mux.js. What I've noticed is it does seem work once I collect around 14-16 packets and flush the transmuxer. If I flush it to early, I end up with the same issue as above - empty data array. So, flushing the transmuxer every 15 packets does the job, however the stream seems to be stuttering for the first couple of seconds and then begins to play smoothly - I guess it's because at that point the player has enough data in the buffer for a smooth playback. I wonder then, is there a way we could tell there's enough data for the transmuxer to generate a valid, combined buffer (video+audio data) that we could use to tell when to flush the transmuxer?
You probably want to modify transmuxer a little so that you can call flush every packet, but it doesn't clear the collected nal units (resetStream), returns early if it built no frames (but keeps the nal units/frames) and produces a GOP on i-frame boundaries instead of looking for the access_unit_delimiter which is not required by the spec to be in the stream (but is helpful)
Do you have any luck with this task? I have raw h264 stream extracted from mkv container. And I also getting empty segment.data array.
PR #200 should solve this issue.
Did anyone get this working? I'm interested in pumping raw h264 bitstream into transmux, extracting SEI nal units and wrapping the rest in an mp4 to be displayed.
@gwolny Geat Job! help me a lot!
Hello @gwolny and guys. I have some issue on let the patch (https://github.com/gwolny/mux.js/commit/437ecad8581f20cd8920345585a47cb72208ce7d) works.
I'm feeding the transmuxer with uint8array NAL units (included 0001 delimiter), but as told by some guys before me, the buffer from on data event is empty. Following the code:
let mux = new muxjs.mp4.Transmuxer();
mux.on('data', function (segment) {
// segment.data.buffer is empty
});
webSocket = new WebSocket("ws://ip_address/stream_id");
webSocket.binaryType = "arraybuffer";
webSocket.onmessage = function (messageEvent) {
mux.push(new Uint8Array(messageEvent.data));
mux.flush();
}
The stream from ffmpeg is built with this command:
.\ffmpeg.exe -stream_loop -1 -re -i .\Files\timer.mp4 -c:v libx264 -vprofile baseline -b:v 600k -bufsize 600k -tune zerolatency -pix_fmt yuv420p -an -f rawvideo http://ip_address/stream_id
Please could you help me guys? Thanks
Hello,
I would like to give you an update about my issue.
I was able to get a proper segment.data.buffer after I merged following code https://github.com/videojs/mux.js/issues/227 (basically it performs an autoflush when it recognizes a end_of_seq_rbsp NAL) to the gwolny@437ecad patch.
Is it the right direction? Or what I'm doing does not make sense?
Thanks
Hi everyone,
any news on merging this PR in master?