Video decoding configuration
This guide is intended for installers who want to get maximum performance out of C-Play. See video in the media guide if you want to know how C-Play loads and handles video files.
C-Play has embedded mpv, which is highly capable free and open-source media player. MPV can be configured in many ways to maximize performance based on your system.
The bundled mpv and FFmpeg versions depend on the C-Play build. Check the libraries supplied with your installation when choosing decoder options; older releases and custom builds may support different options.
MPV configuration files
C-Play ships with a bunch of different pre-configured mpv configuration files, located in the data/mpv-conf directory.
If nothing is specified, C-Play will load the configuration in the default folder. It sets "hwdec": "auto-safe": mpv decodes on the GPU with the hardware decoders it considers safe, and falls back to the CPU for files they cannot decode. There are two ways to choose another configuration:
- Startup configuration setting — In Settings > Playback, select a configuration in the Startup configuration list. The list shows every folder in data/mpv-conf that contains an all.json. Selecting a configuration shows its files in the text area below, so you can compare what each configuration sets before restarting. The selection is saved and used the next time C-Play starts. The master also sends it to the nodes at startup, so the whole cluster uses the same configuration without any command-line options. The folder must exist in data/mpv-conf on every computer; a node that does not have it keeps its current configuration and logs a warning.
- Command-line option — Supplying "--mpvconf decoding_gpu_nvdec" loads the configuration files in that folder when C-Play starts. The copy button next to the Startup configuration list copies this option for the selected configuration.
The command-line option always takes priority over the saved startup configuration, and it is handled separately on the master and the nodes:
- A master started with --mpvconf uses that configuration and does not send its saved choice to the nodes.
- A node started with --mpvconf keeps that configuration, even when the master sends its saved choice.
- A node started without --mpvconf uses the configuration the master sends, or default if the master was started with --mpvconf.
The nodes receive the master's choice after their video player has started, and apply it from the next file load. All options in the shipped configurations can be changed this way. An option in your own configuration that mpv only accepts before initialization would not take effect on the nodes; in that case start the nodes with --mpvconf instead.
Each configuration folder can contain up to three different JSON files:
- all.json
- master-only.json
- nodes-only.json
The all.json file should include options you want C-Play to use on both the master and the clients/nodes. Respectively, you can set options only for the master or only for the clients/nodes in the other two files.
The various configurations that C-Play ships with can be found here, for reference.
All the different mpv options can be found here.
CPU vs GPU
As seen in the included configurations, some are named "_gpu" and some are named "_cpu". MPV is a diverse and powerful media player that can take advantage of a high-end CPU system, by defining thread usage in the configuration file, or a high-end GPU by selecting a decoding library of your choice.
It should be noted that GPU decoding libraries are often more limited in terms of supported formats and resolutions.
However, should you load a video file that is not supported by the GPU to be decoded, MPV automatically tries to utilize the CPU to decode it if the GPU says it can't.
Time sync vs Display sync
By default, the MPV playback engine times the video frames to the audio, and then everything is synced against the system clock. If no audio is present, as is usually the case for the nodes, the system clock is also the default method for syncing. Normally you would have a domain NTP (Network Time Protocol) setup so the computers in the cluster do not differ in time by many milliseconds, and the default mode should work fine.
However, as a cluster setup usually requires frame-syncing to avoid tearing, we could ideally use a timer based on the display rate, instead of the system clock for our playback timing.
The MPV configuration named "decoding_gpu_nvdec_video_sync" showcases the settings needed to enable this. As seen in the config, there are two interesting options:
- "video-sync": "display-resample"
This line tells MPV to resample the audio to match the display rate, opposite of the default behaviour.
- "display-fps-override": "59.94"
Usually the nodes are frame-synced, but the master is not. Because of that, we want to tell all instances to use the refresh rate of the synchronized displays, including the master, so the timing between the master and nodes is the same. You could override only on the master and let the nodes use a detected value if desired, but in the included example we override all.
H264 vs H265
For preparing and encoding media for C-Play, use C-Slice. Its encoding guide covers codec, frame-rate, and quality settings; see video preparation for pre-splitting content to match your SGCT setup.
C-Play has been mostly tested with video files encoded with either H264 or H265, as they are very common formats around and well supported by various decoder libraries integrated in MPV.
Pros/cons of H264
H264 has been around for quite some time, but it is still a widely used format. It is fast to encode, takes reasonably little space, and is fast to decode depending on bitrate. Hardware H264 decoders commonly impose resolution limits. A side-by-side stereo file can exceed those limits even when each eye fits: two 3840 × 2160 views produce a 7680 × 2160 frame.
C-Play will load and play this video. However, even if you specified the use of a GPU decoding library such as nvdec, hardware decoding can fail if the file exceeds the GPU decoder's supported dimensions, profile, or level. So C-Play will play it using the CPU decoder, which is not restricted in the same way.
Pros/cons of H265
H265 is a newer format and a premier choice for streaming 4K content and beyond. While it takes longer to encode, it produces higher quality at smaller bitrates and results in smaller files than H264 at the same quality.
However, H265 is much more complex to decode, and you might notice that if you try to play H265 files on the CPU with C-Play, it struggles a bit. However, the structure of H265 makes it much more suitable to be better decoded on the GPU. A capable HEVC GPU decoder can handle a side-by-side 4K-per-eye file (7680 × 2160), but support depends on the GPU, bit depth, chroma format, profile, and driver. Test representative files on your actual playback machines.
Per-file MPV options
In addition to the global MPV configuration folders described above, C-Play can apply extra MPV options to individual layers. This makes it possible to use special decoding settings for a single file (for instance a transparent video) without affecting any other layer.
Option files
Per-file options are defined in JSON files placed directly in the data/mpv-conf directory (next to the global configuration folders, not inside them). The file name determines which layer type the options apply to:
- <name>_video.json — video layers
- <name>_audio.json — audio layers
- <name>_stream.json — stream layers
- <name>_youtube.json — YouTube layers
The <name> part is what identifies the option set in the user interface, so a file named transparent_video.json shows up as transparent for video layers. You can create as many option sets as you need, and the same name can be used with different suffixes to cover several layer types.
Included presets cover transparent video (transparent_video.json), low-latency RTSP (rtsp-tcp-lowlatency_stream.json), and YouTube (youtube_youtube.json). The transparent-video preset is described below. The available files are scanned at runtime, so new files added to data/mpv-conf appear in the UI without restarting.
Selecting options for a layer
Open the layer's view from the master UI. Video and audio layers have a "Video Options" dropdown next to the audio controls at the top of the window, and stream layers have the same dropdown in their stream controls. It lists "Use global settings" (the default) plus every option file found for that layer type.
When an option set is selected, C-Play first applies the global configuration (all.json and master-only.json / nodes-only.json) and then loads the per-file options, so the per-file values take precedence over the global ones. Changing the selection re-applies the options to the layer's already running MPV instance.
The selection is stored as part of the layer, so it is saved in the presentation's .cplaypres file and synced to the nodes in a cluster setup (master and nodes must run the same C-Play version, and the option file must exist in data/mpv-conf on all computers).
Example: transparent videos
C-Play supports playing back transparent videos, which have been tested with both VP9 and HAP formats. This is implemented as the shipped data/mpv-conf/transparent_video.json option file, which contains:
{
"hwdec": "no",
"alpha": "yes",
"vd": "libvpx-vp9,libvpx"
}
To use it, open the Inspect view of the video layer and select transparent in the "Video Options" dropdown.
- "hwdec": "no"
This disables hardware decoding for the layer, since GPU decoders do not support alpha channel output. The video is decoded on the CPU instead.
- "alpha": "yes"
This option tells MPV to enable alpha channel rendering, so the transparent parts of the video are displayed as transparent. HAP encoded files (and other formats) with alpha support should now playback with transparency.
- "vd": "libvpx-vp9,libvpx"
This forces MPV to use the libvpx VP8 & VP9 decoders for these video formats, which support alpha channel decoding compared to the default VP8 & VP9 decoders.