webpage/docs/configuration/capture.md
import { Def, Opt } from '@site/src/components/Anchor'; import { ConfigurationTab } from '@site/src/components/Configuration'; import configOptions from './help.json';
This guide will show you how to configure the audio and video capture settings in neko.
Neko uses Gstreamer to capture and encode audio and video in the following scenarios:
Neko allows you to capture the display and encode it in real-time using Gstreamer. The encoded video is then sent to the client using WebRTC. This allows you to share the display with the client in real-time.
There can exist multiple video pipelines in neko that are referenced by their unique pipeline id. Each video pipeline can have its own configuration settings and clients can either choose which pipeline they want to use or let neko choose the best pipeline for them.
:::info Limitation All video pipelines must use the same video codec (defined in the <Opt id="video.codec" /> setting). :::
The Gstreamer pipeline is started when the first client requests the video stream and is stopped after the last client disconnects.
<ConfigurationTab options={configOptions} filter={[ "capture.video.display", "capture.video.codec", "capture.video.ids", "capture.video.pipeline", "capture.video.pipelines", ]} comments={false} />
DISPLAY will be used.vp8, vp9, av1, h264. Supported video codecs are dependent on the WebRTC implementation used by the client, vp8 and h264 are supported by all WebRTC implementations.Expression allows you to build the pipeline dynamically based on the current resolution and framerate of the display. Expressions are evaluated using the gval library. Available variables are <Opt id="video.pipelines.width" />, <Opt id="video.pipelines.height" />, and <Opt id="video.pipelines.fps" /> of the display at the time of capture.
capture:
video:
...
pipelines:
<pipeline_id>:
width: "<expression>"
height: "<expression>"
fps: "<expression>"
gst_prefix: "<gst_pipeline>"
gst_encoder: "<gst_encoder_name>"
gst_params:
<param_name>: "<expression>"
gst_suffix: "<gst_pipeline>"
show_pointer: true
! and then be followed by the Gstreamer elements.vp8enc or x264enc.import Tabs from '@theme/Tabs'; import TabItem from '@theme/TabItem';
<Tabs> <TabItem value="vp8" label="VP8 configuration">```yaml title="config.yaml"
capture:
video:
codec: vp8
# HQ is the default pipeline
ids: [ hq, lq ]
pipelines:
hq:
fps: 25
gst_encoder: vp8enc
gst_params:
target-bitrate: round(3072 * 650)
cpu-used: 4
end-usage: cbr
threads: 4
deadline: 1
undershoot: 95
buffer-size: (3072 * 4)
buffer-initial-size: (3072 * 2)
buffer-optimal-size: (3072 * 3)
keyframe-max-dist: 25
min-quantizer: 4
max-quantizer: 20
lq:
fps: 25
gst_encoder: vp8enc
gst_params:
target-bitrate: round(1024 * 650)
cpu-used: 4
end-usage: cbr
threads: 4
deadline: 1
undershoot: 95
buffer-size: (1024 * 4)
buffer-initial-size: (1024 * 2)
buffer-optimal-size: (1024 * 3)
keyframe-max-dist: 25
min-quantizer: 4
max-quantizer: 20
```
```yaml title="config.yaml"
capture:
video:
codec: h264
ids: [ main ]
pipelines:
main:
width: (width / 3) * 2
height: (height / 3) * 2
fps: 20
gst_prefix: "! video/x-raw,format=I420"
gst_encoder: "x264enc"
gst_params:
threads: 4
bitrate: 4096
key-int-max: 15
byte-stream: true
tune: zerolatency
speed-preset: veryfast
gst_suffix: "! video/x-h264,stream-format=byte-stream"
```
If you want to define the pipeline using a Gstreamer pipeline description, you can do so by setting the <Def id="video.pipelines.gst_pipeline" /> parameter.
capture:
video:
...
pipelines:
<pipeline_id>:
gst_pipeline: "<gstreamer_pipeline>"
Since now you have to define the whole pipeline, you need to specify the src element to get the video frames and the sink element to send the encoded video frames to neko. In your pipeline, you can use {display} as a placeholder for the display name that will be replaced by the actual display name at runtime. You need to set the name property of the sink element to appsink so that neko can capture the video frames.
Your typical pipeline string would look like this:
ximagesrc display-name={display} show-pointer=true use-damage=false ! <your_elements> ! appsink name=appsink
See documentation for ximagesrc and appsink for more information.
<details> <summary>Example pipeline configuration</summary> <Tabs> <TabItem value="vp8" label="VP8 configuration">```yaml title="config.yaml"
capture:
video:
codec: vp8
ids: [ hq, lq ]
pipelines:
hq:
gst_pipeline: |
ximagesrc display-name={display} show-pointer=true use-damage=false
! videoconvert ! queue
! vp8enc
name=encoder
target-bitrate=3072000
cpu-used=4
end-usage=cbr
threads=4
deadline=1
undershoot=95
buffer-size=12288
buffer-initial-size=6144
buffer-optimal-size=9216
keyframe-max-dist=25
min-quantizer=4
max-quantizer=20
! appsink name=appsink
lq:
gst_pipeline: |
ximagesrc display-name={display} show-pointer=true use-damage=false
! videoconvert ! queue
! vp8enc
name=encoder
target-bitrate=1024000
cpu-used=4
end-usage=cbr
threads=4
deadline=1
undershoot=95
buffer-size=4096
buffer-initial-size=2048
buffer-optimal-size=3072
keyframe-max-dist=25
min-quantizer=4
max-quantizer=20
! appsink name=appsink
```
```yaml title="config.yaml"
capture:
video:
codec: h264
ids: [ main ]
pipelines:
main:
gst_pipeline: |
ximagesrc display-name={display} show-pointer=true use-damage=false
! videoconvert ! queue
! x264enc
name=encoder
threads=4
bitrate=4096
key-int-max=15
byte-stream=true
tune=zerolatency
speed-preset=veryfast
! video/x-h264,stream-format=byte-stream
! appsink name=appsink
```
```yaml title="config.yaml"
capture:
video:
codec: h264
ids: [ main ]
pipelines:
main:
gst_pipeline: |
ximagesrc display-name={display} show-pointer=true use-damage=false
! videoconvert ! queue
! video/x-raw,format=NV12
! nvh264enc
name=encoder
preset=2
gop-size=25
spatial-aq=true
temporal-aq=true
bitrate=4096
vbv-buffer-size=4096
rc-mode=6
! h264parse config-interval=-1
! video/x-h264,stream-format=byte-stream
! appsink name=appsink
```
This configuration requires [Nvidia GPU](https://developer.nvidia.com/cuda-gpus) with [NVENC](https://developer.nvidia.com/nvidia-video-codec-sdk) support.
```yaml title="config.yaml"
capture:
video:
codec: h264
ids: [ main ]
pipelines:
main:
gst_pipeline: |
ximagesrc display-name={display} show-pointer=true use-damage=false
! cudaupload ! cudaconvert ! queue
! video/x-raw(memory:CUDAMemory),format=NV12
! nvh264enc
name=encoder
preset=2
gop-size=25
spatial-aq=true
temporal-aq=true
bitrate=4096
vbv-buffer-size=4096
rc-mode=6
! h264parse config-interval=-1
! video/x-h264,stream-format=byte-stream
! appsink name=appsink
```
This configuration requires [Nvidia GPU](https://developer.nvidia.com/cuda-gpus) with [NVENC](https://developer.nvidia.com/nvidia-video-codec-sdk) support and [Cuda](https://developer.nvidia.com/cuda-zone) support.
Overview of available encoders for each codec is shown in the table below. The encoder name is used in the <Opt id="video.pipelines.gst_encoder" /> parameter. The parameters for each encoder are different and you can find the documentation for each encoder in the links below.
| codec | encoder | vaapi encoder | nvenc encoder |
|---|---|---|---|
| VP8 | vp8enc | vaapivp8enc | ? |
| VP9 | vp9enc | vaapivp9enc | ? |
| AV1 | av1enc | ? | nvav1enc |
| H264 | x264enc | vaapih264enc | nvh264enc |
| H265 | x265enc | vaapih265enc | nvh265enc |
Only one audio pipeline can be defined in neko. The audio pipeline is used to capture and encode audio, similar to the video pipeline. The encoded audio is then sent to the client using WebRTC.
The Gstreamer pipeline is started when the first client requests the video stream and is stopped after the last client disconnects.
<ConfigurationTab options={configOptions} filter={[ "capture.audio.device", "capture.audio.codec", "capture.audio.pipeline", ]} comments={false} />
opus, g722, pcmu, pcma. Supported audio codecs are dependent on the WebRTC implementation used by the client, opus is supported by all WebRTC implementations.{device} as a placeholder for the audio device name that will be replaced by the actual device name at runtime.capture:
audio:
codec: opus
pipeline: |
pulsesrc device={device}
! audioconvert
! opusenc
bitrate=320000
! appsink name=appsink
Neko allows you to broadcast out-of-the-box the display and audio capture to a third-party service. This can be used to broadcast the display and audio to a streaming service like Twitch or YouTube, or to a custom RTMP server like OBS, Nginx RTMP module, or MediaMTX.
The Gstreamer pipeline is started when the broadcast is started and is stopped when the broadcast is stopped regardless of the clients connected.
<ConfigurationTab options={configOptions} filter={[ "capture.broadcast.audio_bitrate", "capture.broadcast.video_bitrate", "capture.broadcast.preset", "capture.broadcast.pipeline", "capture.broadcast.url", "capture.broadcast.autostart", ]} comments={false} />
The default encoder uses h264 for video and aac for audio, muxed in the flv container and sent over the rtmp protocol. You can change the encoder settings by setting a custom Gstreamer pipeline description in the <Opt id="broadcast.pipeline" /> parameter.
{hostname}, {display}, {device} and {url} as placeholders for the X display name, pulseaudio audio device name, and broadcast URL respectively.rtmp://<server>/<application>/<stream_key>. This can be set later using the API if the URL is not known at the time of configuration or is expected to change.```yaml title="config.yaml"
capture:
broadcast:
pipeline: |
flvmux name=mux
! rtmpsink location={url}
pulsesrc device={device}
! audio/x-raw,channels=2
! audioconvert
! voaacenc
! mux.
ximagesrc display-name={display} show-pointer=false use-damage=false
! video/x-raw,framerate=28/1
! videoconvert
! queue
! x264enc bframes=0 key-int-max=0 byte-stream=true tune=zerolatency speed-preset=veryfast
! mux.
```
```yaml title="config.yaml"
capture:
broadcast:
pipeline: |
flvmux name=mux
! rtmpsink location={url}
pulsesrc device={device}
! audio/x-raw,channels=2
! audioconvert
! voaacenc
! mux.
ximagesrc display-name={display} show-pointer=false use-damage=false
! video/x-raw,framerate=30/1
! videoconvert
! queue
! video/x-raw,format=NV12
! nvh264enc name=encoder preset=low-latency-hq gop-size=25 spatial-aq=true temporal-aq=true bitrate=2800 vbv-buffer-size=2800 rc-mode=6
! h264parse config-interval=-1
! video/x-h264,stream-format=byte-stream,profile=high
! h264parse
! mux.
```
This configuration requires [Nvidia GPU](https://developer.nvidia.com/cuda-gpus) with [NVENC](https://developer.nvidia.com/nvidia-video-codec-sdk) support and [Nvidia docker image](/docs/v3/installation/docker-images#nvidia) of neko.
As a fallback mechanism, neko can capture the display in the form of JPEG images and the client can request these images over HTTP. This is useful when the client does not support WebRTC or when the client is not able to establish a WebRTC connection, or there is a temporary issue with the WebRTC connection and the client should not miss the content being shared.
:::note This is a fallback mechanism and should not be used as a primary video stream because of the high latency, low quality, and high bandwidth requirements. :::
The Gstreamer pipeline is started in the background when the first client requests the screencast and is stopped after a period of inactivity.
<ConfigurationTab options={configOptions} filter={[ "capture.screencast.enabled", "capture.screencast.rate", "capture.screencast.quality", "capture.screencast.pipeline", ]} comments={false} />
10/1 means 10 frames per second.60 means 60% quality.{display} as a placeholder for the X display name.capture:
screencast:
enabled: true
pipeline: |
ximagesrc display-name={display} show-pointer=true use-damage=false
! video/x-raw,framerate=10/1
! videoconvert
! queue
! jpegenc quality=60
! appsink name=appsink
:::danger This feature is experimental and may not work on all platforms. :::
Neko allows you to capture the webcam on the client machine and send it to the server using WebRTC. This can be used to share the webcam feed with the server.
The Gstreamer pipeline is started when the client shares their webcam and is stopped when the client stops sharing the webcam. Maximum one webcam pipeline can be active at a time.
<ConfigurationTab options={configOptions} filter={[ "capture.webcam.enabled", "capture.webcam.device", "capture.webcam.width", "capture.webcam.height", ]} comments={false} />
In order to use the webcam feature, the server must have the v4l2loopback kernel module installed and loaded. The module can be loaded using the following command:
# Install the required packages (Debian/Ubuntu)
sudo apt install v4l2loopback-dkms v4l2loopback-utils linux-headers-`uname -r` linux-modules-extra-`uname -r`
# Load the module with exclusive_caps=1 to allow multiple applications to access the virtual webcam
sudo modprobe v4l2loopback exclusive_caps=1
This is needed even if neko is running inside a Docker container. In that case, the v4l2loopback module must be loaded on the host machine and the device must be mounted inside the container.
services:
neko:
...
# highlight-start
devices:
- /dev/video0:/dev/video0
# highlight-end
...
Neko allows you to capture the microphone on the client machine and send it to the server using WebRTC. This can be used to share the microphone feed with the server.
The Gstreamer pipeline is started when the client shares their microphone and is stopped when the client stops sharing the microphone. Maximum one microphone pipeline can be active at a time.
<ConfigurationTab options={configOptions} filter={[ "capture.microphone.enabled", "capture.microphone.device", ]} comments={false} />