# Hi! Is there any way to decrease latency before we can stream a video?

**URL:** <https://mediasoup.discourse.group/t/hi-is-there-any-way-to-decrease-latency-before-we-can-stream-a-video/2840>\
**Category:** mediasoup libraries\
**Created:** [May 27, 2021, 6:17am UTC](https://mediasoup.discourse.group/t/hi-is-there-any-way-to-decrease-latency-before-we-can-stream-a-video/2840 "2021-05-27T06:17:06Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![kmescharikov](https://yyz2.discourse-cdn.com/free1/user_avatar/mediasoup.discourse.group/kmescharikov/32/1006_2.png) [@kmescharikov](https://mediasoup.discourse.group/u/kmescharikov)\
**Post date:** [May 27, 2021, 6:17am UTC](https://mediasoup.discourse.group/t/hi-is-there-any-way-to-decrease-latency-before-we-can-stream-a-video/2840/1 "2021-05-27T06:17:06Z")

</div>

I mean I now have a latency of about 500-1000ms every time I watch my stream from a new device / browser tab. So what if I define multiple transports / consumers ahead of time to avoid this problem? How is it generally accepted to solve such problems?

---

<div class="post-metadata">

**Author:** ![nazar-pc](https://yyz2.discourse-cdn.com/free1/user_avatar/mediasoup.discourse.group/nazar-pc/32/369_2.png) [@nazar-pc](https://mediasoup.discourse.group/u/nazar-pc)\
**Post date:** [May 27, 2021, 11:02am UTC](https://mediasoup.discourse.group/t/hi-is-there-any-way-to-decrease-latency-before-we-can-stream-a-video/2840/2 "2021-05-27T11:02:49Z")

</div>

This is unreasonably large latency, never seen anything like that with mediasoup, even remotely. There must be something with you app or networking, but impossible to tell from such description.

---

<div class="post-metadata">

**Author:** ![kmescharikov](https://yyz2.discourse-cdn.com/free1/user_avatar/mediasoup.discourse.group/kmescharikov/32/1006_2.png) [@kmescharikov](https://mediasoup.discourse.group/u/kmescharikov)\
**Post date:** [May 28, 2021, 3:10am UTC](https://mediasoup.discourse.group/t/hi-is-there-any-way-to-decrease-latency-before-we-can-stream-a-video/2840/3 "2021-05-28T03:10:21Z")

</div>

Please let me know what information you might find useful?  
Now I can say that I am not doing anything unusual, I have a meteor application on the client, and a backend on node.js. Both are in different docker containers. Communication between them follows the instructions from here: [mediasoup :: Communication Between Client and Server](https://mediasoup.org/documentation/v3/communication-between-client-and-server/)  
I assume that the delay occurs in the mediasoup or due to the network due to the fact that the black screen disappears during the connection to the broadcast after the call to the webrts.connect() and the call to the consumer.resume()

---

<div class="post-metadata">

**Author:** ![nazar-pc](https://yyz2.discourse-cdn.com/free1/user_avatar/mediasoup.discourse.group/nazar-pc/32/369_2.png) [@nazar-pc](https://mediasoup.discourse.group/u/nazar-pc)\
**Post date:** [May 28, 2021, 7:17am UTC](https://mediasoup.discourse.group/t/hi-is-there-any-way-to-decrease-latency-before-we-can-stream-a-video/2840/4 "2021-05-28T07:17:40Z")

</div>

How do you measure delay? Did you already check `about:webrtc` (Firefox) or `chrome://webrtc-internals` (Chromium)?

---

<div class="post-metadata">

**Author:** ![kmescharikov](https://yyz2.discourse-cdn.com/free1/user_avatar/mediasoup.discourse.group/kmescharikov/32/1006_2.png) [@kmescharikov](https://mediasoup.discourse.group/u/kmescharikov)\
**Post date:** [May 28, 2021, 7:19am UTC](https://mediasoup.discourse.group/t/hi-is-there-any-way-to-decrease-latency-before-we-can-stream-a-video/2840/5 "2021-05-28T07:19:46Z")

</div>

By latency I mean the time from the socket connection establishment with the server to the time the broadcast starts, now I do this using the console directives. Time inside my nodejs application

---

<div class="post-metadata">

**Author:** ![nazar-pc](https://yyz2.discourse-cdn.com/free1/user_avatar/mediasoup.discourse.group/nazar-pc/32/369_2.png) [@nazar-pc](https://mediasoup.discourse.group/u/nazar-pc)\
**Post date:** [May 28, 2021, 7:21am UTC](https://mediasoup.discourse.group/t/hi-is-there-any-way-to-decrease-latency-before-we-can-stream-a-video/2840/6 "2021-05-28T07:21:25Z")

</div>

This is not the kind of latency people usually talk about when they talk about latency in RTC.

I guess you’ll have to profile what is happening and where it spends most of the time.

---

<div class="post-metadata">

**Author:** ![kmescharikov](https://yyz2.discourse-cdn.com/free1/user_avatar/mediasoup.discourse.group/kmescharikov/32/1006_2.png) [@kmescharikov](https://mediasoup.discourse.group/u/kmescharikov)\
**Post date:** [May 28, 2021, 7:23am UTC](https://mediasoup.discourse.group/t/hi-is-there-any-way-to-decrease-latency-before-we-can-stream-a-video/2840/7 "2021-05-28T07:23:29Z")

</div>

> **[: The Video Embed element - HTML: HyperText Markup Language | MDN](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/video)**
>
> The HTML Video element () embeds a media player which supports video playback into the document. You can use for audio content as well, but the element may provide a more appropriate user experience.

If I say that the “delay” for me also manifests itself in how long the poster from the “poster” attribute is shown before the broadcast starts, will that change your opinion?

---

<div class="post-metadata">

**Author:** ![ibc](https://yyz2.discourse-cdn.com/free1/user_avatar/mediasoup.discourse.group/ibc/32/1540_2.png) [@ibc](https://mediasoup.discourse.group/u/ibc)\
**Post date:** [May 28, 2021, 7:34am UTC](https://mediasoup.discourse.group/t/hi-is-there-any-way-to-decrease-latency-before-we-can-stream-a-video/2840/8 "2021-05-28T07:34:50Z")

</div>

You are not talking about latency but about setup time, which depends on many factors (including your app code/flow/logic).

---

<div class="post-metadata">

**Author:** ![kmescharikov](https://yyz2.discourse-cdn.com/free1/user_avatar/mediasoup.discourse.group/kmescharikov/32/1006_2.png) [@kmescharikov](https://mediasoup.discourse.group/u/kmescharikov)\
**Post date:** [May 28, 2021, 7:36am UTC](https://mediasoup.discourse.group/t/hi-is-there-any-way-to-decrease-latency-before-we-can-stream-a-video/2840/9 "2021-05-28T07:36:55Z")

</div>

Pls, don’t close the issue, i’ll profile my app with nsolid, then coming back with explained solution or more questions.

---

<div class="post-metadata">

**Author:** ![kmescharikov](https://yyz2.discourse-cdn.com/free1/user_avatar/mediasoup.discourse.group/kmescharikov/32/1006_2.png) [@kmescharikov](https://mediasoup.discourse.group/u/kmescharikov)\
**Post date:** [May 28, 2021, 7:53am UTC](https://mediasoup.discourse.group/t/hi-is-there-any-way-to-decrease-latency-before-we-can-stream-a-video/2840/10 "2021-05-28T07:53:24Z")

</div>

Also can i ask you about “normal” time of setup time? 100ms ? 200ms?

---

<div class="post-metadata">

**Author:** ![kmescharikov](https://yyz2.discourse-cdn.com/free1/user_avatar/mediasoup.discourse.group/kmescharikov/32/1006_2.png) [@kmescharikov](https://mediasoup.discourse.group/u/kmescharikov)\
**Post date:** [May 31, 2021, 7:42am UTC](https://mediasoup.discourse.group/t/hi-is-there-any-way-to-decrease-latency-before-we-can-stream-a-video/2840/11 "2021-05-31T07:42:34Z")

</div>

Hi! Can i ask you what is normal latency value? 100ms? 200ms?

---

<div class="post-metadata">

**Author:** ![savsoft](https://avatars.discourse-cdn.com/v4/letter/s/3d9bf3/32.png) [@savsoft](https://mediasoup.discourse.group/u/savsoft)\
**Post date:** [June 1, 2021, 6:19am UTC](https://mediasoup.discourse.group/t/hi-is-there-any-way-to-decrease-latency-before-we-can-stream-a-video/2840/12 "2021-06-01T06:19:23Z")

</div>

Latency from starting point (where you are producing stream) to end point (where you are consuming) is normally 500ms. ( Webrtc is ultra low latency protocol approx. 500 milliseconds)  
If you are talking about stream initialize time, then it depends upon many factors.  
Like Web camera response time when you ask for video stream + creating connection with mediasoup server (signaling server) + creating transports, adding tracks…

---

<div class="post-metadata">

**Author:** ![BronzedBroth](https://avatars.discourse-cdn.com/v4/letter/b/ad7895/32.png) [@BronzedBroth](https://mediasoup.discourse.group/u/BronzedBroth)\
**Post date:** [June 1, 2021, 7:08am UTC](https://mediasoup.discourse.group/t/hi-is-there-any-way-to-decrease-latency-before-we-can-stream-a-video/2840/13 "2021-06-01T07:08:57Z")

</div>

![2021-06-01 03-06-36](https://global.discourse-cdn.com/free1/uploads/mediasoup/original/2X/8/8a9030cdaa8baac3cdbc949f911f1f193868bae9.gif)

You tell me?

My chat-servers send a message via LAN to broker server then will instruct media servers around the world. Would love to say based off pinging the server anywhere from 20ms to 250ms? For initial boot-up.

---

<div class="post-metadata">

**Author:** ![kmescharikov](https://yyz2.discourse-cdn.com/free1/user_avatar/mediasoup.discourse.group/kmescharikov/32/1006_2.png) [@kmescharikov](https://mediasoup.discourse.group/u/kmescharikov)\
**Post date:** [June 1, 2021, 9:32am UTC](https://mediasoup.discourse.group/t/hi-is-there-any-way-to-decrease-latency-before-we-can-stream-a-video/2840/14 "2021-06-01T09:32:54Z")

</div>

It’s just that the guy who created this repository [GitHub - michaelfig/mediasoup-broadcast-example: Mediasoup WebRTC vanilla JS broadcast example.](https://github.com/michaelfig/mediasoup-broadcast-example) doesn’t have this delay. I can start streaming from my webcam and then open 10 tabs as a subscriber, and when I hit the subscribe button I don’t see a millisecond of delay before I see the broadcast. But in my application, unfortunately, this is not the case, and I cannot understand what is the matter, since profiling gave no results. Also you are right i mean stream initalize time, but I don’t understand why this installation delay is not in the example that I posted above

---

<div class="post-metadata">

**Author:** ![kmescharikov](https://yyz2.discourse-cdn.com/free1/user_avatar/mediasoup.discourse.group/kmescharikov/32/1006_2.png) [@kmescharikov](https://mediasoup.discourse.group/u/kmescharikov)\
**Post date:** [June 1, 2021, 9:33am UTC](https://mediasoup.discourse.group/t/hi-is-there-any-way-to-decrease-latency-before-we-can-stream-a-video/2840/15 "2021-06-01T09:33:36Z")

</div>

I didn’t quite understand what you mean

---

<div class="post-metadata">

**Author:** ![savsoft](https://avatars.discourse-cdn.com/v4/letter/s/3d9bf3/32.png) [@savsoft](https://mediasoup.discourse.group/u/savsoft)\
**Post date:** [June 1, 2021, 9:41am UTC](https://mediasoup.discourse.group/t/hi-is-there-any-way-to-decrease-latency-before-we-can-stream-a-video/2840/16 "2021-06-01T09:41:49Z")

</div>

Can you share your application url?

---

<div class="post-metadata">

**Author:** ![savsoft](https://avatars.discourse-cdn.com/v4/letter/s/3d9bf3/32.png) [@savsoft](https://mediasoup.discourse.group/u/savsoft)\
**Post date:** [June 1, 2021, 10:00am UTC](https://mediasoup.discourse.group/t/hi-is-there-any-way-to-decrease-latency-before-we-can-stream-a-video/2840/17 "2021-06-01T10:00:29Z")

</div>

Broadcast demo and your application using same kind of server (configuration, server location, inbound and outbound network)?

---

<div class="post-metadata">

**Author:** ![kmescharikov](https://yyz2.discourse-cdn.com/free1/user_avatar/mediasoup.discourse.group/kmescharikov/32/1006_2.png) [@kmescharikov](https://mediasoup.discourse.group/u/kmescharikov)\
**Post date:** [June 7, 2021, 6:51am UTC](https://mediasoup.discourse.group/t/hi-is-there-any-way-to-decrease-latency-before-we-can-stream-a-video/2840/18 "2021-06-07T06:51:42Z")

</div>

Can I write to you in pm?

---

<div class="post-metadata">

**Author:** ![savsoft](https://avatars.discourse-cdn.com/v4/letter/s/3d9bf3/32.png) [@savsoft](https://mediasoup.discourse.group/u/savsoft)\
**Post date:** [June 7, 2021, 8:22am UTC](https://mediasoup.discourse.group/t/hi-is-there-any-way-to-decrease-latency-before-we-can-stream-a-video/2840/19 "2021-06-07T08:22:40Z")

</div>

Yes, you can send…

---

<div class="post-metadata">

**Author:** ![BronzedBroth](https://avatars.discourse-cdn.com/v4/letter/b/ad7895/32.png) [@BronzedBroth](https://mediasoup.discourse.group/u/BronzedBroth)\
**Post date:** [June 7, 2021, 10:17am UTC](https://mediasoup.discourse.group/t/hi-is-there-any-way-to-decrease-latency-before-we-can-stream-a-video/2840/20 "2021-06-07T10:17:05Z")

</div>

It means if your connection is Grade A. You’re left with it being a technical issue in your signalling/media servers. This could be as simple as over-looping, being stuck in a loop, nesting statements when not necessary all sorts can slow this down.

Mediasoup is a bit complicated so I imagine it’s in your routing of messages somewhere. Maybe start applying friendly timers you can remove to give you an idea where you spend the most time calculating. 🙂

[Next page](https://mediasoup.discourse.group/t/hi-is-there-any-way-to-decrease-latency-before-we-can-stream-a-video/2840.md?page=2)
