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

Failed to access the live stream with websocket-flv/HLS/DASH protocols. #447

Open hongyi-zhao opened 3 years ago

hongyi-zhao commented 3 years ago

On Ubuntu 20.04, I installed and tested the git master version of Node-Media-Server with the following steps:

$ openssl genrsa -out privatekey.pem 2048
$ openssl req -new -key privatekey.pem -out certrequest.csr
$ openssl x509 -req -in certrequest.csr -signkey privatekey.pem -out certificate.pem

$ git clone https://github.com/illuspas/Node-Media-Server.git illuspas/Node-Media-Server.git
$ npm i
$ node app.js

# Publishing live streams
$ ffmpeg -re -i rtmp://ivi.bupt.edu.cn/livetv/cctv1hd -c copy -f flv rtmp://localhost/live/stream

# Accessing the live stream with the followng two methods will succeed:
$ ffplay rtmp://localhost/live/stream
$ ffplay http://localhost:8000/live/stream.flv

# All of the following accessing methods failed:
# websocket-flv
$ ffplay ws://localhost:8000/live/stream.flv
[...]
ws://localhost:8000/live/stream.flv: Protocol not found

#HLS
$ ffplay http://localhost:8000/live/stream/index.m3u8
[...]
htt1p://localhost:8000/live/stream/index.m3u8: Server returned 404 Not Found

#DASH
$ ffplay http://localhost:8000/live/stream/index.mpd
[...]
http://localhost:8000/live/stream/index.mpd: Server returned 404 Not Found

Any hints for this problem will be highly appreciatged.

Regards, HY

shadowsong91 commented 3 years ago

Same problem...

eugenedw commented 3 years ago

Having same issue

shadowsong91 commented 3 years ago

Solved!Add trans config!

    trans: {
        ffmpeg: 'your ffmpeg binary path',
        tasks: [
            {
                app: 'live', // or other 
                hls: true
            }
        ]
    }
hongyi-zhao commented 3 years ago

Do you mean add these codes in app.js before the auth section?

shadowsong91 commented 3 years ago

Yes, same level with http or rtmp.

hongyi-zhao commented 3 years ago

Based on your notes, I tried with the following settings:

 trans: {
    ffmpeg: '/usr/local/bin/ffmpeg',
    tasks: [
      {
        app: 'live', // or other 
        hls: true,
        hlsFlags: '[hls_time=2:hls_list_size=3:hls_flags=delete_segments]',
        dash: true,
        dashFlags: '[f=dash:window_size=3:extra_window_size=5]',
        "websocket-flv": true
      }
      ]
  }, 

The above config can let me play the following formats correctly:

# HLS
$ ffplay http://localhost:8000/live/stream/index.m3u8
# DASH
$ ffplay http://localhost:8000/live/stream/index.mpd

But still failed to play the websocket-flv:

$ ffplay ws://localhost:8000/live/stream.flv
ffplay version N-100814-g911ba8417e Copyright (c) 2003-2021 the FFmpeg developers
  built with gcc 9 (Ubuntu 9.3.0-17ubuntu1~20.04)
  configuration: --enable-gpl --enable-nonfree --enable-version3 --enable-debug --enable-ffplay --enable-indev=sndio --enable-outdev=sndio --enable-fontconfig --enable-frei0r --enable-openssl --enable-gmp --enable-libgme --enable-gray --enable-libaom --enable-libfribidi --enable-libass --enable-libvmaf --enable-libfreetype --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-librubberband --enable-libsoxr --enable-libspeex --enable-libsrt --enable-libvorbis --enable-libopus --enable-libtheora --enable-libvidstab --enable-libvo-amrwbenc --enable-libvpx --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxml2 --enable-libdav1d --enable-libxvid --enable-libzvbi --enable-libzimg --enable-rpath --enable-shared --enable-avisynth --enable-chromaprint --enable-gcrypt --enable-ladspa --enable-libaribb24 --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libcelt --enable-libcdio --enable-libcodec2 --enable-libdc1394 --enable-libfdk-aac --enable-libflite --enable-libfontconfig --enable-libgsm --enable-libiec61883 --enable-libjack --enable-libklvanc --enable-liblensfun --enable-libmodplug --enable-libopenh264 --enable-libopenmpt --enable-libpulse --enable-librabbitmq --enable-librsvg --enable-librtmp --enable-libshine --enable-libsnappy --enable-libssh --enable-libtesseract --enable-libtwolame --enable-libv4l2 --enable-libxavs2 --enable-libdavs2 --enable-libxcb --enable-libxcb-shm --enable-libxcb-xfixes --enable-libxcb-shape --enable-libzmq --enable-lv2 --enable-libmysofa --enable-openal --enable-opencl --enable-opengl --enable-pocketsphinx --enable-vulkan --enable-libdrm --enable-libmfx --enable-pic --enable-lto --enable-hardcoded-tables --enable-memory-poisoning --enable-ftrapv --enable-linux-perf --enable-libsvtav1
  libavutil      56. 63.101 / 56. 63.101
  libavcodec     58.119.100 / 58.119.100
  libavformat    58. 65.101 / 58. 65.101
  libavdevice    58. 11.103 / 58. 11.103
  libavfilter     7. 97.100 /  7. 97.100
  libswscale      5.  8.100 /  5.  8.100
  libswresample   3.  8.100 /  3.  8.100
  libpostproc    55.  8.100 / 55.  8.100
ws://localhost:8000/live/stream.flv: Protocol not found
    nan    :  0.000 fd=   0 aq=    0KB vq=    0KB sq=    0B f=0/0   

I still can't figure out the solution for this scenario.

Regards, HY

danielehrhardt commented 3 years ago

Based on your notes, I tried with the following settings:

 trans: {
    ffmpeg: '/usr/local/bin/ffmpeg',
    tasks: [
      {
        app: 'live', // or other 
        hls: true,
        hlsFlags: '[hls_time=2:hls_list_size=3:hls_flags=delete_segments]',
        dash: true,
        dashFlags: '[f=dash:window_size=3:extra_window_size=5]',
        "websocket-flv": true
      }
      ]
  }, 

The above config can let me play the following formats correctly:

# HLS
$ ffplay http://localhost:8000/live/stream/index.m3u8
# DASH
$ ffplay http://localhost:8000/live/stream/index.mpd

But still failed to play the websocket-flv:

$ ffplay ws://localhost:8000/live/stream.flv
ffplay version N-100814-g911ba8417e Copyright (c) 2003-2021 the FFmpeg developers
  built with gcc 9 (Ubuntu 9.3.0-17ubuntu1~20.04)
  configuration: --enable-gpl --enable-nonfree --enable-version3 --enable-debug --enable-ffplay --enable-indev=sndio --enable-outdev=sndio --enable-fontconfig --enable-frei0r --enable-openssl --enable-gmp --enable-libgme --enable-gray --enable-libaom --enable-libfribidi --enable-libass --enable-libvmaf --enable-libfreetype --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-librubberband --enable-libsoxr --enable-libspeex --enable-libsrt --enable-libvorbis --enable-libopus --enable-libtheora --enable-libvidstab --enable-libvo-amrwbenc --enable-libvpx --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxml2 --enable-libdav1d --enable-libxvid --enable-libzvbi --enable-libzimg --enable-rpath --enable-shared --enable-avisynth --enable-chromaprint --enable-gcrypt --enable-ladspa --enable-libaribb24 --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libcelt --enable-libcdio --enable-libcodec2 --enable-libdc1394 --enable-libfdk-aac --enable-libflite --enable-libfontconfig --enable-libgsm --enable-libiec61883 --enable-libjack --enable-libklvanc --enable-liblensfun --enable-libmodplug --enable-libopenh264 --enable-libopenmpt --enable-libpulse --enable-librabbitmq --enable-librsvg --enable-librtmp --enable-libshine --enable-libsnappy --enable-libssh --enable-libtesseract --enable-libtwolame --enable-libv4l2 --enable-libxavs2 --enable-libdavs2 --enable-libxcb --enable-libxcb-shm --enable-libxcb-xfixes --enable-libxcb-shape --enable-libzmq --enable-lv2 --enable-libmysofa --enable-openal --enable-opencl --enable-opengl --enable-pocketsphinx --enable-vulkan --enable-libdrm --enable-libmfx --enable-pic --enable-lto --enable-hardcoded-tables --enable-memory-poisoning --enable-ftrapv --enable-linux-perf --enable-libsvtav1
  libavutil      56. 63.101 / 56. 63.101
  libavcodec     58.119.100 / 58.119.100
  libavformat    58. 65.101 / 58. 65.101
  libavdevice    58. 11.103 / 58. 11.103
  libavfilter     7. 97.100 /  7. 97.100
  libswscale      5.  8.100 /  5.  8.100
  libswresample   3.  8.100 /  3.  8.100
  libpostproc    55.  8.100 / 55.  8.100
ws://localhost:8000/live/stream.flv: Protocol not found
    nan    :  0.000 fd=   0 aq=    0KB vq=    0KB sq=    0B f=0/0   

I still can't figure out the solution for this scenario.

Regards, HY


const config = {
  rtmp: {
    port: 1935,
    chunk_size: 60000,
    gop_cache: true,
    ping: 30,
    ping_timeout: 60,
  },
  http: {
    port: 8000,
    mediaroot: './media',
    allow_origin: '*',
  },

  trans: {
    ffmpeg: 'C:/bin/ffmpeg-4.4-full_build/bin/ffmpeg.exe',
    tasks: [
      {
        app: 'live', // or other
        hls: true,
        hlsFlags: '[hls_time=2:hls_list_size=3:hls_flags=delete_segments]',
        dash: true,
        dashFlags: '[f=dash:window_size=3:extra_window_size=5]',
        'websocket-flv': true,
      },
    ],
  },
};
hongyi-zhao commented 3 years ago

I already have the above configuration in app.js:

const config = {
  rtmp: {
    port: 1935,
    chunk_size: 60000,
    gop_cache: true,
    ping: 30,
    ping_timeout: 60,
    /*
    ssl: {
      port: 443,
      key: './privatekey.pem',
      cert: './certificate.pem',
    }
    */
  },
  http: {
    port: 8000,
    mediaroot: './media',
//    webroot: './www',
    allow_origin: '*',
    api: true
  },
  https: {
    port: 8443,
    key: './privatekey.pem',
    cert: './certificate.pem',
  },

    trans: {
    ffmpeg: '/usr/local/bin/ffmpeg',
    tasks: [
      {
        app: 'live', // or other
        hls: true,
        hlsFlags: '[hls_time=2:hls_list_size=3:hls_flags=delete_segments]',
        dash: true,
        dashFlags: '[f=dash:window_size=3:extra_window_size=5]',
        'websocket-flv': true,
      },
    ],
  },

  auth: {
    api: true,
    api_user: 'admin',
    api_pass: 'admin',
    play: false,
    publish: false,
    secret: 'nodemedia2017privatekey'
  }
};

See the following info:

$ node app.js
6/21/2021 08:39:23 2652553 [INFO] Node Media Server v2.2.8
6/21/2021 08:39:23 2652553 [INFO] Node Media Rtmp Server started on port: 1935
6/21/2021 08:39:23 2652553 [INFO] Node Media Http Server started on port: 8000
6/21/2021 08:39:23 2652553 [INFO] Node Media WebSocket Server started on port: 8000
6/21/2021 08:39:23 2652553 [INFO] Node Media Https Server started on port: 8443
6/21/2021 08:39:23 2652553 [INFO] Node Media WebSocketSecure Server started on port: 8443
6/21/2021 08:39:23 2652553 [INFO] Node Media Trans Server started for apps: [ live ] , MediaRoot: ./media, ffmpeg version: N-100814-g911ba8417e
Salman2301 commented 1 month ago

Looks like the appname was empty and causing the stream of flv from http://localhost:8000/appname/stream.flv this becomes http://localhost:8000//stream.flv

Created a PR and not sure if that will fix it