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.98k stars 1.52k forks source link

how to get mp4 resolution(1920 * 1080)HD and rtmp stream HD( by default not good quality stream) #347

Open RupamShaw opened 4 years ago

RupamShaw commented 4 years ago

with this recorded mp4 is 360*640 which is not good quality.

 rtmp: {
    port: process.env.RTMPPORT || 1935, 
    chunk_size: 60000,
    gop_cache: false,
    ping: 60,
    ping_timeout: 30,
  },
  http: {
    port: process.env.RTMPHTTPPORT || 8000, 
    mediaroot: "./myMedia",
    allow_origin: "*",
  },
  trans: {
    ffmpeg: "./node_modules/ffmpeg-static/bin/darwin/x64/ffmpeg"",
    tasks: [
      {
        app: "live",
        ac: "aac",
        acParam: ['-ab', '64k', '-ac', '1', '-b:a', '192k', '-ar', 48000],
        mp4: true,
        mp4Flags: "[movflags=faststart]",
        vcParam: ['-vf', "'scale=1920:-1'", '-b:v', '14000k', '-preset', 'fast', '-profile:v', 'baseline', '-bufsize', '7500k'],
}]}

I would like to have full HD (1920 1080 ) or HD (1280 720) for mp4 and RTMP stream also HD.

http://localhost:8000/api/streams :output stream is

{
  "live": {
    "5ec49b911b2011003d2cff50-1": {
      "publisher": {
        "app": "live",
        "stream": "5ec49b911b2011003d2cff50-1",
        "clientId": "GCIYYMFP",
        "connectCreated": "2020-05-25T06:58:10.888Z",
        "bytes": 18279229,
        "ip": "::ffff:192.168.1.8",
        "audio": {
          "codec": "AAC",
          "profile": "HE",
          "samplerate": 44100,
          "channels": 1
        },
        "video": {
          "codec": "H264",
         "width": 0,
          "height": 0,
          "profile": "High",
          "level": 31
        }
      },
      "subscribers": [
        {
          "app": "live",
          "stream": "5ec49b911b2011003d2cff50-1",
          "clientId": "UKKI3PTZ",
          "connectCreated": "2020-05-25T06:58:12.022Z",
          "bytes": 17100143,
          "ip": "::ffff:127.0.0.1",
          "protocol": "rtmp"
        },
        {
          "app": "live",
          "stream": "5ec49b911b2011003d2cff50-1",
          "clientId": "UBI0BNUD",
          "connectCreated": "2020-05-25T06:58:12.804Z",
          "bytes": 15640973,
          "ip": "::ffff:192.168.1.4",
          "protocol": "rtmp"
        }
      ]
    }
  }
}

video width and height 0 0 ? how i can get**

   "video": {
          "codec": "H264",
          "width": 1920,
          "height": 1080,
          "profile": "Main",
          "level": 4.1,
          "fps": 24
        }

please help @illuspas how to achieve good video streaming quality

package.json contains  

 "node-media-server": "^1.5.1", 
 "@ffmpeg-installer/ffmpeg": "^1.0.20",
    "@ffprobe-installer/ffprobe": "^1.0.12", 
 "ffmpeg-static": "^2.3.0",
    "fluent-ffmpeg": "^2.1.2",

console output

5/25/2020 17:14:12 89608 [INFO] Node Media Trans Server started for apps: [ live ] , MediaRoot: ./myMedia, ffmpeg version: 4.2-tessus
node_core_logger.js:27
5/25/2020 17:14:12 89608 [INFO] There is a new version 2.1.9 that can be updated
node_core_logger.js:27
5/25/2020 17:14:12 88158 [INFO] [rtmp connect] id=N73B3JBJ ip=::ffff:192.168.1.8 app=live args={"app":"live","type":"nonprivate","flashVer":"FMLE/3.0 (compatible; Lavf58.20.100)","swfUrl":"","pageUrl":"","tcUrl":"rtmp://192.168.1.4:1935/live"}
node_core_logger.js:27
5/25/2020 17:14:12 88158 [INFO] [rtmp publish] New stream. id=N73B3JBJ streamPath=/live/5ec49b911b2011003d2cff50-1 streamId=1
node_core_logger.js:27
5/25/2020 17:14:12 88158 [INFO] [rtmp publish] avc sequence header
node_core_logger.js:27
Buffer(31) [23, 0, 0, 0, 0, 1, 100, 0, …]
node_core_logger.js:27
5/25/2020 17:14:12 88158 [INFO] [rtmp publish] Handle video. id=N73B3JBJ streamPath=/live/5ec49b911b2011003d2cff50-1 frame_type=1 codec_id=7 codec_name=H264 0x0
node_core_logger.js:27
5/25/2020 17:14:12 88158 [INFO] [rtmp publish] Handle audio. id=N73B3JBJ streamPath=/live/5ec49b911b2011003d2cff50-1 sound_format=10 sound_type=2 sound_size=1 sound_rate=3 codec_name=AAC 44100 1ch
node_core_logger.js:27
5/25/2020 17:14:13 88158 [INFO] [Transmuxing MP4] /live/5ec49b911b2011003d2cff50-1 to ./myMedia/live/5ec49b911b2011003d2cff50-1/2020-05-25-17-14.mp4
node_core_logger.js:27
5/25/2020 17:14:13 88158 [INFO] ***argv -y,-fflags,nobuffer,-analyzeduration,1000000,-i,rtmp://127.0.0.1:1935/live/5ec49b911b2011003d2cff50-1,-c:v,copy,-c:a,copy,-f,tee,-map,0:a?,-map,0:v?,[movflags=faststart]./myMedia/live/5ec49b911b2011003d2cff50-1/2020-05-25-17-14.mp4|
node_core_logger.js:27
5/25/2020 17:14:13 88158 [INFO] [rtmp connect] id=SEKNNV8K ip=::ffff:127.0.0.1 app=live args={"app":"live","flashVer":"LNX 9,0,124,2","tcUrl":"rtmp://127.0.0.1:1935/live","fpad":false,"capabilities":15,"audioCodecs":4071,"videoCodecs":252,"videoFunction":1}
node_core_logger.js:27
5/25/2020 17:14:13 88158 [INFO] [rtmp play] Join stream. id=SEKNNV8K streamPath=/live/5ec49b911b2011003d2cff50-1  streamId=1 
node_core_logger.js:27
5/25/2020 17:14:16 88158 [INFO] [rtmp connect] id=VHFL0GML ip=::ffff:192.168.1.4 app=live args={"app":"live","flashVer":"LNX 9,0,124,2","swfUrl":"","pageUrl":"","tcUrl":"rtmp://192.168.1.4:1935/live","fpad":false,"capabilities":15,"audioCodecs":4071,"videoCodecs":252,"videoFunction":1}
node_core_logger.js:27
5/25/2020 17:14:16 88158 [INFO] [rtmp play] Join stream. id=VHFL0GML streamPath=/live/5ec49b911b2011003d2cff50-1  streamId=1 
node_core_logger.js:27
5/25/2020 17:14:26 88158 [INFO] [rtmp publish] Close stream. id=N73B3JBJ streamPath=/live/5ec49b911b2011003d2cff50-1 streamId=1
node_core_logger.js:27
5/25/2020 17:14:26 88158 [INFO] [rtmp disconnect] id=N73B3JBJ
node_core_logger.js:27
File myMedia/live/5ec49b911b2011003d2cff50-1/2020-05-25-17-14.mp4 has been added
app.js:76
5/25/2020 17:14:53 88158 [INFO] [rtmp play] Close stream. id=VHFL0GML streamPath=/live/5ec49b911b2011003d2cff50-1 streamId=1
node_core_logger.js:27
5/25/2020 17:14:53 88158 [INFO] [rtmp disconnect] id=VHFL0GML
node_core_logger.js:27
5/25/2020 17:14:53 88158 [INFO] [rtmp play] Close stream. id=SEKNNV8K streamPath=/live/5ec49b911b2011003d2cff50-1 streamId=1
node_core_logger.js:27
5/25/2020 17:14:53 88158 [INFO] [rtmp disconnect] id=SEKNNV8K
node_core_logger.js:27
5/25/2020 17:14:53 88158 [INFO] [Transmuxing end] /live/5ec49b911b2011003d2cff50-1
RupamShaw commented 4 years ago

@illuspas please let me know why http://localhost:8000/api/streams :output stream in this width and height 0

using ffmpeg version: 4.2-tessus from //'./node_modules/ffmpeg-static/bin/darwin/x64/ffmpeg'

I need mp4 HD(1920x1080) but getting 360640 if i set here its by default "-c:v" : "copy" thats why i think neglecting scale 19201080

   vcParam: ['-vf', "'scale=1920:-1'", '-b:v', '14000k', '-preset', 'fast', '-profile:v', 'baseline', '-bufsize', '7500k'],

if I set below

   {
        app: "hls_720p",
        mp4: true,
        mp4Flags: "[movflags=faststart]",
        hls: true,
        ac: "aac",
        acParam: ["-b:a", "128k", "-ar", 48000],
        vcParam: [
          "-c:v",
          "libx264",
          "-vf",
          "scale=1280:-1",
          "-b:v",
          "2800k",
          "-bufsize",
          "4200k",
          "-preset",
          "fast",
        ],

then mp4 audio works but video black and achieve dimensions of video 1280x720 but black. Please let me know right config @illuspas