Hi,
EDIT: See the WebcamStudio for GNU/Linux as is it far more easier and fun to use...
Here is the solutions that I found to be able to screencast my desktop thru a virtual webcam so I can show my destop (or part of it) in aMsn or with Flash in sites like Stickam or BlogTV.
1 - Using recordMyDesktop as the X11 grabber
What you need is recordMyDesktop and ffmpeg from the repositories of Ubuntu:
> sudo apt-get install ffmpeg recordmydesktop
Then, download the source code for Flashcam
> wget http://www.swift-tools.net/Flashcam/flashcam-1.1.tgz
(Check is there is a new version... Just in case...)
Extract, and compile the source code... (See documentation for dependencies)
> ./configure
> make
> sudo make install
Actually, we only need the vloopback module from Flashcam.
When loading the vloopback module, it will tell you which device is the input and which is the output. If you already have a webcam, it is probably already set at /dev/video0. So loading vloopback will give you /dev/video1 as OUTPUT and /dev/video2 as INPUT. The following script a pointing to /dev/video2 by default. You can validate the information my manually loading the vloopback module and using "dmesg" command to find out the input device.
Next, download the utility mjpegtools_yuv_to_v4l from http://panteltje.com/panteltje/mcamip
> wget http://panteltje.com/panteltje/mcami...to_v4l-0.2.tgz
Extract, compile and install as usual...
We are now ready to the big thing! There are a lot of possibilities, but here is a small script that can automate the whole process in a single command from the console:
#************Script*******************
mkfifo stream.ogg
sudo modprobe vloopback
echo "CTRL-C to stop the capture"
sleep 5
# On a single line!
recordmydesktop -width 320 -height 240 -fps 15 --no-sound --on-the-fly-encoding --follow-mouse --overwrite -o stream.ogg & sleep 10 & ffmpeg -i stream.ogg -an -s 320x240 -r 15 -f yuv4mpegpipe - | mjpegtools_yuv_to_v4l /dev/video2
# End of single line
killall recordmydesktop
rm stream.ogg
#*************************************
Copy this script into a bash file (mine is called caputre.sh), and create a folder where to invoke this script.
What happens is
- A fifo file is created to pipe recordMyDesktop with ffmpeg
- The module vloopback is loaded and make sure that your "input" device is /dev/video2. If not, you will have to modify the script to use the correct device. If you already have a webcam on /dev/video0, you will have /dev/video1 as an output and /dev/video2 as an input.
- Then recordMyDestop is invoke and we use the fifo file to record the desktop. That video file in the fifo file will be read by ffmpeg as an input, converted to yuv4mpeg format and the converted file will by piped to the mjpegtools_yuv_to_v4l onto the input device /dev/video2.
- To stop the screencast, simply hit CTRL-C.
* Make sure to start the script before opening you stickam viewer because Flash won't detect properly your new webcam "Vloopback".
* Sometimes, the Flash player crashes and stays zombie in memory. It does not happen often, but when it does, it locks the video device and you have to reboot the computer to have access again to your webcam device.
You will require a good CPU because the whole process is CPU demanding but not too much.
The script will capture a square of 400x300 that will be converted into a 320x240 image for the webcam. This settings gives a good view of what you are doing with a good image quality without sacrificing all your CPU cycles. Capture at 5 fps, more than that does not seem to help in any way for the webcam...
2 - Using ffmpeg (from SVN) as the X11 grabber
Ok, while looking for other possibilities, I found out that FFMpeg is able to grab directly from X11 meaning that we can get rid of recordMyDestop in the process...
Download the source code from the SVN repositories:
> svn checkout svn://svn.mplayerhq.hu/ffmpeg/trunk ffmpeg
Then you have to explicitly enable the X11 grabbing like this:
> ./configure --enable-gpl --enable-x11grab
The --enable-gpl is mandatory for the x11grab...
Then continue with the compilation...
> make
I did not install ffmpeg to keep the one from the repository of Ubuntu, so I did not executed "sudo make install". What I did is copy the binary "ffmpeg" into a dedicated folder to invoke it with a script So I won't mess my Ubuntu setup..
Here is the script to use ffmpeg...
# Loading the vloopback module
sudo modprobe vloopback
# executing the compiled ffmpeg binary with the x11grab enabled...
./ffmpeg -f x11grab -s 640x480 -r 5 -i :0.0 -pix_fmt yuv420p -s 320x240 -r 5 -f yuv4mpegpipe -an - | mjpegtools_yuv_to_v4l /dev/video2
3 - Using GStreamer as the X11 grabber and mixer...
After looking for different way to play with mjpegtools_yuv_to_v4l, I found out that it was possible to use gst-launch to capture the desktop and also to mix the stream of my webcam onto the main desktop stream.
What you need:
- Gstreamer, GStreamer-ffmpeg
- Flashcam (for vloopback)
- mjpegtools_yuv_to_v4l
- recordMyDesktop can be introduced also but is optional.
Here is the script that I started to build to automate que video capture...
##############################################
# WebcamStudio : Small script to #
# create a virtual webcam for Flash or aMsn #
# by mixing different video source #
# #
# Tools required #
# - mjpegtools_yuv_to_v4l #
# - gstreamer, gstreamer-ffmpeg #
# - vloopback (from Flashcam) #
# #
# Created by Patrick balleux #
# http://blog.patrickballeux.com #
# #
# End resolution will be 320x240 #
# #
##############################################
# Setting up a folder to work with...
#mkdir ~/.webcamstudio
#cd ~/webcamstudio
# So not, we are in the right folder to work...
# creating output fifo for use with mjpegtools_yuv_to_v4l
mkfifo output.yuv
# loading the vloopback module
gksudo modprobe vloopback
# set those value depending on your setup...
INPUTDEVICE=/dev/video2
OUTPUTDEVICE=/dev/video1
OUTPUTWIDTH=320
OUTPUTHEIGHT=240
# Creating a stream from the webcam
VIDEO1W=80
VIDEO1H=60
VIDEO1X=240
VIDEO1Y=0
# webcam UVCVIDEO
#VIDEO1GST="v4l2src device=/dev/video0 ! jpegdec ! videoscale ! video/x-raw-yuv,width=$VIDEO1W,height=$VIDEO1H ! ffmpegcolorspace"
# webcam EYETOY
VIDEO1GST="v4lsrc device=/dev/video3 ! videoscale ! video/x-raw-yuv,width=$VIDEO1W,height=$VIDEO1H ! ffmpegcolorspace"
# Creating a stream from the desktop
VIDEO2W=500
VIDEO2H=400
VIDEO2X=100
VIDEO2Y=100
# Using GStreamer for X11 capture
VIDEO2GST="ximagesrc use-damage=false show-pointer=true startx=$VIDEO2X starty=$VIDEO2Y endx=$VIDEO2W endy=$VIDEO2H ! videoscale method=0 !video/x-raw-rgb,framerate=15/1,width=$OUTPUTWIDTH,height=$OUTPUTHEIGHT ! ffmpegcolorspace"
# Using recordMyDesktop for X11 capture
mkfifo screen.ogg
#VIDEO2GST="filesrc location=screen.ogg ! oggdemux ! theoradec ! videoscale !video/x-raw-yuv,framerate=15/1,width=$OUTPUTWIDTH,height=$OUTPUTHEIGHT ! ffmpegcolorspace"
#recordmydesktop --quick-subsampling --no-cursor -width $VIDEO2W -height $VIDEO2H -fps 15 --no-sound --on-the-fly-encoding --follow-mouse --overwrite -o screen.ogg & sleep 2 &
# Virtual webcam...
# Mixing VIDEO1 and VIDEO2
gst-launch $VIDEO1GST \
! videobox border-alpha=0 alpha=1 left=-$VIDEO1X top=-$VIDEO1Y \
! videomixer name=mix ! ffmpegcolorspace \
! y4menc ! filesink location=output.yuv \
$VIDEO2GST ! alpha alpha=1 ! mix. & cat output.yuv | mjpegtools_yuv_to_v4l $INPUTDEVICE
# Sending only VIDEO2
#gst-launch $VIDEO2GST ! y4menc ! filesink location=output.yuv & cat output.yuv | mjpegtools_yuv_to_v4l $INPUTDEVICE
# Live view...
#gst-launch $VIDEO1GST \
#! videobox border-alpha=0 alpha=1 left=-$VIDEO1X top=-$VIDEO1Y \
#! videomixer name=mix ! ffmpegcolorspace \
#! xvimagesink \
# $VIDEO2GST ! alpha alpha=1 ! mix.
rm output.yuv
*********************************
The three solutions work quite well with Flash web site like Stickam or BlogTV. But beware of the CPU usage, Bigger the capture = bigger CPU usage.
Also the video quality of Gstreamer is not as good as the FFMPEG+RECORDMYDESKTOP combo. But you can overlay a webcam in your desktop capture.
I am trying to find a way to had a third stream for images/logos/titles to show on the stream. The GStreamer script is not fine-tuned, but it works ok.
Here are some tips:
- With recordMyDesktop, you have more options on the capture like having a square 400x300 that will follow your mouse.
- Using ffmpeg (with X11grab) is not really lighter than using recordMyDesktop + ffmpeg
- Do not capture more than 640x480 with ffmpeg(x11grab), because it will probably kill your CPUs...
- A framerate of 5 fps is more than enough for the capture.
- Some Flash sites enable live recording. I found out that the recording works better if ffmpeg outputs at 15 FPS...
- Since ffmpeg from the source is able to capture from v4l(2) devices, you can use the same technic to foward from your webcam to a vloopback device. Usefull when Flash does not recognize your webcam...
- If you want to share a video over your webcam, play it in Totem/Mplayer/VLC and simply point yo it with your mouse...
- I also found out that two Flash site can record from the same virtual webcam as the same time... I did not think it was possible...
That's it, hope you will enjoy getting par with Windows users with Manycam of FakeWebcam...
Patrick Balleux
http://blog.patrickballeux.com



Adv Reply


Bookmarks