mattdesl / mp4-h264

[project suspended] MP4 + H264 encoding for the browser with WASM
MIT License
223 stars 11 forks source link

h264 to mp4 live #7

Open e1ioan opened 3 years ago

e1ioan commented 3 years ago

This is not an issue, but a question. I have my own code to get the h264 stream from an IP camera and save it to file. I tested this file with your code and it will convert fine to mp4. The player that I want to play the stream on, doesn't support h264 streams, but you can play an mp4 that resides on a remote location, on a website for example. My question is, how hard would be (and is it even possible) to convert the live stream I get from the camera to mp4, tell the player that this is a 24 hours long mp4 video for example (so it doesn't look for the end of the file), and convert the stream that I get from the camera on the fly?

I hope it makes sense what I'm trying to say.

mattdesl commented 3 years ago

You'll want to set { sequential: true, fragmentation: true } to get encoded data that can be streamed back. Theoretically I imagine this module should be possible to work with live streaming (the minimp4 mentions fMP4 and HLS) but I'm not sure exactly the process to get that, it would be some mixture of Node.js server + streams and such to handle buffering a chunk of live data to, say, a browser that is requesting a <video> tag.

If you don't need the encoding to run in the browser, then it might be easier to use ffmpeg + some already-tested HLS modules on npm. It sounds like you're going to need to use Node.js anyways if you want to host the video files on a server.

Happy to hear more thoughts about this though.

e1ioan commented 3 years ago

No browser involved, but I can't use ffmpeg because I want to implement this on the Roku devices. Another problem is that the Roku only supports a scripting language called BrightScript so I need to port all the code to that language. I was able, so far, to decode jpeg encoded rtsp streams on roku, I had to make it from scratch, but it works very well. The rtsp packets that transport h264 stream are the same as above, so that part is done and I'm able to save raw h264 streams, with some modifications. The problem is that Roku, cannot play raw h264 streams but it can play mp4. For streaming Roku mainly uses HLS.

Yesterday I played a little more with the formats and it seems that if I convert the raw stream to mp4 chunks and use the extension .ts and create the m3u8 file for playlist for HLS, the Roku will play all the chunks fine, so that's maybe the way I should go. I used your code for this conversion.

I also looked to aspt/mp4 and I'm guessing that it will work better for my needs only because is less code to convert to BrightScript, the problem is that I don't know much about how the h264 works and, so far, I can't figure it out how to make mp4 from raw 264 using the aspt/mp4 code.

(As a side note, I use ffmpeg right now with external hardware, a raspberry pi, but I want to make it work directly on the Roku device, to get rid of the rapberry pi).