You are not logged in.

#1 2020-12-29 23:27:40

icar
Member
Registered: 2020-07-31
Posts: 87

[Solved] Simple hw-accelerated program to record the screen?

I use Gnome and I appreciate the little feature it packs for "recording a short screencast" in one shortcut (press it once to start, another time to finish it) and gets saved into your videos folder. I want this simplicity for such a feature.
There are two cons, tho:

  • It has a maximum duration of around a minute (I haven't checked the exact number).

  • It is not hardware accelerated (you can tell by the CPU usage and the choppiness of the output as my laptop struggles to encode it).

For these two reasons, I set myself to find a substitute that, while retaining all the simplicity that Gnome Screencasting offers, it also doesn't have the limitations listed above.

Does anyone know any software that meet these requirements?
So far I have tried:

  • OBS, which works thanks to ffmpeg vaapi but it doesn't meet the requirements of simplicity

  • SimpleScreenRecorder, which has the same problem as OBS plus is not hardware accelerated

  • Peek, which doesn't use hw acceleration (checked htop which showed the command invoked ffmpeg ... didn't have any vaapi options enabled)

  • Creating my own script which has, so far, this:

    #!/bin/bash
    
    notify-send \
        --urgency=low \
        --icon=/usr/share/icons/Adwaita/512x512/mimetypes/video-x-generic.png \
        'Starting the recording...'
    
    echo "Press [q] to stop"
    
    ffmpeg -vaapi_device /dev/dri/renderD128 \
       -f x11grab \
       -video_size 1920x1080 -r 60 \
       -i :0 -vf 'hwupload,scale_vaapi=format=nv12' -c:v h264_vaapi -qp 24 \
       recording-`date '+%d-%m-%Y_%H:%M:%S'`.mp4 > /dev/null

    which I can assign to a keybind but has functionality problems, such as no way to stop it.

Last edited by icar (2021-01-03 23:18:33)

Offline

#2 2020-12-30 01:28:32

Ropid
Member
Registered: 2015-03-09
Posts: 987

Re: [Solved] Simple hw-accelerated program to record the screen?

You could have a second keybind with "killall ffmpeg" to stop the recording. The other idea I have is to wrap an "if" around your current script contents that checks for ffmpeg running. Here's what I'm thinking of:

#!/bin/bash

if pkill -x ffmpeg; then

    notify-send \
        --urgency=low \
        --icon=/usr/share/icons/Adwaita/512x512/mimetypes/video-x-generic.png \
        'Stopped the recording...'

else

    notify-send \
        --urgency=low \
        --icon=/usr/share/icons/Adwaita/512x512/mimetypes/video-x-generic.png \
        'Starting the recording...'

    ffmpeg -vaapi_device /dev/dri/renderD128 \
        -f x11grab \
        -video_size 1920x1080 -r 60 \
        -i :0 -vf 'hwupload,scale_vaapi=format=nv12' -c:v h264_vaapi -qp 24 \
        recording-`date '+%d-%m-%Y_%H:%M:%S'`.mp4 > /dev/null

fi

This runs pkill to (try to) stop an ffmpeg process. It uses pkill's exit status code to know if there was an ffmpeg process running or not.

This pkill idea will break things if there's other ffmpeg processes running because it will send signals to all ffmpeg processes. If that's a problem you could research how to save the PID of your ffmpeg process in a file like /tmp/screen-recording.pid, then use that file to do the "if-then-else" logic and the killing.

Reading your post here, I remembered seeing the following script, maybe check it out and see if there's something you can take from it for your own script:

https://github.com/MAPReiff/ShadowRePlay-Linux

Offline

#3 2020-12-30 09:32:55

icar
Member
Registered: 2020-07-31
Posts: 87

Re: [Solved] Simple hw-accelerated program to record the screen?

Thanks for the ideas!
Seeing the complexity that this requires for such a functionality I might aswell start using something like Python.
New personal project smile

Offline

#4 2020-12-30 13:29:32

Lone_Wolf
Member
From: Netherlands, Europe
Registered: 2005-10-04
Posts: 8,916

Re: [Solved] Simple hw-accelerated program to record the screen?

A quick search for simplescreenrecorder alternatives lead me to https://linuxecke.volkoh.de/vokoscreen/vokoscreen.html .
It's in community and looks simple to configure but powerful.

You may find https://wiki.archlinux.org/index.php/Sc … t_software interesting .

Last edited by Lone_Wolf (2020-12-30 13:30:02)


Disliking systemd intensely, but not satisfied with alternatives so focusing on taming systemd.

(A works at time B)  && (time C > time B ) ≠  (A works at time C)

Offline

#5 2021-01-02 20:04:46

icar
Member
Registered: 2020-07-31
Posts: 87

Re: [Solved] Simple hw-accelerated program to record the screen?

I've been trying to do this with bash. So far I've got this, which is giving me a headache because for some reason ffmpeg exits generating an empty output...

Script:

       │ File: /home/icar/Scripts/recordscreen
───────┼──────────────────────────────────────────────────────────────────────────────────────
   1   │ #!/bin/bash
   2   │ 
   3   │ if [ -e $HOME/.cache/fifo-recording ]; then
   4   │ 
   5   │    echo -n q > $HOME/.cache/fifo-recording
   6   │ 
   7   │    notify-send --urgency=low --icon=/usr/share/icons/Adwaita/512x512/mimetypes/video-
       │ x-generic.png 'Stopping the recording...'
   8   │     
   9   │    rm -f $HOME/.cache/fifo-recording
  10   │ 
  11   │ else
  12   │     
  13   │     notify-send \
  14   │         --urgency=low \
  15   │         --icon=/usr/share/icons/Adwaita/512x512/mimetypes/video-x-generic.png \
  16   │         'Starting the recording...'
  17   │ 
  18   │     rm -f $HOME/.cache/fifo-recording
  19   │     mkfifo $HOME/.cache/fifo-recording
  20   │     mkdir -p $HOME/Vídeos/ffmpeg
  21   │ 
  22   │     exec ffmpeg -vaapi_device /dev/dri/renderD128 \
  23   │         -f x11grab \
  24   │         -video_size 1920x1080 -r 60 \
  25   │         -i :0 -vf 'hwupload,scale_vaapi=format=nv12' -c:v h264_vaapi -qp 24 \
  26   │         $HOME/Vídeos/ffmpeg/recording-`date '+%d-%m-%Y_%H:%M:%S'`.mp4 \
  27   │         < $HOME/.cache/fifo-recording 
  28   │ 
  29   │ fi

It starts correctly, but when the script is executed again, ffmpeg throws this:

ffmpeg version n4.3.1 Copyright (c) 2000-2020 the FFmpeg developers
  built with gcc 10.2.0 (GCC)
  configuration: --prefix=/usr --disable-debug --disable-static --disable-stripping --enable-amf --enable-avisynth --enable-cuda-llvm --enable-lto --enable-fontconfig --enable-gmp --enable-gnutls --enable-gpl --enable-ladspa --enable-libaom --enable-libass --enable-libbluray --enable-libdav1d --enable-libdrm --enable-libfreetype --enable-libfribidi --enable-libgsm --enable-libiec61883 --enable-libjack --enable-libmfx --enable-libmodplug --enable-libmp3lame --enable-libopencore_amrnb --enable-libopencore_amrwb --enable-libopenjpeg --enable-libopus --enable-libpulse --enable-librav1e --enable-libsoxr --enable-libspeex --enable-libsrt --enable-libssh --enable-libtheora --enable-libv4l2 --enable-libvidstab --enable-libvmaf --enable-libvorbis --enable-libvpx --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxcb --enable-libxml2 --enable-libxvid --enable-nvdec --enable-nvenc --enable-shared --enable-version3
  libavutil      56. 51.100 / 56. 51.100
  libavcodec     58. 91.100 / 58. 91.100
  libavformat    58. 45.100 / 58. 45.100
  libavdevice    58. 10.100 / 58. 10.100
  libavfilter     7. 85.100 /  7. 85.100
  libswscale      5.  7.100 /  5.  7.100
  libswresample   3.  7.100 /  3.  7.100
  libpostproc    55.  7.100 / 55.  7.100
[x11grab @ 0x563cc11d5b00] Stream #0: not enough frames to estimate rate; consider increasing probesize
Input #0, x11grab, from ':0':
  Duration: N/A, start: 1609617807.078819, bitrate: 3981312 kb/s
    Stream #0:0: Video: rawvideo (BGR[0] / 0x524742), bgr0, 1920x1080, 3981312 kb/s, 60 fps, 1000k tbr, 1000k tbn, 1000k tbc
Stream mapping:
  Stream #0:0 -> #0:0 (rawvideo (native) -> h264 (h264_vaapi))
Press [q] to stop, [?] for help
Finishing stream 0:0 without any data written to it.
[h264_vaapi @ 0x563cc11bb940] Driver does not support some wanted packed headers (wanted 0xd, found 0x1).
Output #0, mp4, to '/home/icar/Vídeos/ffmpeg/recording-02-01-2021_21:03:19.mp4':
  Metadata:
    encoder         : Lavf58.45.100
    Stream #0:0: Video: h264 (h264_vaapi) (High) (avc1 / 0x31637661), vaapi_vld, 1920x1080, q=-1--1, 60 fps, 15360 tbn, 60 tbc
    Metadata:
      encoder         : Lavc58.91.100 h264_vaapi
frame=    0 fps=0.0 q=0.0 Lsize=       0kB time=00:00:00.00 bitrate=N/A speed=   0x    
video:0kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: unknown

The ffmpeg command alone works ok... Could I have any suggestion? I'd appreciate it.

Offline

#6 2021-01-02 20:27:23

progandy
Member
Registered: 2012-05-17
Posts: 4,145

Re: [Solved] Simple hw-accelerated program to record the screen?

Peek, which doesn't use hw acceleration (checked htop which showed the command invoked ffmpeg ... didn't have any vaapi options enabled)

It shouldn't be too difficult to change the ffmpeg options in the source code and compile your own version (for example with the peek-git AUR package)
https://github.com/phw/peek/blob/master … g.vala#L11

and maybe some changes here https://github.com/phw/peek/blob/master … order.vala

Last edited by progandy (2021-01-02 20:28:45)


| alias CUTF='LANG=en_XX.UTF-8@POSIX ' |

Offline

#7 2021-01-02 21:05:53

icar
Member
Registered: 2020-07-31
Posts: 87

Re: [Solved] Simple hw-accelerated program to record the screen?

progandy wrote:

Peek, which doesn't use hw acceleration (checked htop which showed the command invoked ffmpeg ... didn't have any vaapi options enabled)

It shouldn't be too difficult to change the ffmpeg options in the source code and compile your own version (for example with the peek-git AUR package)
https://github.com/phw/peek/blob/master … g.vala#L11

and maybe some changes here https://github.com/phw/peek/blob/master … order.vala

Thanks for the suggestion. I was modifying it and was looking good, but then I realized I can't do a one-liner to record the whole screen. Looking at the man page one could think of

peek --backend=ffmpeg --start --no-headerbar --display=:0

but that actually requires the application to be already running because it needs to read the coordinates at runtime... Which defeats the idea I'm trying to pursue. I still think that it could be achieved through bash, but if after a couple days trying I cannot make it work, I'll start developing something like a Rust (since I've started to learn it) or Python program.

Offline

#8 2021-01-02 21:40:17

icar
Member
Registered: 2020-07-31
Posts: 87

Re: [Solved] Simple hw-accelerated program to record the screen?

Ok, I've finally done it. A script to do this. The only thing to be done now is to refine the ffmpeg flags, which is not part of the main problem.

Usage: call it once, it starts recording. Call it again, it stops. (you will obviously have to adjust to your system)
           Best idea is to bind this to a key combination with your WM/DE.

#!/bin/bash

if [ -e $HOME/.cache/ffmpeg-pid ]; then

    kill -15 $(cat $HOME/.cache/ffmpeg-pid)

    notify-send \
        --urgency=low \
        --icon=/usr/share/icons/Adwaita/512x512/mimetypes/video-x-generic.png \
        'Stopping the recording...'
    
    rm -f $HOME/.cache/ffmpeg-pid

else
    
    notify-send \
        --urgency=low \
        --icon=/usr/share/icons/Adwaita/512x512/mimetypes/video-x-generic.png \
        'Starting the recording...'

    mkdir -p $HOME/Vídeos/ffmpeg

    echo $$ > $HOME/.cache/ffmpeg-pid
    
    exec ffmpeg -vaapi_device /dev/dri/renderD128 \
        -f x11grab \
        -video_size 1920x1080 -r 60 \
        -i :0 -vf 'hwupload,scale_vaapi=format=nv12' -c:v h264_vaapi -qp 24 \
        -fs 1000000000 \
        $HOME/Vídeos/ffmpeg/recording-`date '+%d-%m-%Y_%H:%M:%S'`.mp4

fi

Last edited by icar (2021-01-02 21:40:59)

Offline

Board footer

Powered by FluxBB