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

Stuttering HLS audio on iOS devices #570

Open jorbig opened 1 year ago

jorbig commented 1 year ago

The Media Server works fine, except for HLS playback on iOS devices. The sound is constantly stuttering/choppy, while on other devices (even iPads and Macs) everything works normally. Could someone confirm this issue and offer a solution?

hankthetank27 commented 1 year ago

I am having the same issue. I have my front end configured to use Hls.js for non iOS devices, and to use the native <audio/> tag in iOS devices since Safari has native HLS support. Seems to be working fine on all other devices, but getting that same stuttered playback in iOS.

hankthetank27 commented 1 year ago

@jorbig In case you're still having a problem with this, I was able to solve it by using a config similar to the one outlined here: https://github.com/illuspas/Node-Media-Server#remux-to-rtmphlsdash-live-stream-with-audio-transcode.

jorbig commented 1 year ago

@hankthetank27 Thanks for your suggestion, but sadly that doesn't solve it for me. My config is based on that one and uses the latest FFMPEG version, but the playback still stutters on iOS. Maybe it's because I'm using Windows? Maybe @illuspas knows what the problem is?

Here's my config:

const NodeMediaServer = require('node-media-server');

const config = {
  rtmp: {
    port: 1935,
    chunk_size: 60000,
    gop_cache: true,
    ping: 30,
    ping_timeout: 60
  },
  http: {
    port: 8080,
    mediaroot: './media',
    allow_origin: '*'
  },
  trans: {
    ffmpeg: './ffmpeg/ffmpeg.exe',
    tasks: [
      {
        app: 'live',
        vc: "copy",
        vcParam: [],
        ac: "aac",
        acParam: ['-ab', '32k', '-ac', '1', '-ar', '22050'],
        hls: true,
        hlsFlags: '[hls_time=2:hls_list_size=3:hls_flags=delete_segments]',
      }
    ]
  }
};

var nms = new NodeMediaServer(config)
nms.run();
hankthetank27 commented 1 year ago

@jorbig Here is mine if its of any help... Possibly it has something to do with the sampling rate you're using, 22050hz? The Apple developer documentation suggests you use either 44.1khz or 48khz.

export function configNms(ffmpegPath: string){
  const config = {
    rtmp: {
        port: 1935,
        chunk_size: 60000,
        gop_cache: false,
        ping: 30,
        ping_timeout: 60
    },
    http: {
        port: 8000,
        mediaroot: './media',
        allow_origin: '*'
    },
    trans: {
      ffmpeg: ffmpegPath,
      tasks: [
        {
          app: 'live',
          vc: "copy",
          vcParam: [],
          ac: "aac",
          acParam: ['-ab', '64k', '-ac', '1', '-ar', '44100'],
          rtmp:true,
          rtmpApp:'live2',
          hls: true,
          hlsFlags: '[hls_time=3:hls_list_size=4:hls_flags=delete_segments]',
          hlsKeep: false
        }
      ]
    },
    mediaServer: {
      idleTimeout: 120
    }
  };
  return config;
};
jorbig commented 1 year ago

Thanks for your help. This also didn't solve it for me, so I switched to MistServer, which seems to work great so far.