how to ScreenCast


Screencast with FFmpeg

fist of all when you have found your ffmpeg string you should create an easy command and create shortcut using alias

kate  ~/.bashrc

now add the line you will use …

alias screenrecoder="ffmpeg PARAMETERS"

for example i have

alias screenrecoder="ffmpeg -s $(xrandr  | awk '/, current /{ gsub(/\,/,""); print $8"x"$10}') -f x11grab -r 30  -i :0.0  -vcodec  ljpeg  -y  $HOME/output.avi"

and if you want convert for youtube it should be fine this

alias youtubeconverter="ffmpeg -i  \"$HOME/output.avi\" -sameq -y $HOME/output.webm"

now just do thsi to load the new alias into the shell

source  ~/.bashrc

if you will type screenrecoder it will load ffmpeg with your own parameters.

Some example we will analyze

this should work with the most of ffmpeg WITHOUT AUDIO

ffmpeg   -s $(xrandr  | awk '/, current /{ gsub(/\,/,""); print $8"x"$10}') -f x11grab -r 25  -i :0.0  -vcodec  ljpeg output.avi 

this is use ljpeg for video codec and wav uncompressed audio codec so it’s faster … but it create huge files : if you need to create screencast to edit you could use this… expecially if you have an old machine

ffmpeg -f  alsa  -ac 2 -ar 48000  -i hw:0,0   -s $(xrandr  | awk '/, current /{ gsub(/\,/,""); print $8"x"$10}') -f x11grab -r 15  -i :0.0 -acodec pcm_s16le -vcodec  ljpeg output.avi 

this will use sampling rate to 48000 usefull if you card got sound noise (tic tic) and it uses x264 codec so it creates a smaller file

 ffmpeg -f  alsa  -ac 2 -ar 48000  -i hw:0,0   -s $(xrandr  | awk '/, current /{ gsub(/\,/,""); print $8"x"$10}') -f x11grab -r 15  -i :0.0 -acodec pcm_s16le -vcodec libx264 -vpre lossless_ultrafast  -threads 2 output.avi 

in this case we have pulse like sound stuff instead of alsa

ffmpeg -f alsa -ac 2 -i pulse -s $(xrandr  | awk '/, current /{ gsub(/\,/,""); print $8"x"$10}') -f x11grab -r 15  -i :0.0 -acodec pcm_s16le -vcodec libx264 -vpre lossless_ultrafast -threads 0 output.avi

in this example i am using different mic , and an external monitor so -s option MUST BE BEFORE -f x11grab or x11grab before captures only 640×480 then it resize to 1920×1080…

alias hdmirec="ffmpeg -f alsa -ac 1 -ar 48000 -i hw:2,0  -s 1920x1080  -f x11grab -i :0  -r 15  -vcodec libx264 test.mp4"

this is a script that can detect a windows id and so record only a portion of your screen

    #!/bin/sh

    INFO=$(xwininfo -frame)

    WIN_GEO=$(echo $INFO | grep -oEe 'geometry [0-9]+x[0-9]+' | grep -oEe '[0-9]+x[0-9]+')
    WIN_XY=$(echo $INFO | grep -oEe 'Corners:\s+\+[0-9]+\+[0-9]+' | grep -oEe '[0-9]+\+[0-9]+' | sed -e 's/\+/,/' )

    ffmpeg -f alsa -ac 2 -i hw:0,0 -f x11grab -r 30 -s $WIN_GEO -i :0.0+$WIN_XY -acodec pcm_s16le -vcodec libx264 -vpre lossless_ultrafast -threads 0 -y output-single.mkv

how to understand parameters

this is the part of audio capture

 ffmpeg -f  alsa  -ac 2 -ar 48000  -i hw:0,0 

here it says to use alsa like driver double channel instead of mono for some cards you shoudl use mono so …-ac 1
ar 48000 it’s the frequency and for some card it’s better use 48000 instead of 41000 to avoid noises

hw:0,0 is the location of your audio capture device

get your audio capture card “location”:

 cat /proc/asound/pcm 

i get

 00-00: ALC861-VD Analog : ALC861-VD Analog : playback 1 : capture 1
00-06: Si3054 Modem : Si3054 Modem : playback 1 : capture 1
01-00: USB Audio : USB Audio : capture 1

so i have want alc861vd so i have to use -i hw:0,0

the part it’s only your scren resolution …try to do you will understand

echo $(xrandr  | awk '/, current /{ gsub(/\,/,""); print $8"x"$10}')

the part

 -f x11grab -r 15 -i :0.0

says to ffmpeg to grab you destkop and set the frame rate to 15 frame for second and gives to ffpeg the location of the screen 0.0 (you could have another monitor o xserver the most have 0.0)

the part

 -acodec pcm_s16le -vcodec ljpeg output.avi 

it’s only the audio codec and the video codec 🙂

the part

 -threads 2  output.avi

says to ffmpeg to use dual core and output.avi…well i dunno 😀

you could add -vf scale:640:480 this is usefull to grab for example 1280 for 800 and rescaling the video on the fly and to keep your video skinny

 ffmpeg -f  alsa -ac 2 -ar 48000  -i hw:0,0   -s $(xrandr  | awk '/, current /{ gsub(/\,/,""); print $8"x"$10}') -f x11grab -r 15  -i :0.0 -acodec pcm_s16le -vcodec libx264 -vpre lossless_ultrafast  -vf scale=640:480  -y  output.avi
 

ScreenCast gif FFMPEG

fullscreen mode

sleep $1 && ffmpeg    -s $(xrandr  | awk '/, current /{ gsub(/\,/,""); print $8"x"$10}') -f x11grab -r 10  -i :0.0 -b 500k -pix_fmt rgb24 -y -loop_output 0 output.gif

gif scaled to 640*480

sleep $1 && ffmpeg    -s $(xrandr  | awk '/, current /{ gsub(/\,/,""); print $8"x"$10}') -f x11grab -r 10  -i :0.0 -b 500k -pix_fmt rgb24 -y -loop_output 0 -vf scale=640:480 output.gif

create gif

byzanz-record  --delay=3 --duration=8 --cursor  plasma_howto-throw-ball.gif

record only audio with ffmpeg

ffmpeg -f  alsa  -ac 2 -ar 48000  -i hw:0,0   -acodec pcm_s16le -vn audio_recording.wav 

And if you have mp3 support ( to undersand the codec name for example for mp3 … ffmpeg -codecs | grep mp3 i get :: EA libmp3lame libmp3lame MP3 (MPEG audio layer 3) where EA means encoder … if you have not E you can’t use any mp3 encoder… )
)

ffmpeg -f  alsa  -ac 2 -ar 48000  -i hw:0,0   -acodec libmp3lame -vn audio_recording.mp3 

if you have aac support ( to undersand the codec name for example for mp3 … ffmpeg -codecs | grep mp3 i get :: DEA aac Advanced Audio Coding
where DEA means encoder … if you have not E you can’t use any AAC encoder… )

ffmpeg -f  alsa  -ac 2 -ar 48000  -i hw:0,0   -acodec aac -vn audio_recording.aac 

Record only video without audio

ffmpeg  -an    -s $(xrandr  | awk '/, current /{ gsub(/\,/,""); print $8"x"$10}') -f x11grab -r 25  -i :0.0 -acodec pcm_s16le -vcodec  ljpeg output.avi 

Cropping and scaling
here i had a video 1280 for 800 pixel and i have cropped 60 pixel from the video and scaled it to original resolution

ffmpeg -i output.avi -sameq -vf crop=1280:740,scale=1280:800   metal_krita.webm 

testing your webcam (i had a logitech ) without to save files

ffplay -f alsa -ac 2   -f video4linux2 -i /dev/video0  

One Response to how to ScreenCast

  1. KillJoy says:

    vaino@vaino-GA-880GM-UD2H:~$ cat /proc/asound/pcm
    00-00: ALC892 Analog : ALC892 Analog : playback 1 : capture 1
    00-01: ALC892 Digital : ALC892 Digital : playback 1 : capture 1
    01-00: USB Audio : USB Audio : capture 1
    02-03: HDMI 0 : HDMI 0 : playback 1
    02-07: HDMI 0 : HDMI 0 : playback 1
    02-08: HDMI 0 : HDMI 0 : playback 1
    02-09: HDMI 0 : HDMI 0 : playback 1
    vaino@vaino-GA-880GM-UD2H:~$
    Questo è l’output del primo comando della guida (cat /proc/asound/pcm) quindi posso seguirla tranquillamente?
    Son sulla 11.04 … che dire non è male però mi crasha plasma ogni tanto va beh dai 😛

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.