在 Linux 中使用 OBS 和 Wayland 进行屏幕录制
屏幕录制
有 [大量可用于 Linux 的屏幕录像机](https://itsfoss.com/best-linux-screen-recorders/)。但是当涉及到支持 [Wayland](https://wayland.freedesktop.org/) 时，几乎所有的都不能用。


这是个问题，因为许多新发布的版本都再次默认切换到 Wayland 显示管理器。而如果像屏幕录像机这样基本的东西不能工作，就会给人留下不好的体验。


[GNOME 的内置屏幕录像机](https://itsfoss.com/gnome-screen-recorder/) 可以工作，但它是隐藏的，没有 GUI，也没有办法配置和控制记录内容。此外，还有一个叫 [Kooha](https://itsfoss.com/kooha-screen-recorder/) 的工具，但它一直在屏幕上显示一个计时器。


只是为了录制屏幕而 [在 Xorg 和 Wayland 之间切换](https://itsfoss.com/switch-xorg-wayland/)，这不是很方便。


这种情况下，我很高兴地得知，由于 Pipewire 的帮助，在 OBS Studio v27 中支持了 Wayland。但即使是这样，也不是很简单，因此我将向你展示使用 [OBS Studio](https://obsproject.com/) 在 Wayland 上录制屏幕的步骤。


### 使用 OBS 在 Wayland 上进行屏幕录制


![](/data/attachment/album/202109/20/163709nq2328j3tc2jqqtf.jpg)


让我们来看看它是如何完成的。


#### 第一步：安装 OBS Studio


你应该先安装 OBS Studio v27。它已经包含在 Ubuntu 21.10 中，我会在本教程中使用它。


要在 Ubuntu 18.04、20.04、Linux Mint 20 等系统上安装 OBS Studio 27，请使用 [官方的 OBS Studio PPA](https://launchpad.net/~obsproject/+archive/ubuntu/obs-studio)。


打开终端，逐一使用以下命令：



```
sudo add-apt-repository ppa:obsproject/obs-studio
sudo apt update
sudo apt install obs-studio

```

如果已经安装了 OBS Studio 的旧版本，它将被升级到较新的版本。


对于 Fedora、Arch 和其他发行版，请检查你的包管理器或非官方仓库以安装最新版本的 OBS Studio。


#### 第二步：检查 Wayland 捕获是否工作


请确认你正在使用 Wayland。现在启动 OBS Studio，查看它在第一次运行时显示的所有内容。我不打算展示这些。


主要步骤是添加 Pipewire 作为屏幕捕捉源。点击 “Sources” 列表下的 “+” 符号。


![Add screen capture source in OBS Studio](/data/attachment/album/202109/20/163710glbvhzbxt55lv2y6.png)


你有没有看到 “Screen Capture (PipeWire)” 的字样？


![Do you see PipeWire option in the screen sources?](/data/attachment/album/202109/20/163710c68nvmw0t2462xxx.png)


**如果没看到，请退出 OBS Studio**。这很正常。至少在 Ubuntu 下，OBS Studio 不会自动切换到使用 Wayland。对此有一个修复方法。


打开一个终端，使用以下命令：



```
export QT_QPA_PLATFORM=wayland

```

在同一个终端，运行以下命令，启动 OBS Studio：



```
obs

```

它将在终端上显示一些信息。不要理会它们。你的注意力应该放在 OBS Studio GUI 上。再次尝试添加屏幕捕捉。你现在应该看到 PipeWire 选项了。


![](/data/attachment/album/202109/20/163710c68nvmw0t2462xxx.png)


你这次用 `QT_QPA_PLATFORM` 变量明确要求 OBS Studio 使用 Wayland。


选择 PipeWire 作为源，然后它要求你选择一个显示屏幕。选择它并点击分享按钮。


![](/data/attachment/album/202109/20/163710juxbyqbmmjenrmqe.png)


现在它应该无限次递归地显示你的屏幕。如果你看到了，你现在就可以开始在 Wayland 中录制屏幕了。


![](/data/attachment/album/202109/20/163710tqclencdze2q02pa.jpg)


#### 第三步：让改变成为永久性的


这很好。你刚刚验证了你可以在 Wayland 上录制屏幕。但每次设置环境变量并从终端启动 OBS 并不方便。


你可以做的是**把这个变量导出到你的 `~/.bash_profile`（对你而言）或 `/etc/profile`（对系统中的所有用户而言）。**



```
export QT_QPA_PLATFORM=wayland

```

退出并重新登录。现在 OBS 会自动开始使用这个参数，你可以用它来录制 Wayland 的屏幕。


我希望这个快速技巧对你有帮助。如果你还有问题或建议，请在评论区告诉我。




---


via: <https://itsfoss.com/screen-record-obs-wayland/>


作者：[Abhishek Prakash](https://itsfoss.com/author/abhishek/) 选题：[lujun9972](https://github.com/lujun9972) 译者：[geekpi](https://github.com/geekpi) 校对：[wxy](https://github.com/wxy)


本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译，[Linux中国](https://linux.cn/) 荣誉推出


OK
There are [tons of screen recorders available for Linux](https://itsfoss.com/best-linux-screen-recorders/). But when it comes to supporting [Wayland](https://wayland.freedesktop.org/), almost all of them do not work.

This is problematic because many new distribution releases are switching to Wayland display manager by default once again. And if something as basic as a screen recorder does not work, it leaves a bad experience.

[GNOME’s built-in screen recorder](https://itsfoss.com/gnome-screen-recorder/) works but it is hidden, has no GUI and no way to configure and control the recordings. There is another tool called [Kooha](https://itsfoss.com/kooha-screen-recorder/) but it keeps on displaying a timer on the screen.

[Switching between Xorg and Wayland](https://itsfoss.com/switch-xorg-wayland/) just for screen recording is not very convenient.

Amidst all this, I was happy to learn that Wayland support landed in OBS Studio with version 27 release thanks to Pipewire. But even there, it’s not straightforward and hence I am going to show you the steps for screen recording on Wayland using [OBS Studio](https://obsproject.com/).

## Using OBS to screen record on Wayland

![obs screen record wayland](https://itsfoss.com/content/images/wordpress/2021/09/obs-screen-record-wayland.webp)

Let’s see how it is done.

### Step 1: Install OBS Studio

You should install OBS Studio version 27 first. It is already included in Ubuntu 21.10 which I am using in this tutorial.

`sudo apt install obs-studio`


To install OBS Studio 27 on Ubuntu 18.04, 20.04, Linux Mint 20 etc, use the [official OBS Studio](https://launchpad.net/~obsproject/+archive/ubuntu/obs-studio)[ ](https://launchpad.net/~obsproject/+archive/ubuntu/obs-studio)[PPA](https://launchpad.net/~obsproject/+archive/ubuntu/obs-studio).

Open a terminal and use the following commands one by one:

```
sudo add-apt-repository ppa:obsproject/obs-studio
sudo apt update
sudo apt install obs-studio
```


If there is an older version of OBS Studio installed already, it will be upgraded to the newer version.

For Fedora, Arch and other distributions, please check your package manager or unofficial repositories for installing the latest version of OBS Studio.

### Step 2: Check if Wayland capture is working

Please make sure that you are using Wayland. Now start OBS Studio and go through all the stuff it shows on the first run. I am not going to show that.

The main step is to add Pipewire as a screen capture source. Click on the + symbol under the Sources list.

![obs studio add screen capture source](https://itsfoss.com/content/images/wordpress/2021/09/obs-studio-add-screen-capture-source-800x537.png)

Do you see anything that reads Screen Capture (PipeWire)?

![obs studio wayland support](https://itsfoss.com/content/images/wordpress/2021/09/obs-studio-wayland-support-800x538.png)

**If the answer is no, quit OBS Studio**. This is normal. OBS Studio does not switch to use Wayland automatically in Ubuntu at least. There is a fix for that.

Open a terminal and use the following command:

`export QT_QPA_PLATFORM=wayland`


In the same terminal, run the following command to start OBS Studio:

`obs`


It will show some message on the terminal. Ignore them. Your focus should be on the OBS Studio GUI. Try to add screen capture once again. You should see the PipeWire option now.

![obs studio wayland support](https://itsfoss.com/content/images/wordpress/2021/09/obs-studio-wayland-support-800x538.png)

You explicitly asked OBS Studio to use Wayland this time with the QT_QPA_PLATFORM variable.

Select PipeWire as the source and then it asks you to choose a display screen. Select it and click on the Share button.

![obs studio screen](https://itsfoss.com/content/images/wordpress/2021/09/obs-studio-screen-800x578.png)

Now it should show your screen recursively infinite number of times. If you see that, you could start recording the screen in Wayland now.

![start screen recording obs wayland](https://itsfoss.com/content/images/wordpress/2021/09/start-screen-recording-obs-wayland-800x537.jpg)

### Step 3: Make changes permanent

That was good. You just verified that you can record your screen on Wayland. But setting the environment variable and starting OBS from the terminal each time is not convenient.

What you can do is to **export the variable to your ~/.bash_profile (for you) or /etc/profile (for all users on the system).**

`export QT_QPA_PLATFORM=wayland`


Log out and log back in. Now OBS will automatically start using this parameter and you can use it to record your screen in Wayland.

**Note: I noticed that MEGA cloud service stopped working after this change. If you notice some applications stopped working after this change, revert it please.**

I hope you find this quick tip helpful. If you still have questions or suggestions, please let me know in the comment section.