Capture screen and mic input using FFmpeg and ALSA

Updated: Apr 22, 2023

Recently, interesting commands appeared in commandlinefu about x11grab using ffmpeg. All are very interesting commands and they did what I expected in my Debian. But only one thing is missing. While creating a screencast, If I want to speak, that should appear in the capturing stream.

Thanks to alsa and ffmpeg, they have a way to capture my laptop’s in-built mic input. So I customized the existing commands which appeared in commandlinefu and created a small script.

# simple command to capture your screen

OUTPUT="${1:?[usage] OUTPUTFILE}"

        xwininfo -root |
        grep 'geometry' |
        awk '{print $2;}'

        ffmpeg -f alsa -itsoffset 00:00:02.000 -ac 2 -i hw:0,0 \
                -f x11grab -s $(getgeometry) -r 10 -i :0.0 \
                -sameq -f mp4 \
                -s wvga \
                -y "${OUTPUT}"


Finally I created my first screencast using script. Here is the video

Atlast, I don’t want to install one more app to create screencast. FFmpeg is with me !!!