Jump to content

How to save bandwidth with KVS tube script


Tech Support

Recommended Posts

For a video site most of the bandwidth is being used for serving videos. In many cases you will have a limited channel like 100mbit or 1000mbit, so you will not save any money by saving bandwidth, however there are several cases when saving bandwidth can make great benefit for you:

  1. When your channel is fully loaded with serving videos, your site may become unresponsive for some users and you may get SEO penalty. One solution is to buy a new server or extend bandwidth limit, but you can save this money with KVS by trying to limit video streaming speed.
  2. When you are using CDN, in most cases you pay for the maximum bandwidth peak. You can save some money by paying less if your maximum peak becomes less.

Why limiting streaming speed can save your bandwidth? Many users do not watch videos in full length, they may skip up and down to different fragments. However if their internet speed is high, they can download full video at a max speed shortly even if they didn't watch most of it. With a speed limit you will reduce % of downloaded bandwidth by each user and finally you will get some cut in your global bandwidth usage.

KVS provides 2 way to limit video streaming speed:

  1. Limit speed to fixed bitrate. This is not a good solution, since it can be inaccurate in many cases - since video bitrate is often dynamic and you won't know the exact bitrate to limit.
  2. Limit speed to dynamic bitrate with a multiplier. This option is much better as it will make sure different speed limits for videos of different bitrates and you don't need to investigate the average bitrate of your videos.

However, there is one important issue which you should know about streaming MP4 files. Each MP4 file has a metadata atom in the beginning (MOOV atom). This atom contains keyframes from video file and can take up to 4MB depending on video duration and geometry. Player needs to download this atom before it can start playing videos. Therefore if you limit download speed, your videos will start playing with a big delay. However Nginx provides a way to fix that, we will describe this later.

NOTE: limiting streaming speed is only possible with serving videos with Nginx or CDN. In case of CDN the implementation of speed limit is fully dependent on your CDN provider (BTW some CDNs are not interested in doing this for an obvious reason). KVS will pass speed limit info to the CDN integration script, which may or may not use it - but this is not KVS issue.

 

How to configure download speed limit

In KVS you can configure download speed limit per each video format separately. Go to Settings -> Video formats and for each video format you can set speed limit:

Global speed limit: Dynamic bitrate x 1.2 (we recommend multipliers from 1.1 to 1.5)

You can set other options under Speed limitation section as needed. For example you can give your premium or active members unlimited download speed. You can also limit speed for visitors from certain countries only, so that you main audience is not affected. In order to define list of countries you want to limit please take a look at Stats -> Countries for reference.

video_format_speed_limit.thumb.png.3deda4e0b8202b494d5f3bf844a7b840.png

 

  • Thanks 1
Link to comment
Share on other sites

  • 1 month later...
Guest xvids

Hi KVS Team,

Thanks for the nice tutorial...:cool:

 

I have added the rule in Nginx config limit_rate_after 4m; with 4MB because I think some on website have HD and Full videos

But I'm little bit confuse this line./ as you said (we recommend multipliers from 1.1 to 1.5)

Please suggest me which number is good for HD and Full videos

 

Global speed limit: Dynamic bitrate x 1.2 (we recommend multipliers from 1.1 to 1.5)

Link to comment
Share on other sites

Please suggest me which number is good for HD and Full videos

 

It doesn't matter which video size or duration you have. Normally you should allow bitrate multiplier as 1.0, since you want player to buffer only video fragment which is being playing at the moment. However in many cases bitrate is not constant, it varies for different video fragments. So setting 1.0 will most likely be not accurate and users will experience interruptions in playback. That's why you need to configure value higher than 1.0 to ensure video is buffered little bit faster than it is played.

 

You can test online by putting 1.2 and see how fast the buffer will become longer than played part. If you set 1.5 buffering will be even more faster and you will save less traffic. Basically 1.2 should be enough.

Link to comment
Share on other sites

  • 5 months later...
10 hours ago, Matyko42 said:

I've just heard this limitation can significantly increase the server load.

Nope, never heard of anything like this.

 

10 hours ago, Matyko42 said:

Maybe there should be a 2021 edition of this tutorial - not sure if the 'game' changed That Much though...

Yes, the game changed by HLS adaptive streaming, but KVS still doesn't support that. We will change this article after finalizing HLS support in KVS.

  • Like 2
Link to comment
Share on other sites

  • 3 months later...

Yes limit_rate_after is still required for MP4 files. It doesn't matter if you use dynamic or fixed bitrate. The purpose of using limit_rate_after is to allow metadata of MP4 file being downloaded as quickly as possible, otherwise video playback will be started slowly.

  • Like 2
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...