Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I want to make a live stream of (a window on) my linux desktop using a free streaming site, using the captured video as a fake webcam. There are many tools for this on windows. ffmpeg allows me to capture input on a specific window, but I can't find a way to output the video to a fake webcam-style device usable by flash.

Can anyone recommend a method (or software) for doing this?

share|improve this question
    
It was all hunky-dory right up until you said "fake webcam-style device usable by flash". –  Ignacio Vazquez-Abrams Apr 13 '12 at 3:05
    
I'm not sure what you mean? By "webcam-style" device I meant something like a fake /dev/videoN device file, or something similar. I assume this is how the captured video would be usable by flash. –  bkconrad Apr 13 '12 at 3:07
    
Exactly. That's hard. –  Ignacio Vazquez-Abrams Apr 13 '12 at 3:08
add comment

3 Answers 3

What distro are you using? I've had success with WebCamStudio under Arch combined with the Livestream web-based "studio." It's been a little while since I've used it, though.

http://www.ws4gl.org/

What are you trying to do exactly? ffmpeg compiled with x11grab can record the desktop. I've had limited success pushing that to Ustream, but again it's been a while and I think what I was doing won't work anymore.

If you just want to stream a file rather than your desktop (I'm thinking when you say, "A window," you mean, "VLC"), I can point you in the right direction to get that working with Livestream (maybe Ustream). I'm clumsily figuring out how to do this through experimentation. It's not fantastic but it works with Livestream.

Justin.tv has scripts that can stream from VLC to their service, as well.

http://apiwiki.justin.tv/mediawiki/index.php/Linux_Broadcasting_API

share|improve this answer
    
Oh wow this is very interesting. I'm trying to stream live gameplay of some games. I already know how to capture into a video file from ffmpeg, I wonder if I can open that same file in vlc and somehow stream it as it's being written. Thanks for the info. –  bkconrad Apr 13 '12 at 15:28
add comment

You can install v4l2loopback. It is a kernel module that simulates a webcam. Load it with:

modprobe v4l2loopback

Then you need to send the video stream to the device /dev/video0 using a program like ffmpeg. In order to capture the desktop and forward it to /dev/video0 with ffmpeg, you can use the following command line:

ffmpeg -f x11grab -r 15 -s 1280x720 -i :0.0+0,0 -vcodec rawvideo -pix_fmt yuv420p -threads 0 -f v4l2 /dev/video0

Change the value of -r from 15 to something else if you want a different frame rate. The resolution is chosen in the -s parameter. If you want to specify an offset from the upper-left corner of the screen, pass it in the -i parameter in the form "-i :0.0+x,y", where x and y are the horizontal and vertical offset respectively.

share|improve this answer
add comment

Use v4l2loopback with mplayer.

  1. Download it,
  2. compile it (make and su -c 'make install'),
  3. load the module with su -c 'modprobe v4l2loopback',
  4. then change one line in the file examples/yuv4mpeg_to_v4l2.c of the v4l2loopback source folder from

    v.fmt.pix.pixelformat = V4L2_PIX_FMT_YUV420;
    

    to

    v.fmt.pix.pixelformat = V4L2_PIX_FMT_YVU420;
    
  5. and do make in this folder.

  6. Then run it from the examples directory like this:

    mkfifo /tmp/pipe  # only needed once, as long as you do not delete the file /tmp/pipe
    ./yuv4mpeg_to_v4l2 < /tmp/pipe &
    mplayer movie.mp4 -vf scale=480:360 -vo yuv4mpeg:file=/tmp/pipe
    

    where you replace movie.mp4 with the name of your video file. And replace /dev/video0 with your loopback device.

MPlayer is able to play any webstreams, all kind of video files, even from stdin! I just tested it with a file from http://www.tagesschau.de which is a german news site.

TS=$(wget "http://www.tagesschau.de/multimedia/video/" -q -O - | grep --regexp='http.*\.webm"' | sed -e 's%.*href="%%' -e 's%\.webm".*%\.webm%')
./yuv4mpeg_to_v4l2 < /tmp/pipe &
mplayer $TS -vf scale=480:360 -vo yuv4mpeg:file=/tmp/pipe

Instead of the $TS you could put a - (which stands for stdin). And in front of mplayer your ffmpeg command redirecting its output to stdout. So something like:

./yuv4mpeg_to_v4l2 < /tmp/pipe &
fmpeg -someOptions ... -o - | mplayer - -vf scale=480:360 -vo yuv4mpeg:file=/tmp/pipe

Did not test the last one, because you did not tell how your ffmpeg command look like.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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