HOW-TO:Modify the video cache: Difference between revisions

From Official Kodi Wiki
Jump to navigation Jump to search
m (Text replacement - "userdata folder" to "userdata folder")
 
(129 intermediate revisions by 13 users not shown)
Line 1: Line 1:
{{Gotham}}
{{mininav| [[advancedsettings.xml]] {{l2| [[Video library]] }} }}
This page describes '''three [[advancedsettings.xml]] settings''' that can be used to maximize the cache that XBMC uses. You can use all or just a couple of these settings to see significant improvements in cache performance, should you require it. Most users will not require any changes in settings and can just use the defaults that XBMC comes with.
<section begin="intro" />This page describes '''three [[advancedsettings.xml]] settings''' that can be used to maximize the video playback cache. You can use all or just a couple of these settings to see significant improvements in cache performance, should you require it ''(most users will not require these modifications)''. This can help with intermittent network issues, buffering, reduce how long the network is tied up, and sometimes improve battery life.<section end="intro" />


__TOC__
==What is the video cache==
During playback from internet sources, XBMC will cache the video in RAM for a little bit. If the data rate of the video file is too slow for live playback, XBMC will pause until it can fill the cache enough so that it won't need to pause anymore. Sometimes XBMC doesn't have enough RAM and will give a "cache full" error message. XBMC has various advanced settings that can be used to tweak this behavior.


===What this guide won't do===
{{note|Even if you change the cache settings in Kodi, that won't change how fast the video file data comes in over the network. For example, it won't make a slow server load the video any faster.}}
Even if you change the cache settings in XBMC, that won't change how fast the video file data comes in over the network:
*It won't make a slow server load the video any faster.
*It won't fix a slow local network.


===What this guide will do===
*Often the problem isn't that the network/server is consistently slow, but rather that there are dips in network/server performance. Filling the cache, even when XBMC doesn't think it's needed at the time, will help smooth out performance. Hopefully to the point where the video never has to pause in order to playback the entire file. When using wifi this can also mean filling the cache up before potential intermittent wifi interference, which can happen unpredictably.


*Increasing the rate and size of the cache can also reduce network congestion. On a healthy 100meg LAN, a TV episode can often load in seconds, and then leave the network's full bandwidth to other tasks.
== Steps ==
If you don't already have an [[advancedsettings.xml]] file, it's very simple to make. Kodi uses this file for advanced settings and features that normal users shouldn't modify without first knowing what they do, as well as for experimental features, etc.


*Battery life can also be increased on devices in at least two situations by modifying these cache settings:
{{how-to
*#First is a situation on certain devices that sustained slow/medium-wifi usage, over the length of the video will use more power than using fast-wifi usage for a shorter time. In other words, slowly loading a video file that is 30 minutes long, over a period of 30 minutes, can actually take more power than loading a 30 minute video in 5 minutes, even though more wifi speed/power is used during the 5 minutes.
| Step1 = Since you can use all or just some of the following settings, let's start out with the basic file. Create a '''plain text file''' (no rich text formatting, don't use .doc, etc) and save it as '''advancedsettings.xml'''. Make sure that the file extension is ".xml" and {{color|red|'''not'''}} ".txt" or ".xml.txt".
*#Second is a situation that by keeping the cache in RAM (which requires a lot of RAM for this to work), but increasing the size and fill-rate, so that sustained mechanical hard drive use is decreased. In this case the cache is being used even though all the files are local, and no network is being used at all. However, a more advisable solution might be to use a solid state hard drive.


==How-to modify the cache==
| Step2 = Cut and paste this into your new plain text file:
If you don't already have an [[advancedsettings.xml]] file, it's very simple to make. XBMC uses this file for advanced settings and features that normal users shouldn't modify without first knowing what they do, as well as for experimental features, etc.
:<syntaxhighlight lang="xml" enclose="div">
 
# Since you can use all or just some of the following settings, let's start out with the basic file. Create a '''plain text file''' (no rich text formatting, don't use .doc, etc) and save it as '''advancedsettings.xml'''. Make sure that the file extension is ".xml" and '''not''' ".txt" or ".xml.txt".
# The basic '''advancedsettings.xml''' file will look like this:
#:<syntaxhighlight lang="xml" enclose="div">
<advancedsettings>
<advancedsettings>
    <network>
  <cache>
          <!--- The three settings will go in this space, between the two network tags. --->
    <!--- The three settings will go in this space, between the two cache tags. --->
    </network>
  </cache>
</advancedsettings>
</advancedsettings>
</syntaxhighlight>
</syntaxhighlight>
# Save this file in your '''[[userdata folder]]'''.
#:''If you have an existing file, make sure the <network></network> tags, and settings we'll add between them, are between the main <advancedsettings></advancedsettings> tags:''
#:{{#lst:userdata|location all}}


===Enable cache for local videos===
| Step3 = Add some or all of the settings tags from the '''[[#Cache settings|next section]]'''.
{| class="wikitable"
 
| Step4 = Save this file in your [[Userdata|userdata folder]]:
{{note|If you have an existing file, make sure the <code><cache></cache></code> tags, and settings we'll add between them, are between the main <code><advancedsettings></advancedsettings></code> tags.}}
::{{#lst:userdata|location all}}
}}
 
==Cache settings==
{| class="prettytable"
! advancedsettings.xml tag !! what it does
! advancedsettings.xml tag !! what it does
|-
|-
| <syntaxhighlight lang="xml" enclose="div">
| <code><buffermode>'''1'''</buffermode></code>
          <alwaysforcebuffer>1</alwaysforcebuffer>
 
</syntaxhighlight>
| {{big|'''Choose what to buffer'''}}
||  
 
This setting will force XBMC to use a cache for all video files, including local network, internet, and even the local hard drive. We do this because by default XBMC will only cache videos that use internet file paths/sources.
This setting will force Kodi to use a cache for all video files, including local network, internet, and even the local hard drive. Default value is 0 and will only cache videos that use internet file paths/sources.
 
{| class="datatable"
|-
| 0 || Buffer all internet filesystems (like "2" but additionally also ftp, webdav, etc.) (default)
|-
| 1 || Buffer all filesystems, both internet and local
|-
| 2 || Only buffer true internet filesystems (streams) (http, etc.)
|-
| 3 || No buffer
|-
| 4 || All network filesystems (incl. smb, nfs, etc.)
|}
|}
|-
| <code><memorysize>'''20971520'''</memorysize></code>
| {{big|'''Increasing the cache'''}}


===Increasing the cache===
{| class="wikitable"
! advancedsettings.xml tag !! what it does
|-
| <syntaxhighlight lang="xml" enclose="div">
          <cachemembuffersize>0</cachemembuffersize>
</syntaxhighlight>
||
Here we can do two things:
Here we can do two things:
* '''{{Big|Value: 5242880}} -''' keep the cache in RAM, but increase how much RAM is used. The number is the buffer size in bytes ''(5242880 is the default, which is about 5MB, which requires 15MB of free RAM)''. XBMC will not buffer ahead more than this. {{highlight|color=white|bordered=yes|'''{{color|red|WARNING:}}''' for the memory size set here, XBMC will require 3x the amount of RAM to be free. Setting this too high might cause XBMC to crash if it can't get enough RAM.}}
* {{Big|'''Value: 20971520''' ''(or any value, in bytes)''}} '''-''' keep the cache in RAM, but increase how much RAM is used. The number is the buffer size in bytes ''(20971520 is the default, which is 20MB, which requires 60MB of free RAM)''. Kodi will not buffer ahead more than this. {{Note|For the memory size set here, Kodi will require 3x the amount of RAM to be free. Setting this too high might cause Kodi to crash if it can't get enough RAM.}}
''or''
'''''or'''''
* '''{{Big|Value: 0}} -''' we can use the local disk memory (typically your hard drive), which will not put any limit on the size (outside of the size of your drive).  This also allows devices with low RAM, such as the [[Raspberry Pi]], to cache more than they normally would due to the small amount of RAM they have. {{note|The cache is reset whenever a video is stopped, so you don't have to worry about needing to manually clear it out.}}
* '''{{Big|Value: 0}} -''' we can use the local disk memory (typically your hard drive), which will not put any limit on the size (outside of the size of your drive).  This also allows devices with low RAM, such as the [[Raspberry Pi]], to cache more than they normally would due to the small amount of RAM they have. The cache is deleted from the local disk whenever playback is stopped. {{note|This will likely cause increased wear-and-tear on your drive.}}
|}
 


===Increase the fill-rate of the cache===
:{{note|Do not use the 0 (zero) setting if you have a device with a low amount of local storage, such as 8GB on a Fire TV. As a general rule of thumb, only use this setting if you have at least 16 GB of local drive space that is currently free on the device. Otherwise, Kodi will stall and stop playing the video, or might even crash.}}
{| class="wikitable"
! advancedsettings.xml tag !! what it does
|-
|-
| <syntaxhighlight lang="xml" enclose="div">
| <code><readfactor>'''10'''</readfactor></code>
          <readbufferfactor>5.0</readbufferfactor>
 
</syntaxhighlight>
| {{big|'''Increase the fill-rate of the cache'''}}
||
 
By default '''(value: 1)''', XBMC will only fill the cache a little above what is needed to play it back. It does this as to not max out your network and possibly max out some hardware. For most users and hardware, this setting shouldn't cause any issues, but be aware of it if you have unusual CPU spikes in your HTPC.  
By default '''(value: 4)''', Kodi will only fill the cache a little above what is needed to play it back. It does this as to not max out your network and possibly max out some hardware. For most users and hardware, this setting shouldn't cause any issues, but be aware of it if you have unusual CPU spikes in your HTPC.  




The value of this setting is a multiplier of the default rate. If XBMC is loading a typical bluray raw file at 36 Mbit/s, then a value of '''2''' will need at least 72 Mbit/s of network bandwidth. However, unlike with the RAM setting, you can safely increase this value however high you want, and XBMC won't crash. Just know that it might cause XBMC to attempt to use all available bandwidth on your HTPC during playback.
The value of this setting is a multiplier of the default limit. If Kodi is loading a typical bluray raw file at 36 Mbit/s, then a value of '''2''' will need at least 72 Mbit/s of network bandwidth. However, unlike with the RAM setting, you can safely increase this value however high you want, and Kodi won't crash. Just know that it might cause Kodi to attempt to use all available bandwidth on your HTPC during playback.
|}
|}
== Kodi v17 changes ==
In Kodi v17, the cache-related tags were removed from <code><network></code> and placed under a '''new''' <code><cache></code> tag. In addition, the following tags were renamed:
* <code><cachemembuffersize></code> was renamed to <code><memorysize></code>
* <code><readbufferfactor></code> is renamed to <code><readfactor></code>


==Examples==
==Examples==
{{Notice|These are just examples to explain how the feature works. '''Most users will just want to use example 4'''.}}
===Example 1===
All three options enabled, using local hard drive for cache.
{{warning|Do not use this for flash-based memory devices.}}
;advancedsettings.xml
<syntaxhighlight lang="xml" enclose="div">
<advancedsettings>
  <cache>
    <buffermode>1</buffermode>
    <memorysize>0</memorysize>
    <readfactor>30</readfactor>
  </cache>
</advancedsettings>
</syntaxhighlight>
===Example 2===
Only cache size changed, using 100MB of RAM for cache (which requires 300MB of free RAM).
;advancedsettings.xml
<syntaxhighlight lang="xml" enclose="div">
<advancedsettings>
  <cache>
    <memorysize>104857600</memorysize>
  </cache>
</advancedsettings>
</syntaxhighlight>
===Example 3===
Two options enabled, using 50MB of RAM for cache (which requires 150MB of free RAM), and cache both internet, LAN, and local content.
;advancedsettings.xml
<syntaxhighlight lang="xml" enclose="div">
<advancedsettings>
  <cache>
    <buffermode>1</buffermode>
    <memorysize>52428800</memorysize>
  </cache>
</advancedsettings>
</syntaxhighlight>
=== Example 4 ===
A safe setting for most devices with 1GB of RAM that should help most users "on the edge". All protocols get cached, cache rate fills up pretty much as fast as possible, and cache size is about 133MB, using about 400MB of ram total.
;advancedsettings.xml
<syntaxhighlight lang="xml" enclose="div">
<advancedsettings>
  <cache>
    <buffermode>1</buffermode>
    <memorysize>139460608</memorysize>
    <readfactor>20</readfactor>
  </cache>
</advancedsettings>
</syntaxhighlight>
== See also ==
* [[Caches explained]]


{{Updated|18}}


[[Category:Advanced topics]]
[[Category:Advanced topics]]
[[Category:How-to]]
[[Category:How-to]]
[[Category:Video Library]]
[[Category:Video library]]

Latest revision as of 10:19, 19 July 2020

Home icon grey.png   ▶ advancedsettings.xml
▶ Video library
▶ HOW-TO:Modify the video cache

This page describes three advancedsettings.xml settings that can be used to maximize the video playback cache. You can use all or just a couple of these settings to see significant improvements in cache performance, should you require it (most users will not require these modifications). This can help with intermittent network issues, buffering, reduce how long the network is tied up, and sometimes improve battery life.


Note: Even if you change the cache settings in Kodi, that won't change how fast the video file data comes in over the network. For example, it won't make a slow server load the video any faster.


Steps

If you don't already have an advancedsettings.xml file, it's very simple to make. Kodi uses this file for advanced settings and features that normal users shouldn't modify without first knowing what they do, as well as for experimental features, etc.

1 Since you can use all or just some of the following settings, let's start out with the basic file. Create a plain text file (no rich text formatting, don't use .doc, etc) and save it as advancedsettings.xml. Make sure that the file extension is ".xml" and not ".txt" or ".xml.txt".
2 Cut and paste this into your new plain text file:
<advancedsettings>
  <cache>
    <!--- The three settings will go in this space, between the two cache tags. --->
  </cache>
</advancedsettings>
3 Add some or all of the settings tags from the next section.
4 Save this file in your userdata folder:

Note: If you have an existing file, make sure the <cache></cache> tags, and settings we'll add between them, are between the main <advancedsettings></advancedsettings> tags.

The Userdata folder is a subfolder of the Kodi Data Folder and is located as shown in the table below.

Operating system Userdata Folder
Android Android/data/org.xbmc.kodi/files/.kodi/userdata/ (see note)
iOS /private/var/mobile/Library/Preferences/Kodi/userdata/
LibreELEC /storage/.kodi/userdata/
Linux ~/.kodi/userdata/
macOS /Users/<your_user_name>/Library/Application Support/Kodi/userdata/
Nvidia Shield (SMB) smb://<nvidiashieldurl>/internal/Android/data/org.xbmc.kodi/files/.kodi/userdata
OSMC /home/osmc/.kodi/userdata/
tvOS /private/var/mobile/Library/Preferences/Kodi/userdata/
webOS /media/developer/apps/usr/palm/applications/org.xbmc.kodi/.kodi/userdata/
Windows %APPDATA%\Kodi\userdata
Windows Portable <Install location chosen by you>\portable_data\userdata\
Windows via Microsoft Store %LOCALAPPDATA%\Packages\XBMCFoundation.Kodi_4n2hpmxwrvr6p\LocalCache\Roaming\Kodi\
Windows Xbox %LOCALAPPDATA%\Packages\XBMCFoundation.Kodi_4n2hpmxwrvr6p\LocalCache\Roaming\Kodi\
Note: In some Android setups the path may be slightly different to the one stated above.


Cache settings

advancedsettings.xml tag what it does
<buffermode>1</buffermode> Choose what to buffer

This setting will force Kodi to use a cache for all video files, including local network, internet, and even the local hard drive. Default value is 0 and will only cache videos that use internet file paths/sources.

0 Buffer all internet filesystems (like "2" but additionally also ftp, webdav, etc.) (default)
1 Buffer all filesystems, both internet and local
2 Only buffer true internet filesystems (streams) (http, etc.)
3 No buffer
4 All network filesystems (incl. smb, nfs, etc.)
<memorysize>20971520</memorysize> Increasing the cache

Here we can do two things:

  • Value: 20971520 (or any value, in bytes) - keep the cache in RAM, but increase how much RAM is used. The number is the buffer size in bytes (20971520 is the default, which is 20MB, which requires 60MB of free RAM). Kodi will not buffer ahead more than this. Note: For the memory size set here, Kodi will require 3x the amount of RAM to be free. Setting this too high might cause Kodi to crash if it can't get enough RAM.

or

  • Value: 0 - we can use the local disk memory (typically your hard drive), which will not put any limit on the size (outside of the size of your drive). This also allows devices with low RAM, such as the Raspberry Pi, to cache more than they normally would due to the small amount of RAM they have. The cache is deleted from the local disk whenever playback is stopped. Note: This will likely cause increased wear-and-tear on your drive.


Note: Do not use the 0 (zero) setting if you have a device with a low amount of local storage, such as 8GB on a Fire TV. As a general rule of thumb, only use this setting if you have at least 16 GB of local drive space that is currently free on the device. Otherwise, Kodi will stall and stop playing the video, or might even crash.
<readfactor>10</readfactor> Increase the fill-rate of the cache

By default (value: 4), Kodi will only fill the cache a little above what is needed to play it back. It does this as to not max out your network and possibly max out some hardware. For most users and hardware, this setting shouldn't cause any issues, but be aware of it if you have unusual CPU spikes in your HTPC.


The value of this setting is a multiplier of the default limit. If Kodi is loading a typical bluray raw file at 36 Mbit/s, then a value of 2 will need at least 72 Mbit/s of network bandwidth. However, unlike with the RAM setting, you can safely increase this value however high you want, and Kodi won't crash. Just know that it might cause Kodi to attempt to use all available bandwidth on your HTPC during playback.

Kodi v17 changes

In Kodi v17, the cache-related tags were removed from <network> and placed under a new <cache> tag. In addition, the following tags were renamed:

  • <cachemembuffersize> was renamed to <memorysize>
  • <readbufferfactor> is renamed to <readfactor>

Examples

Emblem-important-yellow.png NOTICE:
These are just examples to explain how the feature works. Most users will just want to use example 4.


Example 1

All three options enabled, using local hard drive for cache.

Stop hand.png Do not use this for flash-based memory devices.
advancedsettings.xml
<advancedsettings>
  <cache>
    <buffermode>1</buffermode>
    <memorysize>0</memorysize>
    <readfactor>30</readfactor>
  </cache>
</advancedsettings>

Example 2

Only cache size changed, using 100MB of RAM for cache (which requires 300MB of free RAM).

advancedsettings.xml
<advancedsettings>
  <cache>
    <memorysize>104857600</memorysize>
  </cache>
</advancedsettings>

Example 3

Two options enabled, using 50MB of RAM for cache (which requires 150MB of free RAM), and cache both internet, LAN, and local content.

advancedsettings.xml
<advancedsettings>
  <cache>
    <buffermode>1</buffermode>
    <memorysize>52428800</memorysize>
  </cache>
</advancedsettings>

Example 4

A safe setting for most devices with 1GB of RAM that should help most users "on the edge". All protocols get cached, cache rate fills up pretty much as fast as possible, and cache size is about 133MB, using about 400MB of ram total.

advancedsettings.xml
<advancedsettings>
  <cache>
    <buffermode>1</buffermode>
    <memorysize>139460608</memorysize>
    <readfactor>20</readfactor>
  </cache>
</advancedsettings>

See also