Script to record a window + audio in Linux (Solved)

Audio editors, music players, video players, burning software, etc.
Post Reply
Message
Author
labbe5
Posts: 2159
Joined: Wed 13 Nov 2013, 14:26
Location: Canada

Script to record a window + audio in Linux (Solved)

#1 Post by labbe5 »

https://lukas.zapletalovi.com/2019/11/s ... linux.html
Simple script to record a window and audio in Linux

#!/bin/bash

NAME=screencast-$(date +%Y%m%d%H%M)
FPS=10
THREADS=7

echo "Click the window to capture and get ready!"

tmpfile=/tmp/screengrab.tmp.$$
trap 'touch $tmpfile; rm -f $tmpfile' 0

xwininfo > $tmpfile 2>/dev/null
left=$(grep 'Absolute upper-left X:' $tmpfile | awk '{print $4}');
top=$(grep 'Absolute upper-left Y:' $tmpfile | awk '{print $4}');
width=$(grep 'Width:' $tmpfile | awk '{print $2}');
height=$(grep 'Height:' $tmpfile | awk '{print $2}');
geom="-geometry ${width}x${height}+${left}+${top}"
echo "Geometry: ${geom}"
size="${width}x${height}"
pos="${left},${top}"
echo "pos=$pos size=$size"

ffmpeg -y -f pulse -ac 2 -i default -f x11grab -r $FPS -s $size -i ${DISPLAY-0:0}+${pos} -acodec pcm_s16le $NAME-temp.wav -an -vcodec libx264 -preset ultrafast -threads 0 $NAME-temp.mp4

echo Merge audio+video and encode to webm for YouTube? && read

ffmpeg -i $NAME-temp.mp4 -i $NAME-temp.wav -acodec libvorbis -ab 128k -ac 2 -vcodec libvpx -threads $THREADS $NAME.webm

User avatar
don570
Posts: 5528
Joined: Wed 10 Mar 2010, 19:58
Location: Ontario

#2 Post by don570 »

The script is listed on git
https://raw.githubusercontent.com/lzap/ ... cordwindow
___________________________________

press the key 'q' to go to the second stage of combining the two files.
_______________________________________________________

User avatar
takenp
Posts: 101
Joined: Wed 05 Aug 2015, 23:27
Location: Moskva
Contact:

#3 Post by takenp »

The above ffmpeg command utilizes pulse audio server that is not present on the most puppies by default. Plus in most cases we just need to capture whole screen with sound/mic.

So here is just a single command line to achieve this goal on every puppy that has ffmpeg installed:

Code: Select all

ffmpeg -f alsa -ac 2 -i hw:0,0 -f x11grab -r 30 -s $(xwininfo -root | grep 'geometry'| awk '{print $2;}') -i :0.0 -acodec libmp3lame -ab 128k -vcodec libx264 -vpre lossless_ultrafast -threads 2 -y output.avi
to recognize which hw card/device numbers to use type

Code: Select all

aplay -l
and choose appropriate card and device number 0,0 or 0,1 etc.

have fun!

User avatar
soniabu
Posts: 162
Joined: Thu 01 Feb 2018, 21:24
Location: Paris

#4 Post by soniabu »

I tried the command but it answers me this:
Image

User avatar
takenp
Posts: 101
Joined: Wed 05 Aug 2015, 23:27
Location: Moskva
Contact:

#5 Post by takenp »

[quote=":0.0: Invalid argument[/quote]

try remove -i :0.0

or

:0,0

User avatar
don570
Posts: 5528
Joined: Wed 10 Mar 2010, 19:58
Location: Ontario

#6 Post by don570 »

replying to soniabu

I have a Dell 990 desktop machine and it can't record the audio at the same time as video.

________________________________________

User avatar
soniabu
Posts: 162
Joined: Thu 01 Feb 2018, 21:24
Location: Paris

#7 Post by soniabu »

thx all

User avatar
Flash
Official Dog Handler
Posts: 13071
Joined: Wed 04 May 2005, 16:04
Location: Arizona USA

#8 Post by Flash »

Thx for what? Is your problem solved?

User avatar
soniabu
Posts: 162
Joined: Thu 01 Feb 2018, 21:24
Location: Paris

#9 Post by soniabu »

yes solved, I use SSR in multimedia section on my bionicpup64.
here: http://murga-linux.com/puppy/viewtopic. ... 26#1049326

Post Reply