After trying the instructions here to use netcat and mplayer to stream from the Raspberry Pi camera module to Windows, I found that although the cache filled on the Windows machine, indicating that data was being received, mplayer never launched. I searched around a bit and came to the conclusion that it was something to do with either Windows 7, or having a 64-bit machine. I settled for the 64-bit issue as it’s not uncommon for the 64-bit architecture to create problems.
I eventually found a combination of netcat and mplayer that worked! Here’s a tutorial on how to do it.
How to do it
Download netcat 1.12 from here.
Download the AMD64 version of mplayer r36169 from here.
Unzip them on a Windows machine into a folder so you have, amongst other files::
MPlayer-x86_64-r36169+g2844ea8mplayer.exe netcat-win32-1.12nc64.exe
Created a batch file (called Wait-for-stream.bat) with the following command in it:
netcat-win32-1.12/nc64.exe -L -p 5001 | "MPlayer-x86_64-r36169+g2844ea8mplayer.exe" -vo direct3d -fps 31 -cache 1024 -
Note: I had to specify the -vo direct3d option as otherwise all I got was a black screen. No idea why this was needed, but I guess it’s something to do with my laptop specifically, so you may find you don’t need it.
On the Raspberry Pi, create a script (stream-to-netcat.sh) and add the following line to it:
raspivid -t 999999 --hflip -o - | nc 192.168.1.64 5001
An explanation:
- -t 999999 means that the camera will keep capturing for that number of milliseconds. Increase if you need to.
- -hflip Currently, the camera flips its output horizontally. This is something to do with the camera being ‘front facing’. This is being reviewed to see if it can be changed (which I know it can because it used to work the correct way around)
- -o – This means ‘output the data to standard out’ – effectively dump the output to the console.
- | nc – This means send the output from the camera through a ‘pipe’ into netcat (which does the actual broadcast)
- The IP address is the address of my Windows 7 64-bit laptop.
On the Windows, run the batch script Wait-for-stream.bat to start the ‘listener’. You should get:
MPlayer sherpya-r36169+g2844ea8-4.6 (C) 2000-2013 MPlayer Team
Playing -.
Reading from stdin...
Cache fill: 0.00% (0 bytes)
On the Pi, run the stream-to-netcat.sh script. Nothing should appear on the Pi.
On the Windows machine, the Cache will start to fill up, a bit of Codec debug will appear and the video should show on-screen.
And that’s it! A lot of fiddling about, but worth it so I can run Windows on Saturday at the Cambridge Jam! (And just to prove I could!)
[…] recantha After trying the instructions here to use netcat and mplayer to stream from the Raspberry Pi […]
I have the same issue, MPlayer not launched
I discribed step by step my test at
http://www.raspberrypi.org/phpBB3/viewtopic.php?f=43&t=52401&p=402571#p402571
Thanks, it works great. But is there a way to not stream to a specific IP address so that any PC on the LAN can see it?
This method is point-to-point. However… try taking a look at this blog post instead:
http://178.62.14.192/?p=7321
Hi! Thanks for the tutorial! But it doesnt work for me 🙁 The cache just doesn’t fill up. it stays on “Cache fill: 0.00% (0 bytes)” forever…. I’m on Windows 8 and I took all the steps exactly as you explained. Do you have any idea?
Sounds like something specific to Windows 8… which isn’t good.
When you refer the file “netcat-win32-1.12nc64.exe”
doesnt you mean “netcat-win32-1.12/nc64.exe”??
Ahhhh. Yes. I believe so, Thiago.
Thanks! That worked perfecty now!!
Hi Recantha, its me again.
Do you know how to watch the stream and save it simultaneously?
Hi there. I don’t I’m afraid. I’m sure there’s some way of doing it so that you save the stream and then stream off of it, but I don’t know the commands. Try asking on the Raspberry Pi forums. Sorry! 🙁
Its ok. Thanks Anyway!
[…] Credits to https://www.recantha.co.uk/blog/?p=4128 […]
How can I do it with USB camera?
Try https://pimylifeup.com/raspberry-pi-webcam-server/