illuspas / Node-Media-Server

A Node.js implementation of RTMP/HTTP-FLV/WS-FLV/HLS/DASH/MP4 Media Server
https://www.npmjs.com/package/node-media-server
MIT License
5.89k stars 1.51k forks source link

How to stream mp4 files? #604

Closed hotfusion closed 9 months ago

hotfusion commented 9 months ago

Hello, I am been struggling to stream my mp4 files with dash.js using this package, the documentation really useless and doesn't help match. I was able to mount the server with these configurations: `{

"rtmp": {
    "port"         : 1935,
    "chunk_size"   : 60000,
    "gop_cache"    : true,
    "ping"         : 30,
    "ping_timeout" : 60
},
"http": {
    "port"         : 8000,
    "allow_origin" : "*",
    "mediaroot" : "c:/mymedia"
},
"trans": {
    "tasks": [{
       "app"       : "live",
       "vc"        : "copy",
       "ac"        : "aac",
       "rtmpApp"   : "live2",
       "hls"       : true,
       "dash"      : true,
       "rtmp"      : true,
       "hlsFlags"  : "[hls_time=2:hls_list_size=3:hls_flags=delete_segments]",
       "dashFlags" : "[f=dash:window_size=3:extra_window_size=5]",
       "vcParam"   : [],
       "acParam"   : ["-ab", "64k", "-ac", "1", "-ar", "44100"],
    }]
}

}`

I have a file which I stored in c:/mymedia/example.mp4 and when I am trying to play this file in dash.js player, i am getting an error: http://localhost:8000/live/example.mp4 net::ERR_CONNECTION_REFUSED Should I convert the mp4 file to another format? Maybe the URL I am entering is not correct http://localhost:8000/live/example.mp4? Is there an example that I can follow how to do it? I tried to google it but found nothing... Thanks

hotfusion commented 9 months ago

I found the answer, http://localhost:8000/live/example.mp4 was a wrong link, should use http://localhost:8000/example.mpd. The mp4 file must to convert into mpd ffmpeg -i example.mp4 -vcodec copy -acodec copy example.mpd before the stream. However, for dash files you can have a simple express server.