kevinGodell / mp4frag

Parser that works with ffmpeg to read piped data and fragment mp4 into an initialization segment and media segments. It can also get the codec info and generate an fmp4 HLS m3u8 playlist.
https://kevingodell.github.io/mp4frag/
MIT License
68 stars 15 forks source link

Streaming live h264 video using mp4frag #4

Closed karlbrowns closed 4 years ago

karlbrowns commented 4 years ago

Hi Kevin, I want to stream a live h264 stream to a web browser video panel. I'm already using node for the web server, and ffmpeg to turn the h264 stream to fragmented mp4, and then I found your mp4frag module. The issue I have at the moment without mp4frag is that I feed the ffmpeg data into node via a UDP port, and whenever this gets some data it writes it out on the wss socket to the browser. However, as it comes in in small chunks, the browser tries to add the buffer received to the mediasource sourceBuffer and this fails with a CHUNK DEMUXER ERROR APPEND FAILED error. I'm running this on an embedded system, so don't have vast amounts of storage available, and don't want the latency of HLS. Is it possible to get mp4frag to send the stream to MSE one frame at a time? How would I configure it to do this? Many thanks, Simon

kevinGodell commented 4 years ago

hi Simon (@karlbrowns)

If I remember correctly, mediasource can only use mp4 segments. Feeding it raw h264 data probably will not work, as you have discovered.

Mp4frag only searches for the start and end tags of mp4 fragments/segments of frames and parses them out. It does not have the capability to find individual frames.

If you need to make smaller chunks to lower latency, then you will have to use ffmpeg to encode the mp4 data as you need, as opposed to simply copying it directly from your video source. Of course, encoding the video will result in a much higher cpu load.

If you want to brainstorm a little, please post some of your code and ffmpeg params being used.

kevin