I’ve had my cheap IP camera for a while now, originally buying it without purpose, and now promoted to a full time baby monitor to check on little ‘average baby’ at night.
Until now I have always used an Android app to view my IP camera feed, but recently got curious as to whether a Raspberry Pi could do something similar with one of the many small screens on the market.
My idea came from the fact that I’ve had this mini screen in my box of Pi bits for a good while, but I haven’t ever made anything worthwhile with it. It’s a cool bit of kit to play with, and has a certain novelty factor, but in reality it’s just not practical for day to day Terminal or desktop viewing.
After an evening of trial and error using various method suggestions I found across the internet, I eventually got my IP cam feed showing on my mini screen using both mplayer and omxplayer!
In this blog I’ll show you how to make your own Raspberry Pi IP camera viewer, and the differences between the two players.
For this project I’m using my NeoSec/TinyLCD 3.5″ screen with an original Model B Pi. I do also have a 2.8″ PiTFT but after trying both mplayer and omxplayer, I couldn’t get this to work with Adafruit’s popular display.
My method may also work with other screens – but don’t count on it!
Install Raspbian + Hardware
I’ve had quite a few failed Pi projects recently so I like to have a bit of confidence that I haven’t changed anything that could cause a problem. Therefore, I always start with a fresh Raspbian image.
Now, this isn’t a simple Raspbian SD card install like you’re used to – mini screens like these either need either a custom Raspbian image (with all the bits already done to make the screens work via the GPIO) or you’ll need to make manual changes on top of a standard Raspbian image yourself.
Luckily my NeoSec/TinyLCD screen comes with a pre-made Raspbian image, which works very well out of the box. Pre-made images aren’t everyone’s cup of tea, but it works for me.
You’re also going to need an internet connection to your Pi (Ethernet or WiFi adapter) and ideally a keyboard (although you could SSH in). I wrote a guide on setting up WiFi on your Raspberry Pi here.
Update your Pi
Once you’ve installed the SD card and got the screen running, run an update and upgrade using the usual commands below. Remember, you’ll need the internet connection working for this part:
sudo apt-get update
sudo apt-get upgrade
Now just reboot your Pi, then we’re ready to start the project.
IP Camera Details Required
This article assumes you already have an IP Camera and have it set up to view on your home WiFi network (Ideally with a static IP address).
All we need from your IP Camera is the IP address, username and password. You should know these if you’re already viewing your IP camera from a phone or similar.
If you’re not sure, getting the IP address is easy with apps like ‘Fing’ for Android, but I can’t help with the user name and password. These should be either on the camera itself, or in the manual.
If you get stuck, try resetting the IP Camera (there may be a button underneath) and then try the stock settings on the camera’s info sticker/manual.
I managed to get two different players to work with this screen – mplayer and omxplayer. So what’s the difference?
From my perspective, omxplayer gives a better picture. It shows almost the whole camera image, whereas mplayer seems to cut a lot off and almost zoom in. From what I have read online, this may be because omxplayer is the only player that utilises the Pi’s GPU.
In a way, I found mplayer easier to use, as it’s ready to go out of the box. Omxplayer requires a little setup and is hard to control via the mini screen, but really there’s not much in it.
Streaming Your IP Camera Feed To The Pi
Fire up your Raspberry Pi and open a Terminal session:
Mplayer should be ready to use, so simply type in the command below to start viewing your camera feed. Change the IP address, username and password to match your camera:
mplayer fbdev2:/dev/fb1 "http://192.168.1.9:90/videostream.asf?user=USERNAME&pwd=PASSWORD"
After a few seconds of code running on the screen, your live IP camera stream should start. If it doesn’t recognise the mplayer command, you may need to install mplayer using the following:
sudo apt-get install mplayer
This options needs a bit of setup first. I found this guide and just had a go with reasonably low expectations for success – but it turned out to work very well!
So, let’s set it up. Use the commands below, one by one (you only have to do these once):
sudo apt-get install cmake
git clone https://github.com/tasanakorn/rpi-fbcp
sudo install fbcp /usr/local/bin/fbcp
sudo modprobe fbtft dma
sudo modprobe fbtft_device name=tinylcd35 rotate=90 speed=48000000 fps=50
Now you just need to “start the fb copying process” in the background using this final command. You just need to do this part every time you boot:
Once that’s all done, start the stream using the following command. Same as with mplayer, change the IP address, username and password to match your camera:
omxplayer --live "http://192.168.1.9:90/videostream.asf?user=USERNAME&pwd=PASSWORD"
If you get an error, it may be because omxplayer isn’t installed. If so, here’s the command:
sudo apt-get install omxplayer
Here’s my omxplayer running – notice how the image quality appears better, and much more is fit into the screen:
Compared to using my Android app, there are a few limitations with this project.
- You can’t control the IP Cam’s movement motors. I never intended or expected this to be possible – this is just a simple viewing solution, useful if your cam is usually in a fixed position (on a baby’s cot or garage door for example)
- You can’t see more than one IP camera at a time – compared to the Android app that lets you view and select multiple feeds at once.
- Doing this can’t get you a date. Guaranteed.
- As stated above, make sure you have mplayer/omxplayer installed first if you get any issues
- Different IP Cameras have different ways of streaming, sending a different image/video type (I’m not educated on this, but I know this is ‘a thing’). I’m using a Wansview NCB-541W if that helps.
- Power – if you’re using a cheapo power supply, the drain of the Pi + screen + WiFi adapter + peripherals may be too much and cause instability. Don’t be a muppet – buy a proper power supply!
Next Steps & Improvements
Firstly, I can’t find a way to exit the camera view and go back to the terminal or desktop. None of the usual exit/quit commands worked (ctrl+z, ctrl+c etc) so I found that I had to pull the power. It’s almost like I need a command to clear the screen/close the player properly. **UPDATE** Thanks to comments at the bottom of this blog, I’ve been told hitting the ‘q’ key will exit omxplayer.
I’m also wondering if mplayer/omxplayer can be built around something like tkinter to make a mini control interface, being able to view and move the camera on the same screen. This sounds way beyond my abilities, but could be fun to investigate. I found something called TBOplayer, and it might just be the way forward.
For viewing the feed externally, setting up a DNS service like NoIP is easy and would allow me to view my camera feed outside of my WiFi network. I could take my camera viewer to work to have on my desk – how cool is that! I wrote an article on using a Raspberry Pi as a NoIP update client, so I could even involve more Pis in the process.
Something for me to play with – the guys at NeoSec have sent me one of their new 7″ screens recently, so I will be trying the project on this larger display soon…stay tuned!
If you have any questions or suggestions, please add a comment below.