High CPU load even though hardware acceleration is used
System Info
- Kooha version (2.0.0, or including the commit hash if applicable) 1.2.1
- Distro information and version (Fedora 34 Workstation, etc.) Manjaro
- Desktop Environment information and version (GNOME 41, etc.) Gnome - Wayland
- Display Server (Wayland, etc.) Wayland
- Flatpak? No
Describe the bug First things first: Thank you for the first screen capture tool that actually works under Wayland :heart: However, when i start a screen record on my (4K) display, the CPU load is quite high and leads to stuttering: around 20-30% on an Intel 8600k. When i do a screen share with Firefox (e.g.) the CPU load is at about 15% which is quite a significant difference. I am not sure if that's because Kooha is using a higher resolution or framerate (I use the default settings, so no 60fps).
I tried enabling hardware acceleration and switched to MP4 (all other containers had no encoder) but it didn't change much to the system load. I am not really sure if it's really used, that's why i attach the logs below.
I enabled dma-buf screensharing if that could help Kooha:
~ ❯ gsettings get org.gnome.mutter experimental-features
['scale-monitor-framebuffer', 'dma-buf-screen-sharing']
To Reproduce Steps to reproduce the behavior:
- Start Kooha with the comand from the logs below.
- Start a recording
Expected behavior The system load should be lower if possible.
Screenshots If applicable, add screenshots to help explain your problem.
Additional context
~ ❯ RUST_BACKTRACE=1 RUST_LOG=kooha=debug GST_DEBUG=3 PIPEWIRE_DEBUG=3 kooha
INFO kooha::application > Kooha (io.github.seadve.Kooha)
INFO kooha::application > Version: 1.2.1 ()
INFO kooha::application > Datadir: /usr/local/share/kooha
DEBUG kooha::backend::recorder > is_show_pointer: true
DEBUG kooha::backend::recorder > is_selection_mode: false
INFO kooha::backend::screencast_portal > ScreenCastProxy created
INFO kooha::backend::screencast_portal > Session created
INFO kooha::backend::screencast_portal > Select sources window showed
INFO kooha::backend::screencast_portal > Screencast session started
INFO kooha::backend::screencast_portal > Ready for pipewire stream
DEBUG kooha::backend::recorder > pulse_server_version: pulseaudio version 15.0
DEBUG kooha::backend::recorder > PipelineBuilder { is_record_speaker: false, is_record_mic: false, framerate: 30, file_path: "/home/laurenz/Videos/Kooha 02-21-2022 21:00:37.mp4", fd: 20, streams: [Stream { pipewire_node_id: 38, position: Some((0, 0)), size: Some((3072, 1728)) }], speaker_source: Some("alsa_output.pci-0000_00_1f.3.analog-surround-21.monitor"), mic_source: Some("alsa_input.usb-Sonix_Technology_Co.__Ltd._USB_2.0_Camera_SN0001-02.analog-stereo"), coordinates: None, actual_screen: None }
DEBUG kooha::backend::pipeline_builder > is_use_vaapi: false
DEBUG kooha::backend::pipeline_builder > pipeline_string: queue name=queue0 ! videorate ! video/x-raw, framerate=30/1 ! videoconvert chroma-mode=GST_VIDEO_CHROMA_MODE_NONE dither=GST_VIDEO_DITHER_NONE matrix-mode=GST_VIDEO_MATRIX_MODE_OUTPUT_ONLY n-threads=6 ! queue ! x264enc qp-max=17 speed-preset=superfast threads=6 ! video/x-h264, profile=baseline ! queue ! mp4mux name=mux ! filesink name=filesink location="/home/laurenz/Videos/Kooha 02-21-2022 21:00:37.mp4" pipewiresrc fd=20 path=38 do-timestamp=true keepalive-time=1000 resend-last=true ! video/x-raw, max-framerate=30/1 ! queue0.
[I][24305.285387] pw.context | [ pipewire.c: 668 pw_init()] version 0.3.45
[I][24305.289931] pw.conf | [ conf.c: 414 conf_load()] 0x563ee3654280: loaded config '/usr/share/pipewire/client.conf' with 5 items
[I][24305.289990] pw.conf | [ conf.c: 830 pw_context_conf_section_for_each()] handle config '/usr/share/pipewire/client.conf' section 'context.properties'
[I][24305.290015] pw.context | [ context.c: 277 pw_context_new()] 0x563ee39f92f0: parsed 1 context.properties items
[I][24305.290498] pw.conf | [ conf.c: 830 pw_context_conf_section_for_each()] handle config '/usr/share/pipewire/client.conf' section 'context.spa-libs'
[I][24305.290566] pw.context | [ context.c: 375 pw_context_new()] 0x563ee39f92f0: parsed 2 context.spa-libs items
[I][24305.290587] pw.conf | [ conf.c: 830 pw_context_conf_section_for_each()] handle config '/usr/share/pipewire/client.conf' section 'context.modules'
[I][24305.291117] pw.conf | [ conf.c: 567 load_module()] 0x563ee39f92f0: loaded module libpipewire-module-protocol-native
[I][24305.291707] pw.conf | [ conf.c: 567 load_module()] 0x563ee39f92f0: loaded module libpipewire-module-client-node
[I][24305.292032] pw.conf | [ conf.c: 567 load_module()] 0x563ee39f92f0: loaded module libpipewire-module-client-device
[I][24305.292405] pw.conf | [ conf.c: 567 load_module()] 0x563ee39f92f0: loaded module libpipewire-module-adapter
[I][24305.292745] pw.conf | [ conf.c: 567 load_module()] 0x563ee39f92f0: loaded module libpipewire-module-metadata
[I][24305.293150] pw.conf | [ conf.c: 567 load_module()] 0x563ee39f92f0: loaded module libpipewire-module-session-manager
[I][24305.293180] pw.context | [ context.c: 379 pw_context_new()] 0x563ee39f92f0: parsed 6 context.modules items
[I][24305.293197] pw.context | [ context.c: 384 pw_context_new()] 0x563ee39f92f0: parsed 0 context.objects items
[I][24305.293214] pw.context | [ context.c: 387 pw_context_new()] 0x563ee39f92f0: parsed 0 context.exec items
[I][24305.293270] pw.context | [ context.c: 136 context_set_freewheel()] 0x563ee39f92f0: exit freewheel
[I][24305.293299] pw.context | [ context.c: 141 context_set_freewheel()] 0x563ee39f92f0: freewheel error:Die Operation wird nicht unterstützt
[I][24305.293326] pw.metadata | [ impl-metadata.c: 205 impl_set_property()] 0x563ee3a14690: add id:0 key:log.level type: value:0
[I][24305.293345] pw.metadata | [ impl-metadata.c: 205 impl_set_property()] 0x563ee3a14690: add id:0 key:clock.rate type: value:48000
[I][24305.293364] pw.metadata | [ impl-metadata.c: 205 impl_set_property()] 0x563ee3a14690: add id:0 key:clock.allowed-rates type: value:[ 48000 ]
[I][24305.293380] pw.metadata | [ impl-metadata.c: 205 impl_set_property()] 0x563ee3a14690: add id:0 key:clock.quantum type: value:1024
[I][24305.293397] pw.metadata | [ impl-metadata.c: 205 impl_set_property()] 0x563ee3a14690: add id:0 key:clock.min-quantum type: value:32
[I][24305.293414] pw.metadata | [ impl-metadata.c: 205 impl_set_property()] 0x563ee3a14690: add id:0 key:clock.max-quantum type: value:2048
[I][24305.293456] pw.metadata | [ impl-metadata.c: 205 impl_set_property()] 0x563ee3a14690: add id:0 key:clock.force-quantum type: value:0
[I][24305.293474] pw.metadata | [ impl-metadata.c: 205 impl_set_property()] 0x563ee3a14690: add id:0 key:clock.force-rate type: value:0
[I][24305.293654] pw.conf | [ conf.c: 830 pw_context_conf_section_for_each()] handle config '/usr/share/pipewire/client.conf' section 'stream.properties'
0:00:04.117807509 41823 0x7fe23c52f060 FIXME default gstutils.c:4025:gst_pad_create_stream_id_internal:<pipewiresrc0:src> Creating random stream-id, consider implementing a deterministic way of creating a stream-id
[I][24305.298888] pw.stream | [ stream.c: 550 impl_send_command()] 0x563ee3a28bc0: command Spa:Pod:Object:Command:Node:Start
[I][24305.299055] pw.node | [ impl-node.c: 378 node_update_state()] (kooha-0) creating -> running
INFO kooha::backend::recorder > Pipeline state set from Null -> Ready
INFO kooha::backend::recorder > Pipeline state set from Ready -> Paused
0:00:04.376261379 41823 0x7fe23c52f120 WARN x264enc :0::<x264enc0> VBV underflow (frame 0, -3428008 bits)
0:00:04.376898403 41823 0x7fe23c408920 FIXME basesink gstbasesink.c:3388:gst_base_sink_default_event:<filesink> stream-start event without group-id. Consider implementing group-id handling in the upstream elements
0:00:04.376952606 41823 0x7fe23c408920 WARN qtmux gstqtmux.c:3076:gst_qt_mux_start_file:<mux> Robust muxing requires reserved-moov-update-period to be set
0:00:04.377397753 41823 0x7fe23c408920 FIXME aggregator gstaggregator.c:1365:gst_aggregator_aggregate_func:<mux> Subclass should call gst_aggregator_selected_samples() from its aggregate implementation.
INFO kooha::backend::recorder > Pipeline state set from Paused -> Playing
0:00:04.399524888 41823 0x7fe23c52f120 WARN x264enc :0::<x264enc0> VBV underflow (frame 1, -9653 bits)
0:00:04.495609310 41823 0x7fe23c52f120 WARN x264enc :0::<x264enc0> VBV underflow (frame 3, -4695803 bits)
0:00:04.530377485 41823 0x7fe23c52f120 WARN x264enc :0::<x264enc0> VBV underflow (frame 4, -3530181 bits)
0:00:04.542122486 41823 0x7fe23c52f120 WARN x264enc :0::<x264enc0> VBV underflow (frame 5, -47109 bits)
0:00:04.716261812 41823 0x7fe23c52f120 WARN x264enc :0::<x264enc0> VBV underflow (frame 10, -3792763 bits)
0:00:04.801287659 41823 0x7fe23c52f120 WARN x264enc :0::<x264enc0> VBV underflow (frame 13, -2449240 bits)
0:00:04.889383033 41823 0x7fe23c52f120 WARN x264enc :0::<x264enc0> VBV underflow (frame 15, -2604107 bits)
[...]
INFO kooha::backend::recorder > Sending eos event to pipeline
0:00:12.022222172 41823 0x7fe23c52f120 WARN x264enc :0::<x264enc0> VBV underflow (frame 229, -239003 bits)
0:00:12.046499296 41823 0x7fe23c52f120 WARN x264enc :0::<x264enc0> VBV underflow (frame 231, -210395 bits)
0:00:12.049942130 41823 0x7fe23c52f120 WARN x264enc :0::<x264enc0> VBV underflow (frame 233, -209515 bits)
[I][24313.245446] pw.stream | [ stream.c: 550 impl_send_command()] 0x563ee3a28bc0: command Spa:Pod:Object:Command:Node:Pause
[I][24313.245493] pw.node | [ impl-node.c: 378 node_update_state()] (kooha-0) running -> idle
[I][24313.251354] pw.stream | [ stream.c: 550 impl_send_command()] 0x563ee3a28bc0: command Spa:Pod:Object:Command:Node:Suspend
[I][24313.251387] pw.node | [ impl-node.c: 378 node_update_state()] (kooha-0) idle -> suspended
[I][24313.251518] pw.node | [ impl-node.c: 1816 pw_impl_node_destroy()] (kooha-0) destroy
INFO kooha::backend::screencast_portal > Session closed
INFO kooha::backend::recorder > Eos signal received from record bus
Edit: I just tried recording a single window instead of the whole screen, which is even worse. Now the CPU spikes go up to 60%