Ubuntu 上的 ffmpeg x11grab:增加 FPS

Ubuntu 上的 ffmpeg x11grab:增加 FPS

我正在尝试配置 FFMpeg 来捕获整个 FHD 屏幕(浏览器内有视频和声音)。结果 FPS 太低(每秒 3 到 15 帧,取决于 CLI 参数,但我至少需要每秒 30 帧)。

录制屏幕时,只有 Firefox 和 ffmpeg 在运行,没有加载其他应用程序。浏览器呈现内容时没有延迟,正如我在显示屏上看到的那样,一切都运行顺畅。

当前的操作系统版本是Ubuntu 22.04.4 LTS(Lubuntu 发行版),我尝试了不同的版本:20.04、22.04、24.04——结果相同。

以下是我获得的硬件:8GB RAM,CPU:

Vendor ID:                          GenuineIntel
CPU family:                         6
Model:                              142
Model name:                         Intel(R) Core(TM) i5-7200U CPU @ 2.50GHz
Stepping:                           9
CPU MHz:                            2700.000
CPU max MHz:                        3100.0000
CPU min MHz:                        400.0000

视频适配器:

00:02.0 VGA compatible controller: Intel Corporation HD Graphics 620 (rev 02)
    DeviceName:  Onboard IGD
    Subsystem: Intel Corporation HD Graphics 620
    Kernel driver in use: i915

description: VGA compatible controller
       product: HD Graphics 620
       vendor: Intel Corporation
       physical id: 2
       bus info: pci@0000:00:02.0
       version: 02
       width: 64 bits
       clock: 33MHz
       capabilities: pciexpress msi pm vga_controller bus_master cap_list rom
       configuration: driver=i915 latency=0
       resources: irq:125 memory:de000000-deffffff memory:c0000000-cfffffff ioport:f000(size=64) memory:c0000-dffff

我得到了 SSD,启用了 AHCI,速度测试结果如下:

$ sudo hdparm -Tt /dev/sda
/dev/sda:
 Timing cached reads:   14394 MB in  1.99 seconds = 7232.49 MB/sec
 Timing buffered disk reads: 1552 MB in  3.00 seconds = 517.09 MB/sec

$ dd if=/dev/zero of=/tmp/output bs=8k count=10k; rm -f /tmp/output
10240+0 records in
10240+0 records out
83886080 bytes (84 MB, 80 MiB) copied, 0.0493025 s, 1.7 GB/s

我在捕获过程中观察了 CPU 温度,一切正常

coretemp-isa-0000
Adapter: ISA adapter
Package id 0:  +40.0°C  (high = +100.0°C, crit = +100.0°C)
Core 0:        +40.0°C  (high = +100.0°C, crit = +100.0°C)
Core 1:        +39.0°C  (high = +100.0°C, crit = +100.0°C)

另外,当我观察top命令时,每个 CPU 核心的负载约为 50%(我预计约为 100%)。

我尝试在 BIOS 中启用/禁用超线程 – 没有区别。

以下是ffmpeg的日志:

ffmpeg version 4.4.2-0ubuntu0.22.04.1 Copyright (c) 2000-2021 the FFmpeg developers
  built with gcc 11 (Ubuntu 11.2.0-19ubuntu1)
  configuration: --prefix=/usr --extra-version=0ubuntu0.22.04.1 --toolchain=hardened --libdir=/usr/lib/x86_64-linux-gnu --incdir=/usr/include/x86_64-linux-gnu --arch=amd64 --enable-gpl --disable-stripping --enable-gnutls --enable-ladspa --enable-libaom --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libcdio --enable-libcodec2 --enable-libdav1d --enable-libflite --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libgme --enable-libgsm --enable-libjack --enable-libmp3lame --enable-libmysofa --enable-libopenjpeg --enable-libopenmpt --enable-libopus --enable-libpulse --enable-librabbitmq --enable-librubberband --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libsrt --enable-libssh --enable-libtheora --enable-libtwolame --enable-libvidstab --enable-libvorbis --enable-libvpx --enable-libwebp --enable-libx265 --enable-libxml2 --enable-libxvid --enable-libzimg --enable-libzmq --enable-libzvbi --enable-lv2 --enable-omx --enable-openal --enable-opencl --enable-opengl --enable-sdl2 --enable-pocketsphinx --enable-librsvg --enable-libmfx --enable-libdc1394 --enable-libdrm --enable-libiec61883 --enable-chromaprint --enable-frei0r --enable-libx264 --enable-shared
  libavutil      56. 70.100 / 56. 70.100
  libavcodec     58.134.100 / 58.134.100
  libavformat    58. 76.100 / 58. 76.100
  libavdevice    58. 13.100 / 58. 13.100
  libavfilter     7.110.100 /  7.110.100
  libswscale      5.  9.100 /  5.  9.100
  libswresample   3.  9.100 /  3.  9.100
  libpostproc    55.  9.100 / 55.  9.100
[x11grab @ 0x618d6e2979c0] Stream #0: not enough frames to estimate rate; consider increasing probesize
Input #0, x11grab, from ':0.0+420,0+nomouse':
  Duration: N/A, start: 1714673470.543033, bitrate: 1119744 kb/s
  Stream #0:0: Video: rawvideo (BGR[0] / 0x524742), bgr0, 1080x1080, 1119744 kb/s, 30 fps, 1000k tbr, 1000k tbn, 1000k tbc
Guessed Channel Layout for Input Stream #1.0 : stereo
Input #1, pulse, from 'default':
  Duration: N/A, start: 1714673470.670193, bitrate: 1536 kb/s
  Stream #1:0: Audio: pcm_s16le, 48000 Hz, stereo, s16, 1536 kb/s
Stream mapping:
  Stream #0:0 -> #0:0 (rawvideo (native) -> h264 (libx264))
  Stream #1:0 -> #0:1 (pcm_s16le (native) -> pcm_s16le (native))
Press [q] to stop, [?] for help
[libx264 @ 0x618d6e2b1300] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX FMA3 BMI2 AVX2
[libx264 @ 0x618d6e2b1300] profile High 4:4:4 Predictive, level 3.2, 4:4:4, 8-bit
[libx264 @ 0x618d6e2b1300] 264 - core 163 r3060 5db6aa6 - H.264/MPEG-4 AVC codec - Copyleft 2003-2021 - http://www.videolan.org/x264.html - options: cabac=0 ref=1 deblock=0:0:0 analyse=0:0 me=dia subme=0 psy=0 mixed_ref=0 me_range=16 chroma_me=1 trellis=0 8x8dct=0 cqm=0 deadzone=21,11 fast_pskip=0 chroma_qp_offset=0 threads=6 lookahead_threads=1 sliced_threads=0 nr=0 decimate=1 interlaced=0 bluray_compat=0 constrained_intra=0 bframes=0 weightp=0 keyint=250 keyint_min=25 scenecut=0 intra_refresh=0 rc=cqp mbtree=0 qp=0
Output #0, matroska, to '/home/gena2/rvideosrv/storage/salEh99z/salEh99z.mkv':
  Metadata:
    encoder         : Lavf58.76.100
  Stream #0:0: Video: h264 (H264 / 0x34363248), yuv444p(tv, progressive), 1080x1080, q=2-31, 30 fps, 1k tbn
    Metadata:
      encoder         : Lavc58.134.100 libx264
    Side data:
      cpb: bitrate max/min/avg: 0/0/0 buffer size: 0 vbv_delay: N/A
  Stream #0:1: Audio: pcm_s16le ([1][0][0][0] / 0x0001), 48000 Hz, stereo, s16, 1536 kb/s
    Metadata:
      encoder         : Lavc58.134.100 pcm_s16le
[x11grab @ 0x618d6e2979c0] Thread message queue blocking; consider raising the thread_queue_size option (current value: 8)
frame=  595 fps=4.1 q=0.0 size=  299264kB time=00:02:2frame=  618 fps=4.1 q=0.0 size=  310272kB time=00:02:31.75 bitrate=16748.9kbits/s dup=0 drop=51 speed=0.999x

以下是我尝试过的命令变体:

ffmpeg -f x11grab -framerate 30 -s 1920x1080 -i :0.0+0,0+nomouse -f pulse -ac 2 -i default -c:v libx264 -preset ultrafast -crf 0 -c:a pcm_s16le -y /home/user/cJE2wDqU.mkv

ffmpeg -f pulse -ac 2 -i default -f x11grab -r 30 -s 1920x1080 -i :0.0+0,0+nomouse -acodec aac -vcodec libx264 -b:a 320k -b:v 10M -ac 96000 -preset ultrafast -threads 2 -y /home/user/cJE2wDqU.mkv

我尝试设置threads 4,尝试设置crf,,,,——thread_queue_size但没有任何结果。probesizeb:v

也许我应该安装编解码器或者别的什么东西?

相关内容