From 48803ababd17ea02fd0de9808e52b75c7a576ae7 Mon Sep 17 00:00:00 2001 From: mhdzli <50514359+mhdzli@users.noreply.github.com> Date: Sun, 26 Jan 2020 17:38:03 +0330 Subject: [PATCH] Add vaapi recording functions Hardware video acceleration makes it possible for the video card to decode/encode video, thus offloading the CPU and saving power. There is a brief reference with practical useful information in [Arch wiki](https://wiki.archlinux.org/index.php/Vaapi). These changes mostly inspired by [Kai Henry](https://github.com/kaihendry/recordmydesktop2.0) and [Simon Hugh's](https://github.com/simonhughcom/dmenu-bin/blob/master/recordmenu) scripts. --- .local/bin/dmenurecord | 44 ++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 42 insertions(+), 2 deletions(-) diff --git a/.local/bin/dmenurecord b/.local/bin/dmenurecord index 7e80f3c8..04948ea9 100755 --- a/.local/bin/dmenurecord +++ b/.local/bin/dmenurecord @@ -24,6 +24,7 @@ killrecording() { # even after SIGTERM, ffmpeg may still run, so SIGKILL it. sleep 3 kill -9 "$recpid" + pkill swcursor exit } @@ -41,6 +42,27 @@ screencast() { \ updateicon "⏺️🎙️" } +vaapicast() { \ + #Relies on https://github.com/andykitchen/swcursor for showing a readable cursor. (Assuming that you put the swcursor and cursor.png in $HOME/.local/bin) So if you need the cussor uncomment these lines or you can use the x11grab: +# cd $HOME/.local/bin/ +# swcursor & + ffmpeg -y \ + -f alsa -i default \ + -f kmsgrab \ + -i - \ + -vaapi_device /dev/dri/renderD128 \ + -video_size $(xdpyinfo | grep dimensions | awk '{print $2;}') \ + -filter:v hwmap,scale_vaapi=format=nv12 \ + -framerate 60 \ + -r 30 \ + -c:a aac -crtc_id 48 -c:v h264_vaapi \ + "$HOME/screencast-$(date '+%y%m%d-%H%M-%S').mp4" & +# If you need the cursor you can use this command: +# ffmpeg -y -vaapi_device /dev/dri/renderD128 -f x11grab -video_size $(xdpyinfo | grep dimensions | awk '{print $2;}') -framerate 60 -r 30 -i $DISPLAY -f alsa -i default -vf 'hwupload,scale_vaapi=format=nv12' -c:v h264_vaapi -qp 24 -c:a aac -f mp4 "$HOME/screencast-$(date '+%y%m%d-%H%M-%S').mp4" & + echo $! > /tmp/recordingpid + updateicon "⏺️🎙️" +} + video() { ffmpeg \ -f x11grab \ -s $(xdpyinfo | grep dimensions | awk '{print $2;}') \ @@ -51,6 +73,23 @@ video() { ffmpeg \ updateicon "⏺️" } +vaapivideo() { \ + ffmpeg -y \ + -f kmsgrab \ + -i - \ + -vaapi_device /dev/dri/renderD128 \ + -video_size $(xdpyinfo | grep dimensions | awk '{print $2;}') \ + -filter:v hwmap,scale_vaapi=format=nv12 \ + -framerate 60 \ + -r 30 \ + -c:v h264_vaapi \ + "$HOME/screencast-$(date '+%y%m%d-%H%M-%S').mp4" & +# If you need the cursor you can use this command: +# ffmpeg -y -vaapi_device /dev/dri/renderD128 -f x11grab -video_size $(xdpyinfo | grep dimensions | awk '{print $2;}') -framerate 60 -i $DISPLAY -vf 'hwupload,scale_vaapi=format=nv12' -c:v h264_vaapi -qp 24 -f matroska "$HOME/video-$(date '+%y%m%d-%H%M-%S').mkv" & + echo $! > /tmp/recordingpid + updateicon "⏺️" + } + webcamhidef() { ffmpeg \ -f v4l2 \ -i /dev/video0 \ @@ -69,7 +108,6 @@ webcam() { ffmpeg \ updateicon "🎥" } - audio() { \ ffmpeg \ -f alsa -i default \ @@ -80,13 +118,15 @@ audio() { \ } askrecording() { \ - choice=$(printf "screencast\\nvideo\\naudio\\nwebcam\\nwebcam (hi-def)" | dmenu -i -p "Select recording style:") + choice=$(printf "screencast\\nvideo\\naudio\\nwebcam\\nwebcam (hi-def)\\nvaapicast\\nvaapivideo\\nwindow" | dmenu -i -p "Select recording style:") case "$choice" in screencast) screencast;; audio) audio;; video) video;; webcam) webcam;; "webcam (hi-def)") webcamhidef;; + vaapicast) vaapicast;; + vaapivideo) vaapivideo;; esac }