Node-Media-Server icon indicating copy to clipboard operation
Node-Media-Server copied to clipboard

Stuttering HLS audio on iOS devices

Open jorbig opened this issue 1 year ago • 5 comments

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?

jorbig avatar Feb 22 '23 14:02 jorbig

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 avatar Mar 24 '23 20:03 hankthetank27

@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.

hankthetank27 avatar Mar 30 '23 23:03 hankthetank27

@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();

jorbig avatar Apr 01 '23 15:04 jorbig

@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;
};

hankthetank27 avatar Apr 03 '23 14:04 hankthetank27

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

jorbig avatar Apr 04 '23 12:04 jorbig