I'm using the following command to capture my screen cast and laptop video camera at the same time. Video from the camera appears in a smallish window in bottom right of the screen cast. This works, however there is a snag; I can't see the video of myself on screen while I'm recording and I want to be able to see myself in the bottom right window so I can be sure I align myself with the camera. How can I do this?

ffmpeg -f alsa -i default \
-f x11grab -s `xdpyinfo | grep 'dimensions:'|awk '{print $2}'` -r 25 \
-i :0.0 -f video4linux2 \
-i /dev/video0 -filter_complex '[2:v]scale=380:-1[cam];[1:v][cam]overlay=W-w-8:H-h-8' \
-c:a flac \
-qscale 0 screen_and_video_grab.mkv
  • Open the webcam stream with a player, such as ffplay -noborder /dev/video0, then record desktop.
    – llogan
    Commented Dec 26, 2017 at 2:49
  • @LordNeckbeard Thanks. That helped me get to the solution I have posted.
    – Kes
    Commented Dec 28, 2017 at 15:40

1 Answer 1


This solution works in Linux. To screen cast with inset video of yourself on screen where you have a video camera that is located at /dev/video0, paste the following into a text file and name it start_recording.sh or something similar and make it executable


#####  set variables below ####


T="$(date +%d-%m-%Y-%H-%M-%S)".mkv

#echo $T


#echo $video_window_title

####  Place video camera on own screen & detach the process  ####
ffplay -window_title "$video_window_title" /dev/video0 &

####  Record everything on the screen  ####
ffmpeg -y -f x11grab -s \
`xdpyinfo | grep 'dimensions:'|awk '{print $2}'` \
-i :0.0 -f alsa \
-i default $HOME/$T

To stop recording, paste the following into a text file and name it stop_recording.sh or something similar and make it executable


# kills the ffmpeg and ffplay processes     
pkill ffmpeg && pkill ffplay

The below two line script will make your inset video the always on top window, or not. Simply put the below two lines below in a text file, call it something like toggle_video_inset_to_always_above_layer_or_normal_layer.sh or something you can remember, and make it executable.


wmctrl -r $(wmctrl -lx | grep ffplay | grep -oE "[0-9a-z\._-]{20,25}$") -b toggle,above

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.