Jump to content

OBS Studio: Difference between revisions

From Official NixOS Wiki
m Added information about the OBS module added to NixOS in 24.11.
Mach50 (talk | contribs)
Added the `video` group requirement for virtual camera
 
(2 intermediate revisions by one other user not shown)
Line 12: Line 12:
   programs.obs-studio = {
   programs.obs-studio = {
     enable = true;
     enable = true;
    # optional Nvidia hardware acceleration
    package = (
      pkgs.obs-studio.override {
        cudaSupport = true;
      }
    );
     plugins = with pkgs.obs-studio-plugins; [
     plugins = with pkgs.obs-studio-plugins; [
       wlrobs
       wlrobs
       obs-backgroundremoval
       obs-backgroundremoval
       obs-pipewire-audio-capture
       obs-pipewire-audio-capture
      obs-vaapi #optional AMD hardware acceleration
      obs-gstreamer
      obs-vkcapture
     ];
     ];
   };
   };
Line 23: Line 34:
or by wrapping the package with <code>wrapOBS</code>:
or by wrapping the package with <code>wrapOBS</code>:


<syntaxhighlight lang="nix">
<syntaxhighlight lang="nix">environment.systemPackages = [
environment.systemPackages = [
   (pkgs.wrapOBS {
   (pkgs.wrapOBS {
     plugins = with pkgs.obs-studio-plugins; [
     plugins = with pkgs.obs-studio-plugins; [
Line 30: Line 40:
       obs-backgroundremoval
       obs-backgroundremoval
       obs-pipewire-audio-capture
       obs-pipewire-audio-capture
      obs-vaapi #optional AMD hardware acceleration
      obs-gstreamer
      obs-vkcapture
     ];
     ];
   })
   })
];
];</syntaxhighlight>'''Package collision''': Including both <code>obs-studio</code> and <code>(pkgs.wrapOBS {...</code> in <code>environment.systemPackages</code> will result in a package collision; if plugins are needed, only include the "wrapped" version, which sets the plugins directory to include Nix-managed plugins (see [https://github.com/NixOS/nixpkgs/blob/master/pkgs/applications/video/obs-studio/wrapper.nix pkgs/applications/video/obs-studio/wrapper.nix].
</syntaxhighlight>


Including both <code>obs-studio</code> and <code>(pkgs.wrapOBS {...</code> in <code>environment.systemPackages</code> will result in a package collision; if plugins are needed, only include the "wrapped" version, which sets the plugins directory to include Nix-managed plugins (see [https://github.com/NixOS/nixpkgs/blob/master/pkgs/applications/video/obs-studio/wrapper.nix pkgs/applications/video/obs-studio/wrapper.nix].
'''Missing hardware acceleration''': Sometimes you need to set "Output Mode" to Advanced in settings Output tab to see the hardware accelerated Video Encoders options.


=== Using the Virtual Camera ===
=== Using the Virtual Camera ===


The virtual camera requires the <code>v4l2loopback</code> [[Linux kernel#Custom kernel modules|kernel module]] to be installed, a loopback device configured, and polkit enabled so OBS can access the virtual device.
The virtual camera requires the <code>v4l2loopback</code> [[Linux kernel#Custom kernel modules|kernel module]] to be installed, a loopback device configured, polkit enabled so OBS can access the virtual device and the relevant users to be added to the <code>video</code> group.


This can be done in NixOS with:<syntaxhighlight lang="nixos">
This can be done in NixOS with:<syntaxhighlight lang="nixos">programs.obs-studio.enableVirtualCamera = true;
programs.obs-studio.enableVirtualCamera = true;
 
</syntaxhighlight>Or by setting the kernel options manually, this is useful if you need to add an additional loopback device as shown below:<syntaxhighlight lang="nix">
users.users.<username>.extraGroups = ["video"]; # replace <username> with your username</syntaxhighlight>Or by setting the kernel options manually, this is useful if you need to add an additional loopback device as shown below:<syntaxhighlight lang="nix">
{ config, ... }:
{ config, ... }:
{
{
Line 54: Line 66:
   '';
   '';
   security.polkit.enable = true;
   security.polkit.enable = true;
  users.users.<username>.extraGroups = ["video"];
}
}
</syntaxhighlight>
</syntaxhighlight>

Latest revision as of 19:27, 6 November 2026

OBS Studio is free and open-source software for video recording and live streaming, licensed under the GNU GPLv2 license.

Installing Plugins

Plugins are available from the obs-studio-plugins package set.

They can be installed by using either the NixOS or Home Manager module:

{ config, pkgs, ... }:
{
  programs.obs-studio = {
    enable = true;

    # optional Nvidia hardware acceleration
    package = (
      pkgs.obs-studio.override {
        cudaSupport = true;
      }
    );

    plugins = with pkgs.obs-studio-plugins; [
      wlrobs
      obs-backgroundremoval
      obs-pipewire-audio-capture
      obs-vaapi #optional AMD hardware acceleration
      obs-gstreamer
      obs-vkcapture
    ];
  };
}

or by wrapping the package with wrapOBS:

environment.systemPackages = [
  (pkgs.wrapOBS {
    plugins = with pkgs.obs-studio-plugins; [
      wlrobs
      obs-backgroundremoval
      obs-pipewire-audio-capture
      obs-vaapi #optional AMD hardware acceleration
      obs-gstreamer
      obs-vkcapture
    ];
  })
];

Package collision: Including both obs-studio and (pkgs.wrapOBS {... in environment.systemPackages will result in a package collision; if plugins are needed, only include the "wrapped" version, which sets the plugins directory to include Nix-managed plugins (see pkgs/applications/video/obs-studio/wrapper.nix.

Missing hardware acceleration: Sometimes you need to set "Output Mode" to Advanced in settings Output tab to see the hardware accelerated Video Encoders options.

Using the Virtual Camera

The virtual camera requires the v4l2loopback kernel module to be installed, a loopback device configured, polkit enabled so OBS can access the virtual device and the relevant users to be added to the video group.

This can be done in NixOS with:

programs.obs-studio.enableVirtualCamera = true;

users.users.<username>.extraGroups = ["video"]; # replace <username> with your username

Or by setting the kernel options manually, this is useful if you need to add an additional loopback device as shown below:

{ config, ... }:
{
  boot.extraModulePackages = with config.boot.kernelPackages; [
    v4l2loopback
  ];
  boot.kernelModules = [ "v4l2loopback" ];
  boot.extraModprobeConfig = ''
    options v4l2loopback devices=1 video_nr=1 card_label="OBS Cam" exclusive_caps=1
  '';
  security.polkit.enable = true;

  users.users.<username>.extraGroups = ["video"];
}

It is possible to use Droidcam as virtual camera.

If you use a digital camera as a webcam via gphoto2 you will need an additional loopback device to use this camera as a virtual camera. For a setup like this you may wish to change the above v4l2loopback module config to something like this:

boot.extraModprobeConfig = ''
  options v4l2loopback devices=2 video_nr=1,2 card_label="OBS Cam, Virt Cam" exclusive_caps=1
'';

For more the arch wiki entry on v4l2loopback is a good reference. In addition to gphoto2 you will need the v4l-utils and ffmpeg packages so that you can use gphoto2 to send the raw feed from your camera to the virtual camera via ffmpeg for example using a command like this[1]:

gphoto2 --stdout autofocusdrive=1 --capture-movie | ffmpeg -i - -vcodec rawvideo -pix_fmt yuv420p -threads 0 -f v4l2 /dev/video2