#screen-recording #screen-capture #wayland #performance #high #recorder #video

app wl-screenrec

为 wlroots 提供的高性能屏幕/音频录制器

5 个版本

0.1.5 2024年8月4日
0.1.4 2024年7月16日
0.1.3 2024年2月16日
0.1.1 2023年11月18日
0.1.0 2023年10月2日

#58 in GUI

Download history 86/week @ 2024-04-24 4/week @ 2024-05-29 4/week @ 2024-06-05 105/week @ 2024-07-10 35/week @ 2024-07-17 22/week @ 2024-07-24 107/week @ 2024-07-31 23/week @ 2024-08-07

每月 292 次下载

自定义许可证

100KB
2.5K SLoC

wl-screenrec

为 wlroots Wayland 的高性能屏幕录制器。

使用 dma-buf 传输获取表面,并使用 GPU 进行像素格式转换和编码,这意味着原始视频数据永远不会触及 CPU,使其能够运行您的应用程序。

如果有什么问题,请提出问题,我很乐意查看。

系统要求

性能

(相对不科学的)基准测试设置

  • 4Kp60 显示器
  • i9-11900H CPU/GPU
  • vkcube 在屏幕上运行,因为 wf-recorderwl-screenrec 在没有差异时不会复制/编码帧
命令 CPU 使用率 GPU 3D Δ GPU 视频 Δ
wf-recorder ~500% +44% 0%
wf-recorder-c h264_vaapi-d/dev/dri/card0 ~75% +88% +23%
wl-screenrec ~2.5% +91% +30%

此外,在使用 wf-recorder 的任何配置中,在 vkcube 窗口中都会有明显的卡顿。 wl-screenrec 似乎根本不会卡顿。

然而,这代价是稍微使用了更多的 GPU。这些数字似乎很稳定,我假设它们在统计上是有意义的,但仍然不是巨大的变化。

安装

从 AUR 安装

paru -S wl-screenrec
# OR
paru -S wl-screenrec-git

或,手动安装

git clone https://aur.archlinux.org/wl-screenrec-git.git
cd wl-screenrec-git
makepkg -si

使用 cargo 从源代码安装

安装 ffmpeg 6 或更高版本,这是必需的依赖项。ffmpeg 5 可能可以工作,但尚未测试(如果您使用 ffmpeg 5 进行测试,请提出问题或 PR,以便我可以更新这些文档,以了解是否可以正常工作)

cargo install wl-screenrec # stable version
# OR
cargo install --git https://github.com/russelltg/wl-screenrec # git version

FreeBSD

目前存在一个 上游问题 阻止在 FreeBSD 上成功构建,但您可以通过修补 rust-ffmpeg 依赖关系来解决此问题

git clone https://github.com/russelltg/wl-screenrec
cd wl-screenrec
echo '[patch.crates-io]
ffmpeg-next = { git = "https://github.com/russelltg/rust-ffmpeg", branch = "fix_freebsd_build" }' >> Cargo.toml
cargo install --path .

使用方法

捕获整个输出

wl-screenrec         # valid when you only have one output
wl-screenrec -o DP-1 # specify outuput

捕获区域

wl-screenrec -g "$(slurp)"    # use slurp
wl-screenrec -g "0,0 128x128" # manual region

捕获444视频(无像素格式压缩)

注意:查看vainfo -以查看支持的像素格式。支持程度高度依赖于硬件。例如,在我的机器上,只有HEVC支持444格式,所有8位RGB格式由于某种原因都无法工作。

wl-screenrec --codec hevc --encode-pixfmt vuyx   # 8-bit 444
wl-screenrec --codec hevc --encode-pixfmt xrgb10 # 10-bit 444

带有音频的捕获

wl-screenrec --audio                                                                 # default capture device
wl-screenrec --audio --audio-device alsa_output.pci-0000_00_1f.3.hdmi-stereo.monitor # capture desktop audio (example, use `pactl list short sources` to figure out what you should put here)

带历史记录录制

wl-screenrec --history 10 & # record the most recent 10 seconds into memory, not writing into the file
# ... some important event occurs
killall -USR1 wl-screenrec  # flush the most recent 10 seconds onto the file, and start appending to the file like recording normally

捕获到v4l2loopback(用于Zoom等)

sudo modprobe v4l2loopback
v4l2-ctl --list-devices # find "Dummy video device" device. /dev/video6 in my case.
wl-screenrec --ffmpeg-muxer v4l2 -f /dev/video6

所有选项

$ wl-screenrec --help
High performance screen/audio recorder for wlroots

Usage: wl-screenrec [OPTIONS]

Options:
      --no-hw
          don't use the GPU encoder, download the frames onto the CPU and use a software encoder. Ignored if `encoder` is supplied
  -f, --filename <FILENAME>
          filename to write to. container type is detected from extension [default: screenrecord.mp4]
  -g, --geometry <GEOMETRY>
          geometry to capture, format x,y WxH. Compatible with the output of `slurp`. Mutually exclusive with --output
  -o, --output <OUTPUT>
          Which output (display) to record. Mutually exclusive with --geometry. Defaults to your only display if you only have one [default: ]
  -v, --verbose...
          add very loud logging. can be specified multiple times
      --dri-device <DRI_DEVICE>
          which dri device to use for vaapi. by default, this is obtained from the drm-lease-v1 protocol, if present. if not present, /dev/dri/renderD128 is guessed
      --low-power <LOW_POWER>
          [default: auto] [possible values: auto, on, off]
      --codec <CODEC>
          which video codec to use. Ignored if `--ffmpeg-encoder` is supplied [default: auto] [possible values: auto, avc, hevc, vp8, vp9, av1]
      --ffmpeg-muxer <FFMPEG_MUXER>
          Which ffmpeg muxer to use. Guessed from output filename by default
      --ffmpeg-muxer-options <FFMPEG_MUXER_OPTIONS>
          Options to pass to the muxer. Format looks like key=val,key2=val2
      --ffmpeg-encoder <FFMPEG_ENCODER>
          Use this to force a particular ffmpeg encoder. Generally, this is not necessary and the combo of --codec and --hw can get you to where you need to be
      --audio-codec <AUDIO_CODEC>
          Which audio codec to use. Ignored if `--ffmpeg-audio-encoder` is supplied [default: auto] [possible values: auto, aac, mp3, flac, opus]
      --ffmpeg-audio-encoder <FFMPEG_AUDIO_ENCODER>
          Use this to force a particular audio ffmpeg encoder. By default, this is guessed from the muxer (which is guess by the file extension if --ffmpeg-muxer isn't passed)
      --encode-pixfmt <ENCODE_PIXFMT>
          which pixel format to encode with. not all codecs will support all pixel formats. This should be a ffmpeg pixel format string, like nv12 or x2rgb10. If the encoder supports vaapi memory, it will use this pixel format type but in vaapi memory
      --encode-resolution <ENCODE_RESOLUTION>
          what resolution to encode at. example: 1920x1080. Default is the resolution of the captured region. If your goal is reducing filesize, it's suggested to try --bitrate/-b first
  -b, --bitrate <BITRATE>
          bitrate to encode at. Unit is bytes per second, so 5 MB is 40 Mbps [default: "5 MB"]
      --history <HISTORY>
          run in a mode where the screen is recorded, but nothing is written to the output file until SIGUSR1 is sent to the process. Then, it writes the most recent N seconds to a file and continues recording
      --audio
          record audio with the stream. Defaults to the default audio capture device
      --audio-device <AUDIO_DEVICE>
          which audio device to record from. list devices with `pactl list short sources` [default: default]
      --audio-backend <AUDIO_BACKEND>
          which ffmpeg audio capture backend (see https://ffmpeg.org/ffmpeg-devices.html`) to use. you almost certainally want to specify --audio-device if you use this, as the values depend on the backend used [default: pulse]
      --no-damage
          copy every frame, not just unique frames. This can be helpful to get a non-variable framerate video, but is generally discouraged as it uses much more resources. Useful for testing
      --gop-size <GOP_SIZE>
          GOP (group of pictures) size
  -h, --help
          Print help
  -V, --version
          Print version

已知问题

  • 无法捕获跨越多个显示器的区域。这可能可行,但相当困难,尤其是在刷新率可能存在差异的情况下。可能永远不会得到支持。

依赖项

~7–18MB
~260K SLoC