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.91k stars 1.51k forks source link

How do I can change stream's resolution in real time? #477

Closed pavel-vorobyev closed 2 years ago

pavel-vorobyev commented 2 years ago

This my config:

module.exports = {
  logType: 3,
  rtmp: {
    port: 1935,
    chunk_size: 60000,
    gop_cache: false,
    ping: 30,
    ping_timeout: 60,
  },
  http: {
    port: 8000,
    allow_origin: '*',
    mediaroot: '/DIRECT/PATH/rmtp-server/media'
  },
  trans: {
    ffmpeg: /DIRECT/PATH/rmtp-server/ffmpeg',
    tasks: [
      {
        app: 'live',
        ac: 'aac',
        vc: 'libx264',
        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]'
      }
    ]
  }
}

This is my client implementation. I'm using his.js

<div>
    <video id="video" muted="muted" autoplay></video>
</div>

import Hls from 'hls.js'

const video = document.getElementById('video') as HTMLVideoElement
const videoSrc = 'http://localhost:8000/live/qqq/index.m3u8'

if (Hls.isSupported()) {
    const hls = new Hls()
    hls.loadSource(videoSrc)
    hls.attachMedia(video)
    hls.startLoad()
}

How do I can implement stream resolution changing? What I need to do on the client and on the server sides to get it done? Thanks in advance.

pavel-vorobyev commented 2 years ago

I checked the documentation carefully and found this. That's the key :)