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

hi if i want rtmp to fmp4 stream how can i start #6

Closed MarsCaiWORD closed 4 years ago

MarsCaiWORD commented 4 years ago

ex. if i have rtmp://x.x.x.x/live/test
how can i use node.js create fmp4 stream

not work const ffmpeg = spawn( 'ffmpeg', ['-loglevel', 'quiet', '-probesize', '64', '-analyzeduration', '100000', '-reorder_queue_size', '5', '-rtsp_transport', 'tcp', '-i', 'rtmp://127.0.0.1:1935/live/test', '-an', '-c:v', 'copy', '-f', 'mp4', '-movflags', '+frag_keyframe+empty_moov+default_base_moof', '-metadata', 'title="ip 127.0.0.1"', '-reset_timestamps', '1', 'pipe:1'], { stdio: ['ignore', 'pipe', 'inherit'] } );

kevinGodell commented 4 years ago

Before trying to run this command inside nodejs, run it in the command line. Of course, make sure you have ffmpeg installed. Start with the simplest command with the input and output. Some of those input flags may not apply to rtmp input, I am not sure. I would try something along the lines of ffmpeg -loglevel verbose -i rtmp://127.0.0.1:1935/live/test video.mp4. Ffmpeg is pretty good at guessing the input type and has good default parameters set. If that command can make a playable mp4, then you can start tweaking the flags and customize the video stream. Let me know your results. I am here to help.

MarsCaiWORD commented 4 years ago

const ffmpeg = spawn( 'ffmpeg', ["-i", "rtmp://127.0.0.1/live/test", '-f', 'mp4', '-movflags', '+frag_keyframe+empty_moov+default_base_moof', '-metadata', 'title="ip 127.0.0.1"', '-reset_timestamps', '1', 'pipe:1' ], { stdio: ['ignore', 'pipe', 'inherit'] } );

i try this can work , but my init-pool.mp4 is empty

image

MarsCaiWORD commented 4 years ago

is work , sorry to bother you ,btw do you know how to build Low latency HLS?

kevinGodell commented 4 years ago

Low latency Hls is not easy. The trick is to get the individual mp4 fragments to be as small as possible. If you can get the chunk size to be 1 second duration, it might get down to a 2 second delay at best. This is a limitation of the mp4 container.