View your Raspberry Pi Webcam from anywhere. Connect to it from a unique domain name and check in on your house or pets while you are away.
Requirements For This Walkthrough
Materials
- Local network
- Mac or PC
- Raspberry Pi camera module, a Compatible Webcam (or the exact same one I used to write this tutorial)
- Raspberry Pi running Raspbian “wheezy”
- Domain name
- Router capable of supporting DynDNS, noip, or other dynamic DNS service; or a software-based dynamic DNS client (not covered in this walkthrough)
- lighttpd Web server running on the Pi (optional–allows your to embed a stream to a Webpage, which can be password-protected)
- HDMI Cable (*optional)
- Keyboard (*optional)
- Mouse (*optional)
- Monitor with HDMI input (*optional)
- *If the Raspberry Pi is set up as a headless machine, you will not need a monitor, keyboard, or mouse–just another computer, which would be used to access it remotely over the network via SSH.
Downloads
- MJPG-Streamer
- input_uvc_patch.txt
Resources
- http://blog.miguelgrinberg.com/post/how-to-build-and-run-mjpg-streamer-on-the-raspberry-pi
- http://www.instructables.com/id/Create-an-internet-controlled-robot-using-Livebots/step5/Get-the-webcam-streamer-for-Raspberry-Pi/
- http://wolfpaulus.com/jounal/embedded/raspberrypi_webcam/
- http://www.linuxcircle.com/2013/02/06/faster-video-streaming-on-raspberry-media-server-with-mjpg-streamer/
- http://skillfulness.blogspot.com/2010/03/mjpg-streamer-documentation.html
- http://www.plugcomputer.org/plugforum/index.php?topic=6231.0
- http://iomem.com/index.php?archives/3-Starting-out-with-Lighttpd.html&serendipity%5Bentrypage%5D=4&serendipity%5Bentrypage%5D=all&serendipity%5Bentrypage%5D=all
- http://nutz95.wordpress.com/2013/05/14/raspberry-pi-pirider-install-mjpegstreamer/
- http://www.phillips321.co.uk/2012/11/05/raspberrypi-webcam-mjpg-stream-cctv/
Step-by-step Walkthrough
Short-and-sweet Version (for advanced users)
lsusb sudo apt-get update sudo apt-get upgrade sudo apt-get install libjpeg8-dev imagemagick libv4l-dev sudo ln -s /usr/include/linux/videodev2.h /usr/include/linux/videodev.h sudo apt-get install subversion cd ~ svn co https://svn.code.sf.net/p/mjpg-streamer/code/mjpg-streamer/ mjpg-streamer cd mjpg-streamer make mjpg_streamer input_file.so input_uvc.so output_http.so sudo cp mjpg_streamer /usr/local/bin sudo cp output_http.so input_file.so input_uvc.so /usr/local/lib/ sudo cp -R www /usr/local/www sudo vi ~/.bashrc export LD_LIBRARY_PATH=/usr/local/lib/ source ~/.bashrc /usr/local/bin/mjpg_streamer -i "input_file.so -f /tmp/stream -n pic.jpg"-o "output_http.so -w /usr/local/www" sudo vi /usr/sbin/livestream.sh #!/bin/bash /usr/local/bin/mjpg_streamer -i "/usr/local/lib/input_uvc.so" -o "/usr/local/lib/output_http.so -w /var/www/stream -c username:password" sudo chmod 755 /etc/init.d/livestream.sh sudo update-rc.d livestream.sh defaults
Conceptual Overview
- Update the Raspberry Pi and install software dependencies
- Download the MJPG-Streamer source code
- Compile the source code
- Install the patch to prevent a blank white screen
- Capture images from the Webcam and serve them on a Webpage
- Set MJPG-Streamer to run at boot
Two Methods: Camera Module or USB Webcam
You can use the Raspberry Pi camera module, or any compatible USB Webcam. I found that that the USB Webcam method is easier and better quality, but there are instructions for both. In the walkthrough, I’ll be using a USB Webcam. The camera module instructions can be found in the appendix.
Step-by-step Walkthrough
Check If the Pi Recognizes the Webcam
Plug in the USB Webcam and run the command:
lsusb
Look for an entry relating to your Webcam. This is a good indicator it has been recognized.
Update Pi and Install Dependencies
First, update the Raspberry Pi and then install some of the dependencies of MJPG-Streamer.
sudo apt-get update sudo apt-get upgrade sudo apt-get install libjpeg8-dev imagemagick libv4l-dev
An adjustment needs to be made: the videodev.h file has been replaced with videodev2.h but this change needs to be made manually. To do this, just create a symbolic link.
sudo ln -s /usr/include/linux/videodev2.h /usr/include/linux/videodev.h
Download and Compile MJPG-Streamer
Unfortunately, MJPG-Streamer isn’t available via apt-get , so we need to compile it from source. This may be more complex than setting up a Webcam using Motion, but I found MJPG-Streamer to be less resource-intensive so the additional complexity of setting it up is worth it.
There are a few different ways to install MJPG-Streamer. The easiest is via subversion, which is what I will walkthrough. If you want directions for some other methods, look in the appendix at the bottom of the post.
Download via Subversion (svn)
Install subversion (if necessaary).
sudo apt-get install subversion
Then, download a copy of the MJPG-Streamer source code to your home folder and move into the directory when the download is complete:
cd ~ svn co https://svn.code.sf.net/p/mjpg-streamer/code/mjpg-streamer/ mjpg-streamer cd mjpg-streamer
There are a lot of plugins included with MJPG-Stream, but for this walkthrough, we will just compile three. If you only plan to use a USB Webcam, you can modify the command below to suit your needs. Just leave off the items you do not want.
- input_uvc.so (for USB Webcams) : copies JPGs from a single input (the Webcam in this case) to one or more output plugins. This is good for streaming larger images at a higher framerate with lower CPU usage.
- input_file.so (for camera module): similar to the above, but copies them from a directory.
- output_http.so: streams the files to a Webserver
make mjpg_streamer input_file.so input_uvc.so output_http.so
Alternatively, running make , you can compile everything that comes with MJPG-Streamer. I chose to just install what was necessary to save on storage space and resources.
Copy MJPG-Streamer to an Alternate Location
You could run MJPG-Streamer right from the folder after it is compiled (./mjpg_streamer ), but it might be better to give it a permanent home.
Run the following commands to copy it to a more globally-accessible area:
sudo cp mjpg_streamer /usr/local/bin sudo cp output_http.so input_file.so input_uvc.so /usr/local/lib/ sudo cp -R www /usr/local/www
/usr/local/ is a common place for third-party items or things added to a system by an admin. But you could put them wherever you like, or just leave it where it is. You will just need to modify the paths for the rest of the walkthrough.
Export Paths
If you did try to run mjpg_streamer now, it probably returned an error about search paths. This is because right now, the system doesn’t know where to find the files. This is an easy fix. Just append the following line to ~/.bashrc (assuming you ran the commands above to copy the files to /usr/local/ . This will make it a permanent change so that you don’t need to do this every time you log in:
export LD_LIBRARY_PATH=/usr/local/lib/
Now you can either log out and back in again, but it is easier to run the source command to apply the change (this has the same effect as logging in):
source ~/.bashrc
Now, you can simply call mjpg_streamer no matter what directory you are in. We are almost ready to start capturing images. But if you run into a blank white screen, you’ll want to install the patch below (see also user experiences in the comments section)
Install A Patch
Many users reported a blank white screen when trying to use it. Apparently, this patch fixes it (see also here).
vim mjpg-streamer-code/mjpg-streamer vim input_uvc_patch.txt
Paste in this code and save the file
--- plugins/input_uvc/input_uvc.c (revision 174) +++ plugins/input_uvc/input_uvc.c (working copy) @@ -405,9 +405,13 @@ if(pcontext->videoIn->formatIn == V4L2_PIX_FMT_YUYV) { DBG("compressing frame from input: %d\n", (int)pcontext->id); pglobal->in[pcontext->id].size = compress_yuyv_to_jpeg(pcontext->videoIn, pglobal->in[pcontext->id].buf, pcontext->videoIn->framesizeIn, gquality); + /* copy this frame's timestamp to user space */ + pglobal->in[pcontext->id].timestamp = pcontext->videoIn->buf.timestamp; } else { DBG("copying frame from input: %d\n", (int)pcontext->id); - pglobal->in[pcontext->id].size = memcpy_picture(pglobal->in[pcontext->id].buf, pcontext->videoIn->tmpbuffer, pcontext->videoIn->buf.bytesused); + pglobal->in[pcontext->id].size = memcpy_picture(pglobal->in[pcontext->id].buf, pcontext->videoIn->tmpbuffer, pcontext->videoIn->tmpbytesused); + /* copy this frame's timestamp to user space */ + pglobal->in[pcontext->id].timestamp = pcontext->videoIn->tmptimestamp; } #if 0 @@ -418,8 +422,6 @@ prev_size = global->size; #endif - /* copy this frame's timestamp to user space */ - pglobal->in[pcontext->id].timestamp = pcontext->videoIn->buf.timestamp; /* signal fresh_frame */ pthread_cond_broadcast(&pglobal->in[pcontext->id].db_update); Index: plugins/input_uvc/v4l2uvc.c =================================================================== --- plugins/input_uvc/v4l2uvc.c (revision 174) +++ plugins/input_uvc/v4l2uvc.c (working copy) @@ -450,6 +450,8 @@ */ memcpy(vd->tmpbuffer, vd->mem[vd->buf.index], vd->buf.bytesused); + vd->tmpbytesused = vd->buf.bytesused; + vd->tmptimestamp = vd->buf.timestamp; if(debug) fprintf(stderr, "bytes in used %d \n", vd->buf.bytesused); Index: plugins/input_uvc/v4l2uvc.h =================================================================== --- plugins/input_uvc/v4l2uvc.h (revision 174) +++ plugins/input_uvc/v4l2uvc.h (working copy) @@ -28,6 +28,7 @@ #include <stdio.h> +#include <stdint.h> #include <string.h> #include <fcntl.h> #include <unistd.h> @@ -105,6 +106,8 @@ int framecount; int recordstart; int recordtime; + uint32_t tmpbytesused; + struct timeval tmptimestamp; }; /* context of each camera thread */
Then run these commands to apply the patch
patch -p0 < input_uvc_patch.txt sudo make USE_LIBV4L2=true clean all sudo make DESTDIR=/usr/local install
Using input_uvc.so to Capture Images
Start running mjpg_streamer
with the command:
/usr/local/bin/mjpg_streamer -i "/usr/local/lib/input_uvc.so" -o "/usr/local/lib/output_http.so -w /usr/local/www"
This command options are as follows:
- -i : uses input_uvc.so (the USB Webcam) as input
- -o : output_http.so for the output (sending the images to a Web server
- -w : the directory, which has the HTML, CSS, and JS files: /usr/local/www
You can cancel the stream by pressing Ctrl+C. If you want to experiment with some other options, some are listed below:
- -b : runs in the background
- -p : set a default port instead of the default 8080
- -c : prompts for username:password
- -y YUYV : enables YUYV format and disables MJPEG mode
- -f : framerate (in seconds)
If you used the -b option, you will get your prompt back. So how do you stop it from running? After running the command, you will see a line like:
forked to background (4979)
If you want to stop the stream, just run:
kill 4979
which just kills the process ID (PID) of MJPG-Streamer.
View the Webcam Live-stream From a Browser
(while connected to your local network)
Even if you have already set up a Webserver, you can still run this without problem because it is accessed on a different (default) port: 8080 . So when you navigate to it in a browser, just append :8080 after the IP address:
- locally: http://localhost:8080
- from another device on the network: http://<raspberry_pi’s_ip_address>:8080
Accessing Your Pi Over the Internet
Viewing your Webcam while connected to your local network is cool, but I’ll show you how to access your Webcam from anywhere by going to a URL such as: myDomain.com:8080 . This stream can be password-protected, but it really isn’t very secure, so be careful if you make this available online.
Pre-requisites
- Forward port 8080 to your Raspberry Pi
- Enable a dynamic DNS service on your router
- (optional) Setup a lighttpd Web server with a password-protected directory
Once the steps above are complete, you will be able to access your Webcam stream from any browser by navigating to http://myDomainName.org:8080 . But there is no password yet! Anyone on the Internet will be able to see your Webcam.
We can tell MJPG-Streamer to use a password with the -c option. This password is not very secure (it is only base 64 encoded), but it can offer a first line of defense. Someone could easily sniff and decode the password, but if you are on a trusted network then it is not as much of a problem.
The command would look like this:
/usr/local/bin/mjpg_streamer -i "/usr/local/lib/input_uvc.so" -o "/usr/local/lib/output_http.so -w /usr/local/www -c username:password"
The best way to secure any online resource is with a layered-defense model. So before you would want this out on the Internet, you might want to be protected using other tools.
Embed the Stream into a Web Page
For simplicity, just make the page in the same directory that is serving up the HTML files (/usr/local/www/ in this walkthrough). This makes it easier to make sure the page works. After you know its working, you can move it somewhere else, but you will just need to adjust the paths. Enter the following HTML code (adjusting to your setup) and it is ready to go.
<html> <head><title>Kitty-cam Live-stream</title></head> <body> <center><h1>Meow</h1></center> <center> <img src="/?action=stream" /> </center> <body> </html>
If you want, you can also use lighttpd to password-protect your embedded-stream.
Now, just navigate to your page to see it:
- http://192.168.1.100:8080/catcam.html (on the local network)
- http://myDomainName.org:8080/catcam.html (over the Internet)
Run MJPG-Streamer as a Daemon (Background Service)
Until now, we have just been launching MJPG-Streamer on an as-needed basis by running a command with our options. If you want to make this more permanent and have the Raspberry Pi start the Webcam stream when it boots up, we need to tell it to do so.
There are two scripts below: a very basic one that just runs the command, and an advanced script that will allow you to use the service command to control it:
sudo service livestream.sh start sudo service livestream.sh stop sudo service livestream.sh restart
Simple Script
A very simple script to do this is below:
sudo vi /etc/init.d/livestream.sh
#!/bin/bash /usr/local/bin/mjpg_streamer -i "/usr/local/lib/input_uvc.so" -o "/usr/local/lib/output_http.so -w /usr/local/www -c username:password"
Save the script. Make it executable:
sudo chmod 755 /usr/sbin/livestream.sh
This next command makes sure it is executed during boot:
sudo update-rc.d livestream.sh defaults
Advanced Script
Below is a script that should load MJPG-Streamer at boot and allow use of the service command:
#!/bin/sh # /etc/init.d/livestream.sh ### BEGIN INIT INFO # Provides: livestream.sh # Required-Start: $network # Required-Stop: $network # Default-Start: 2 3 4 5 # Default-Stop: 0 1 6 # Short-Description: mjpg_streamer for webcam # Description: Streams /dev/video0 to http://IP/?action=stream ### END INIT INFO f_message(){ echo "[+] $1" } # Carry out specific functions when asked to by the system case "$1" in start) f_message "Starting mjpg_streamer" /usr/local/bin/mjpg_streamer -b -i "/usr/local/lib/input_uvc.so" -o "/usr/local/lib/output_http.so -w /usr/local/www -c username:password" sleep 2 f_message "mjpg_streamer started" ;; stop) f_message "Stopping mjpg_streamer…" killall mjpg_streamer f_message "mjpg_streamer stopped" ;; restart) f_message "Restarting daemon: mjpg_streamer" killall mjpg_streamer /usr/local/bin/mjpg_streamer -b -i "/usr/local/lib/input_uvc.so" -o "/usr/local/lib/output_http.so -w /usr/local/www -c username:password" sleep 2 f_message "Restarted daemon: mjpg_streamer" ;; status) pid=`ps -A | grep mjpg_streamer | grep -v "grep" | grep -v mjpg_streamer. | awk ‘{print $1}’ | head -n 1` if [ -n "$pid" ]; then f_message "mjpg_streamer is running with pid ${pid}" f_message "mjpg_streamer was started with the following command line" cat /proc/${pid}/cmdline ; echo "" else f_message "Could not find mjpg_streamer running" fi ;; *) f_message "Usage: $0 {start|stop|status|restart}" exit 1 ;; esac exit 0
Once saved, run the same commands as above:
sudo chmod 755 /etc/init.d/livestream.sh sudo update-rc.d livestream.sh defaults
Success!
Now your Webcam is available over the Internet and starts up when you turn on your Raspberry Pi.
Appendix:
Download MJPG-Streamer via curl or wget
wget http://sourceforge.net/code-snapshots/svn/m/mj/mjpg-streamer/code/mjpg-streamer-code-182.zip unzip mjpg-streamer-code-182.zip
Finish running the commands from the Via subversion section.
Download MJPG-Streamer via scp
Download MJPG-Streamer on another device and then use scp to copy it over to the Raspberry Pi.
scp ~/Downloads/ pi@192.168.1.100:~/
Finish running the commands from the Via subversion section.
Using input_file.so to Capture Images
For this method, you need to set the camera to start recording images using the command raspistill . You will also need a folder to store the files in; for now, just make it in /tmp :
mkdir /tmp/stream
Then, enable the camera with a command similar to the following:
raspistill --nopreview -w 640 -h 480 -q 5 -o /tmp/stream/pic.jpg -tl 100 -t 9999999 -th 0:0:0 &
The options of the command are explained below, so adjust them as you see fit:
- –nopreview : Do not display a preview window
- -w and -h : image with and height (in pixels)
- -q : quality <1-100>
- -o : write out to a file (named pic.jpg)
- -tl : time (in ms) before it takes a picture and shuts down and link latest complete image to filename
- -t : time (9999999ms)
- -th : set thumbnail parameters (x:y:quality)
- & : sends the job to the background (not part of raspistill )
144 replies on “Raspberry Pi Webcam Over the Internet Using MJPG-Streamer”
Really good job of compiling this article. I’ve used mjpg-streamer and I know how much of a pain it can be to set it up without resources like this post to help you out 😀
Quick question, haven’t explored it yet, but what’s the easiest way to stream as well as process a webcam stream? Say, using OpenCV?
Also, capturing stills with mjpg-streamer is as simple as linking a button action to the still image page in the default page hosted when the server is launched right? I haven’t tried it yet so just wanted to know if there’s anything else involved.
Unfortunately, I am not familiar with OpenCV, so I can’t say much on that topic.
Yes, as far as I know, you can just link to the static page and you could save it from there.
I have installed it but there is an error when i try
mjpg_streamer -i “/usr/local/lib/input_uvc.so” -o “/usr/local/lib/output_http.so -w /usr/local/www”
error:
MJPG Streamer Version: svn rev: 3:172 i: Using V4L2 device.: /dev/video0 i: Desired Resolution: 640 x 480 i: Frames Per Second.: 5 i: Format…………: MJPEG Unable to set format: 1196444237 res: 640×480 Init v4L2 failed !! exit fatal i: init_VideoIn failed
there is no ouput on localhost too.
What should I do?
Try launching mjpg_streamer with the additional option:
-y YUYV
, which enables YUYV format and disables MJPEG mode. The error might be because your Webcam does not support the mjpg format.I have faced problem when i want to ./mjpg-streamer.sh start
faild to start
I am using
Bus 001 Device 006: ID 041e:4034 Creative Technology, Ltd Webcam Instant
mjgp-streamer.log
————————–
MJPG Streamer Version: svn rev: 3:160M
i: Using V4L2 device.: /dev/video0
i: Desired Resolution: 640 x 480
i: Frames Per Second.: 4
i: Format…………: YUV
i: JPEG Quality……: 80
i: The format asked unavailable, so the width 352 height 288
The input device does not supports YUV mode
Init v4L2 failed !! exit fatal
i: init_VideoIn failed
MJPG Streamer Version: svn rev: 3:160M
i: Using V4L2 device.: /dev/video0
i: Desired Resolution: 640 x 480
i: Frames Per Second.: 4
i: Format…………: MJPEG
i: The format asked unavailable, so the width 352 height 288
The inpout device does not supports MJPEG mode
You may also try the YUV mode (-yuv option), but it requires a much more CPU power
Init v4L2 failed !! exit fatal
i: init_VideoIn failed
MJPG Streamer Version: svn rev: 3:160M
i: Using V4L2 device.: /dev/video0
i: Desired Resolution: 320 x 240
i: Frames Per Second.: 5
i: Format…………: MJPEG
i: The format asked unavailable, so the width 176 height 144
The inpout device does not supports MJPEG mode
You may also try the YUV mode (-yuv option), but it requires a much more CPU power
Init v4L2 failed !! exit fatal
i: init_VideoIn failed
MJPG Streamer Version: svn rev: 3:160M
i: Using V4L2 device.: /dev/video0
i: Desired Resolution: 320 x 240
i: Frames Per Second.: 5
i: Format…………: MJPEG
i: The format asked unavailable, so the width 176 height 144
The inpout device does not supports MJPEG mode
You may also try the YUV mode (-yuv option), but it requires a much more CPU power
Init v4L2 failed !! exit fatal
i: init_VideoIn failed
mjpg-streamer.sh
—————————–
#!/bin/bash
VIDEO_DEV=”/dev/video0″
FRAME_RATE=”4″
RESOLUTION=”640×480″
PORT=”8080″
YUV=”true”
MJPG_STREAMER_DIR=”$(dirname $0)”
MJPG_STREAMER_BIN=”mjpg_streamer”
LOG_FILE=”${MJPG_STREAMER_DIR}/mjpg-streamer.log”
RUNNING_CHECK_INTERVAL=”2″ # how often to check to make sure the server is running (in seconds)
HANGING_CHECK_INTERVAL=”3″ # how often to check to make sure the server is not hanging (in seconds)
function running() {
if ps aux | grep ${MJPG_STREAMER_BIN} | grep ${VIDEO_DEV} >/dev/null 2>&1; then
return 0
else
return 1
fi
}
function start() {
if running; then
echo “already started”
return 1
fi
export LD_LIBRARY_PATH=”${MJPG_STREAMER_DIR}:.”
INPUT_OPTIONS=”-r ${RESOLUTION} -d ${VIDEO_DEV} -f ${FRAME_RATE}”
if [ “${YUV}” == “true” ]; then
INPUT_OPTIONS+=” -y”
fi
OUTPUT_OPTIONS=”-p ${PORT} -w www”
${MJPG_STREAMER_DIR}/${MJPG_STREAMER_BIN} -i “input_uvc.so ${INPUT_OPTIONS}” -o “output_http.so ${OUTPUT_OPTIONS}” >> ${LOG_FILE} 2>&1 &
sleep 1
if running; then
if [ “$1” != “nocheck” ]; then
check_running & > /dev/null 2>&1 # start the running checking task
check_hanging & > /dev/null 2>&1 # start the hanging checking task
fi
echo “started”
return 0
else
echo “failed to start”
return 1
fi
}
function stop() {
if ! running; then
echo “not running”
return 1
fi
own_pid=$$
if [ “$1” != “nocheck” ]; then
# stop the script running check task
ps aux | grep $0 | grep start | tr -s ‘ ‘ | cut -d ‘ ‘ -f 2 | grep -v ${own_pid} | xargs -r kill
sleep 0.5
fi
# stop the server
ps aux | grep ${MJPG_STREAMER_BIN} | grep ${VIDEO_DEV} | tr -s ‘ ‘ | cut -d ‘ ‘ -f 2 | grep -v ${own_pid} | xargs -r kill
echo “stopped”
return 0
}
function check_running() {
echo “starting running check task” >> ${LOG_FILE}
while true; do
sleep ${RUNNING_CHECK_INTERVAL}
if ! running; then
echo “server stopped, starting” >> ${LOG_FILE}
start nocheck
fi
done
}
function check_hanging() {
echo “starting hanging check task” >> ${LOG_FILE}
while true; do
sleep ${HANGING_CHECK_INTERVAL}
# treat the “error grabbing frames” case
if tail -n2 ${LOG_FILE} | grep -i “error grabbing frames” > /dev/null; then
echo “server is hanging, killing” >> ${LOG_FILE}
stop nocheck
fi
done
}
function help() {
echo “Usage: $0 [start|stop|restart|status]”
return 0
}
if [ “$1” == “start” ]; then
start && exit 0 || exit -1
elif [ “$1” == “stop” ]; then
stop && exit 0 || exit -1
elif [ “$1” == “restart” ]; then
stop && sleep 1
start && exit 0 || exit -1
elif [ “$1” == “status” ]; then
if running; then
echo “running”
exit 0
else
echo “stopped”
exit 1
fi
else
help
fi
kindly guide me i have tried a lot.
Based off of your log file, it looks like your Webcam does not support either format–see the bolded lines:
i: The format asked unavailable, so the width 352 height 288
The input device does not supports YUV mode
Init v4L2 failed !! exit fatal
i: init_VideoIn failed
MJPG Streamer Version: svn rev: 3:160M
i: Using V4L2 device.: /dev/video0
i: Desired Resolution: 640 x 480
i: Frames Per Second.: 4
i: Format…………: MJPEG
i: The format asked unavailable, so the width 352 height 288
The inpout device does not supports MJPEG mode
You may also try the YUV mode (-yuv option), but it requires a much more CPU power
I also noticed the Instant Webcam is not listed on the list of supported devices.
If you wanted to be sure you could install a utility to check:
sudo apt-get install uvcdynctrl
uvcdynctrl -f
You will probably need to get a different Webcam.
it works fine when i use motion instead of mjpg-streamer. I don’t know what is the video format there. It means webcam works fine. isn’t?
I don’t believe so. motion uses
I don’t know all the technical differences on the formats, but I still think you need a different Webcam based off your log file. The only other thing I could think to try is to lower the resolution…
Nice tutorial, I have been using mjpeg-streamer with Pogoplugs and dockstars using Logitech Quickcam Pros, streaming on the web at 10fps and recording 1 image per second, and have a cron job running every two hours, generating an timelapse AVI file) and was planning on using my Raspberry pi with Pi Cam for my outside of the house security cam. But when I saw the smooth stream from Raspivid, I became dis-illusioned with the streams from mjpeg-streamer as at most I can get from the quickcam 9000 was 10 fps at 960×720 (vs. 1080p from Raspicam). However I can never get both livestreaming and recording to work at the same time (except if I get a PC to record the livestream off the raspberry Pi) so I guess I’m stuck with mjpeg-streamer.
I’ve seen some tutorials involving a Beaglebone Black with a Logitech C920 that has beautiful recordings, but the C920 is way too expensive vs the Raspicam…
I was wondering if you know how I can get HD video streams with recordings with Raspberry?
Sorry, I don’t.
I tried a few different Webcams while writing this tutorial, along with other pieces of software (like motion) but came out with similar results as you. The Pi might just not have enough power to do HD live streams. I have considered trying the Hummingboard since it seems to be a little bit more powerful.
If I do find something out, I’ll post it here.
I have a Beaglebone Black and a Cubox-i4 Pro and have considered these,as my live streamers, but I found that I still need an expensive webcam for them if I want HD Live streams. Hopefully, there is something out there that uses Raspi cam which is priced reasonably…
I guess there is a tradeoff for HD or low-cost. Can you get HD using your expensive Webcams with the Pi? Or do you need the extra power as well?
Thank you for this work you done works very well
I’m glad it works!
Thanks for the tutorial. I am pretty sure I followed your instructions but below is what I get when I enter
mjpg_streamer -i “/usr/local/lib/input_uvc.so” -o “/usr/local/lib/output_http.so -w /usr/local/www”
MJPG Streamer Version: svn rev: 3:172
i: Using V4L2 device.: /dev/video0
i: Desired Resolution: 640 x 480
i: Frames Per Second.: 5
i: Format…………: MJPEG
ERROR opening V4L interface: No such file or directory
Init v4L2 failed !! exit fatal
i: init_VideoIn failed
I am using a RaspberryPi B+ and a Pi Camera module. What do I try next?
TIA, Glen
Was the camera recognized when you ran
lsusb
? You could also trysudo apt-cache search v4l
and then install whatever seems appropriate. Unfortunately, I do not have the B+ or the camera module so I can’t test. I also found a comment that might give you some more clues.Here is the output from lsusb
Bus 001 Device 002: ID 0424:9514 Standard Microsystems Corp.
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 001 Device 003: ID 0424:ec00 Standard Microsystems Corp.
Bus 001 Device 004: ID 0bda:8176 Realtek Semiconductor Corp. RTL8188CUS 802.11n WLAN Adapter
Bus 001 Device 005: ID 046d:c313 Logitech, Inc. Internet 350 Keyboard
sudo apt-cache search v41
returns
xserver-xorg-video-radeon – X.Org X server — AMD/ATI Radeon display driver
Will look a the comment you linked in a few minutes – have to do some real work (the stuff they pay me for).
I haven’t tested this, but maybe these utilities will help?
sudo apt-get install v4l-utils v4l-conf
For the Pi camera and Pi-Noir you need the UV4L driver.
http://www.linux-projects.org/modules/sections/index.php?op=viewarticle&artid=14
Nice, thanks!
Can I change the frames perr second in the streamer?, Because is very slow, I think……..
Yes. Use the
-f
option in the input_uvc.so section of the command. (i.e.mjpg_streamer -i "/usr/local/lib/input_uvc.so -f 30" -o "/usr/local/lib/output_http.so -w /usr/local/www"
)Hey Jacob,
Thanks for the guide. Question for you, hoping you might be able to help. Currently I have gotten Mjpg-streamer to work using the YUV format. However, Mjpeg format only outputs a white box (i.e. no video on the webpage). I know the camera supports Mjpeg (Logitech HD-3000) and have also tried several other cameras.
Do you know a way to further troubleshoot this issue, maybe with some sort of logs?
Thanks for any help as I have been banging my head against the wall for weeks on this issue.
Yes, the first place I would look are the log files. I don’t have my Pi set up for this anymore so I don’t know where the log file is. Most logs are in
/var/logs
, so check there. I think you can also see some stuff in/var/log/messages
.Hey Jacob,
I tried to follow your tuto but I’ve got some problems testing it.
I’m using the Pi camera on a raspberry B model, and I followed successfully every steps until the capture images step.
So here I’m stuck with the below message when I ran “raspistill –nopreview -w 640 -h 480 -q 5 -o /tmp/stream/pic.jpg -tl 100 -t 9999999 -th 0:0:0 &”
mmal: Skipping frame 2 to restart at frame 13
mmal: Skipping frame 14 to restart at frame 36
mmal: Skipping frame 37 to restart at frame 58
mmal: Skipping frame 59 to restart at frame 80
mmal: Skipping frame 81 to restart at frame 103
etc..
I’ve already set up the lighttp server, but I can see the image on it. I’m on 172.16.62.221:8888, which is a port number that I defined by myself.
And my camera led is on during the all time I get the mmal message.
I might need to send the captured images on output_http.so but I don’t know how to do it.
Thanks for any help.
Somehow my mjpg_streamer will not start as a service/deamon
I did the export and update-rc.d command.
I guess it has to do with the export of the path somehow what is not recognized in the environment of the deamon.
Did you try logging out and back in or rebooting?
After completion, M getting message like boundarydonotcross content-type:image/jpeg content-Length 0 X-timestamp 296.098931….
It repeats with different time stamps values..
Please help me.. Reply me on my mail id Solanki.krunal7@gmail.com if possible.
I never ran into that when working with my setup. Were you able to try any of the other formats? Or perhaps reducing the framerate. Or maybe your images are not being capture as it says Content-Length 0? Just a guess. Let me know what happens when you use the different options.
Thanks for reply, I tried with YUV format using -y in terminal window but getting the same results. My camera works well. I can have pictures through it. what main problem is I cant start mjpg streamer.
Should I cross compile it ?
please let me know, How?
What to do if mjpg streamer is not taking pictures as content lengh is zero.?
I tried with fps 1 too as shown below.
pi@raspberrypi ~/mjpg-streamer-r63 $ mjpg_streamer -i “/usr/local/lib/input_uvc.so -f 1” -o “/usr/local/lib/output_http.so -w /usr/local/www”
MJPG Streamer Version.: 2.0
i: Using V4L2 device.: /dev/video0
i: Desired Resolution: 640 x 480
i: Frames Per Second.: 1
i: Format…………: MJPEG
o: www-folder-path…: /usr/local/www/
o: HTTP TCP port…..: 8080
o: username:password.: disabled
o: commands……….: enabled
What happens when you start the streamer and then navigate to the page? http://localhost:8080 or http://IP_of_Pi:8080?
Also, are you sure your Webcam is being detected? Try running
lsusb
to see if it is listed.Also, make sure you have all the dependencies installed:
libjpeg8-dev imagemagick libv4l-dev
.Finally, just try to restart and reboot everything.
I installed all required libraries, I rebooted many times but still getting the same error.
Please help me what to do?
M streaming through the http://localhost:8080/?action=stream.
You did not post the results of the
lsusb
command. Does the Webpage show up but you just can’t get images from the Webcam?Yes exactly, lsusb command shows the camera, using different tools without mjpg-streamer, I can take pictures too. But I can’t have live streaming over Web page.
Does the actual Webpage load, though? If the page loads, but you just can’t see a steam, then it is probably an issue with the camera, or a setting pertaining to it.
Yes, actual Web page loads, I am using Microsoft lifecam vx800 camera, I can have pictures too on my pi board using this same camera, but instead of live streaming, I am getting this content length, content type message.
My guess is that your camera is not supported, or does not work with any of the formats. mjpeg_streamer is running fine since you can get to the Webpage, so it seems to me that your Webcam is the problem.
It’s Ok, but if camera have problem then I wouldn’t have images on my pi board. Don’t know what’s going wrong.
Send this command on a terminal, maybe the webcam is set to operate in another mode.
v4l2-ctl –list-formats
That’s what I meant: the Webcam works, but just not in mjpg_streamer. Try ConoscenzaCollettiva’s suggestion.
Hello Jacob,
Glad you had time to share your time and knowledge. I follow your tutorial but when running the command
svn co https://svn.code.sf.net/p/mjpg-streamer/code/mjpg-streamer/ mjpg-streamer
I get the following error
svn: E170000: URL ‘https://svn.code.sf.net/p/mjpg-streamer/code/mjpg-streamer/mjpg-streamer’ doesn’t exist
So I decide to download the source code directly from
http://sourceforge.net/projects/mjpg-streamer/files/mjpg-streamer/Sourcecode/
Could you confirm if this is the right source code? or better if you have a update download link it will be appreciated.
It has been a while since making this article. I think the URL you have works, but I also found this one:
http://sourceforge.net/code-snapshots/svn/m/mj/mjpg-streamer/code/mjpg-streamer-code-182.zip
Hello Jacob,
Thanks so much for the help. I was able to complete the entire tutorial without any issues.
One quick question. I will like to make my Raspberry pi a stand alone streaming device but I need a way to have internet on the Go! Is there a way to use a GSM Usb modem to use a cell phone sim card and have internet on the road?
I have never done this myself so I cannot say for certain, but I will try point you in the right direction.
Since a USB modem is basically just another network interface, you could probably modify
/etc/network/interfaces
to get a network address. With the setup in this tutorial, everything is pretty automatic since you are just plugging the Pi into the router, so you never really had to mess around with those settings.Hope this helps. Good luck!
the “svn: E170000” is due to a little sintax error in the short tutorial:
svn co https://svn.code.sf.net/p/mjpg-streamer/code/mjpg-streamer/mjpg-streamer
it should be:
svn co https://svn.code.sf.net/p/mjpg-streamer/code/mjpg-streamer/ mjpg-streamer
it lacks of a space between the svn repository and the last dir “mjpg-streamer”
Thanks. I fixed the code on the page. Hopefully, you won’t get that error now.
Thanks to you for the this tutorial 🙂
Got this working, thank you. But how would I include this on my main webpage served by my raspberry pi? It is on 192.168.0.6. camera works on 192.168.0.6:8080. but I want to embed the stream on my main page doesn’t do it, any idea anyone?
I guess you could try putting the full URL in the
img src
. My Pi is being used for some other projects now, so I can’t test it.Hey, Great tutorial!
I used the code which makes the streamer start at boot and i can use the service commands
But it webcam dosent start at boot, i get this error on the boot screen:
[+] Strating mjpg_streamer
/etc/init/d/livestream.sh: 20: /etc/init.d/livestream.sh: mjpg_streamer: not found
[+] mjpg_streamer started
But the service commands work
Could you please help me out
Thanks,
Abhijeet.
It’s saying mjpg_streamer is not found? Try putting the full path name in and see if that fixes it.
Hey Thanks for the reply!
Could you please tell me the full path name and where to put it in the code? Line 20 is it?
Thanks again!
Abhijeet.
If you followed the tutorial exactly, it should be in
/usr/local/bin/
.Try that full path on every line that begins with mjpg_streamer.
Hey,
Im really sorry, i didnt understand your post, could you please explain a bit in detail?
Thanks
Abhijeet
Whatever line of code begins with
mjpg_streamer
need to be changed to/usr/local/bin/mjpg_streamer
.Hey,
Thanks a lot, its working!
Thanks again!
Abhijeet.
Great. I am glad it works. I will update the code on the page so others do not run into the same issue.
Hey,
Could you tell me one last thing? I tried changing the port unsuccessfully, could you just give me the entire command of the mjpeg streamer including text to change the port, i would really appreciate it.
Thanks!
Abhijeet
I used this tutorial a month back and it worked great, but now i used the tutorial to start at boot, the webcam starts but i can’t see the stream on the mjpeg streamer website
Plz help!
Abhijeet
PS: when i ran the command to run the mjpeg streamer it works, only when i set it up to start at boot, it doesn’t
Thanks!
Hey,
Please could you update the tutorial, I have tried using the tutorial a million times! and its just not working.
Thanks
Abhijeet.
It seems to work for most people, but it is possible the guide is outdated. I am going to re-visit all my tutorials once my Raspberry Pi 2 arrives. Unfortunately, blogging is just a side gig after work.
When i used the tutorial without running sudo apt-get upgrade, it worked!!
When i used that command the webcam streaming didn’t work
Nice! I suppose updating isn’t always the best thing to do. I’m glad you figured it out!
I will buy you a couple of them if you can help me get this running! I am pulling the hair out of my bald head!…BUT, great tutorial. I really appreciate your time in making it. I am on the right path, just lost in the weeds.
It seems to work for most people, but it is possible the guide is outdated. I am going to re-visit all my tutorials once my Raspberry Pi 2 arrives. Unfortunately, blogging is just a side gig after work.
ei jacob i have a problem with microsoft lifecam cinema… start the web site but there aren’t the stream and image… the led on cam is on when start the command /usr/local/bin/mjpg_streamer -i “/usr/local/lib/input_uvc.so” -o “/usr/local/lib/output_http.so -w /usr/local/www” but no stream…
thank in advance
Does your Webcam show images without using mjpg_streamer? That would be the first step: verify the Webcam works and is supported. If it does, than there is probably some configuration with mjpg_streamer that needs to be adjusted.
yes the webcam works
could you help me?
I need more information like log files and whatnot.
i’ve installed all the package but when i do to the webpage i see the text without the stream .. my cam is a microsoft livecam cinema. why this?
I’m getting this error:
“404: Not Found!
Could not open file”
When I try to go to http://:8080
I’m like 99% sure I copied everything correctly.
A 404 means the file or page doesn’t exist. Were you able to start mjpg_streamer OK?
HI,
I am having the same logitech camera as the picture. but cannot make it work in mjpg
v4l2-ctl –list-formats
ioctl: VIDIOC_ENUM_FMT
Index : 0
Type : Video Capture
Pixel Format: ‘YUYV’
Name : YUV 4:2:2 (YUYV)
Index : 1
Type : Video Capture
Pixel Format: ‘MJPG’ (compressed)
Name : MJPEG
does anyone have a clue?
are you using the
-y YUYV
option?i have problem
It seems to be an error relating to the driver for the camera concerning the pan/tilt functionality. You should see if there is another driver to use…
http://stackoverflow.com/questions/13437244/mjpg-streaming-with-a-raspberry-pi-and-a-webcam
it is oky now thnx i just add -y YUYV
Great! Glad it works now.
I’m having the same issue, but when I try to add -y YUYV it reports back the -y is an unrecognized option. Any suggestions?
The syntax is a little weird. If I remember, I think it needs to be inside the double quotes of the
-i
section, so something like this:/usr/local/bin/mjpg_streamer -i "/usr/local/lib/input_uvc.so -y YUYV" -o "/usr/local/lib/output_http.so"...and so on...
Got it, thanks!
So it looks like there’s a patch available to update mjpg-streamer. I was following this tutorial but always came up with a blank screen (no image) until I found the patch.
Immediately before the
“make mjpg_streamer input_file.so input_uvc.so output_http.so”
command, I manually patched mjpg-streamer using this:http://www.raspberrypi.org/forums/viewtopic.php?t=97983 and now I have it working.
Just to verify, did you follow the instructions from mirak123? If so, I will add them to the walkthrough.
Download mjpg_streamer
svn checkout svn://svn.code.sf.net/p/mjpg-streamer/code/ mjpg-streamer-code
Change directories to the folder
cd mjpg-streamer-code/mjpg-streamer
Create a patch file
nano input_uvc_patch
Paste the following code into the file
--- plugins/input_uvc/input_uvc.c (revision 174)+++ plugins/input_uvc/input_uvc.c (working copy)
@@ -405,9 +405,13 @@
if(pcontext->videoIn->formatIn == V4L2_PIX_FMT_YUYV) {
DBG("compressing frame from input: %dn", (int)pcontext->id);
pglobal->in[pcontext->id].size = compress_yuyv_to_jpeg(pcontext->videoIn, pglobal->in[pcontext->id].buf, pcontext->videoIn->framesizeIn, gquality);
+ /* copy this frame's timestamp to user space */
+ pglobal->in[pcontext->id].timestamp = pcontext->videoIn->buf.timestamp;
} else {
DBG("copying frame from input: %dn", (int)pcontext->id);
- pglobal->in[pcontext->id].size = memcpy_picture(pglobal->in[pcontext->id].buf, pcontext->videoIn->tmpbuffer, pcontext->videoIn->buf.bytesused);
+ pglobal->in[pcontext->id].size = memcpy_picture(pglobal->in[pcontext->id].buf, pcontext->videoIn->tmpbuffer, pcontext->videoIn->tmpbytesused);
+ /* copy this frame's timestamp to user space */
+ pglobal->in[pcontext->id].timestamp = pcontext->videoIn->tmptimestamp;
}
#if 0
@@ -418,8 +422,6 @@
prev_size = global->size;
#endif
- /* copy this frame's timestamp to user space */
- pglobal->in[pcontext->id].timestamp = pcontext->videoIn->buf.timestamp;
/* signal fresh_frame */
pthread_cond_broadcast(&pglobal->in[pcontext->id].db_update);
Index: plugins/input_uvc/v4l2uvc.c
===================================================================
--- plugins/input_uvc/v4l2uvc.c (revision 174)
+++ plugins/input_uvc/v4l2uvc.c (working copy)
@@ -450,6 +450,8 @@
*/
memcpy(vd->tmpbuffer, vd->mem[vd->buf.index], vd->buf.bytesused);
+ vd->tmpbytesused = vd->buf.bytesused;
+ vd->tmptimestamp = vd->buf.timestamp;
if(debug)
fprintf(stderr, "bytes in used %d n", vd->buf.bytesused);
Index: plugins/input_uvc/v4l2uvc.h
===================================================================
--- plugins/input_uvc/v4l2uvc.h (revision 174)
+++ plugins/input_uvc/v4l2uvc.h (working copy)
@@ -28,6 +28,7 @@
#include
+#include
#include
#include
#include
@@ -105,6 +106,8 @@
int framecount;
int recordstart;
int recordtime;
+ uint32_t tmpbytesused;
+ struct timeval tmptimestamp;
};
/* context of each camera thread */
Apply the patch
patch -p0 < input_uvc_patch
Compile the patch
make -- USE_LIBV4L2=true clean all
Install the patch
sudo make DESTDIR=/usr/local install
I followed those instructions up until:
$ patch -p0 < input_uvc_patch
After that I returned to your guide and it worked from there.
Interesting. Thanks. I’ll add that to the original post at some point!
Im getting this error when patching
patch: **** malformed patch at line 3: if (pContext->videoIn->formatIn == V4L2_PIX_FMT_YUYV)
i have a need to display my web content locally, as take a webcam, run it into Pi, then hook into hdmi to monitor. thats it. doing demos to classrooms small groups of kids clustered around widescreenTV. whats the best way to do this?
Couldn’t you just boot up into the GUI and display it that way? I’m sure there is some app that lets you view the Webcam that way.
hi i m using raspberry pi b+ and logitech c170 camera
i followed your tutorial and i tried this command
/usr/local/bin/mjpg_streamer -i “/usr/local/lib/input_uvc.so -d /dev/video0 -n” -o “/usr/local/lib/output_http.so -w /usr/local/www”
( coz i was getting error in following command
/usr/local/bin/mjpg_streamer -i “/usr/local/lib/input_uvc.so” -o “/usr/local/lib/output_http.so -w /usr/local/www”)
it shows this
MJPG Streamer Version: svn rev: 3:172
i: Using V4L2 device.: /dev/video0
i: Desired Resolution: 640 x 480
i: Frames Per Second.: 5
i: Format…………: MJPEG
o: www-folder-path…: /usr/local/www/
o: HTTP TCP port…..: 8080
o: username:password.: disabled
o: commands……….: enabled
and there is no error but when i open the page it is not showing any image please help me
The simplest thing to try is switching formats using the
-y YUYV
option. Alternatively, there has been success installing a patch formjpg_streamer
. I will add these instructions to the how-to when I make time for it,thanx for reply
i tried this /usr/local/bin/mjpg_streamer -i “/usr/local/lib/input_uvc.so -y YUYV” -o “/usr/local/lib/output_http.so -w /usr/local/www”
and it shows
MJPG Streamer Version: svn rev: 3:172
i: Using V4L2 device.: /dev/video0
i: Desired Resolution: 640 x 480
i: Frames Per Second.: 5
i: Format…………: YUV
i: JPEG Quality……: 80
ERROR opening V4L interface: No such file or directory
Init v4L2 failed !! exit fatal
i: init_VideoIn failed
so pls help me to solve this
also i followed your instruction for installing a patch and
when i tried
svn checkout svn://svn.code.sf.net/p/mjpg-streamer/code/ mjpg-streamer-code
it shows
Checked out revision 182.
is this some kind of error ?
hey thanx well i uninstalled all the things and then again followed your steps including installing a patch and
its working welll
thank you so much
Great! Glad it worked!
Thanx a lot for the great howto! Works fine with RPi2 and surveillance station 7.
Greetz,
MM
Glad you found it useful!
Hello,
I have similar problem by getting it work.
I have followed the tut. and also set the -y YUYV option, but still get following error:
I’m using the Logitech C270 webcam which is also detected by the USB port.
Some one an Idea?
Thanks in advance,
You can try seeing what formats are supported with:
v4l2-ctl --list-formats
You will probably have luck installing the patch as described here. I mean to add it into the original post at some point, but just haven’t made time to do so.
Hi,
I also had this issue but fixed,
The solution is:
/usr/local/bin/mjpg_streamer -i “/usr/local/lib/input_uvc.so -d /dev/video0 -r 100×100 -f 100 -n -y” -o “/usr/local/lib/output_http.so -w /usr/local/www”
” Add = -d /dev/video0 ”
P.S; Jacob Salmela can you help me “look my post”.
hi, Nice Post, I got mine up by following this post and adding the yuv option . I would like to be able to create a page in my apache folder /var/www and be able to access the feed from there. any ideas on how to ?
You can embed as a stream to a Webpage, as described. You might also be able to use
mod_redirect
to redirect to the mainmjpg_streamer
page.Hey ! ran through the tutorial, installed the patch but stil getting a blank screen??
Here’s the log I get when i run the command to start capturing images::
pi@raspberrypi ~/mjpg-streamer-code/mjpg-streamer $ /usr/local/bin/mjpg_streamer -i “/usr/local/lib/input_uvc.so” -o “/usr/local/lib/output_http.so -w /usr/local/www”
MJPG Streamer Version: svn rev: 3:172
i: Using V4L2 device.: /dev/video0
i: Desired Resolution: 640 x 480
i: Frames Per Second.: 5
i: Format…………: MJPEG
Adding control for Pan (relative)
UVCIOC_CTRL_ADD – Error: Inappropriate ioctl for device
Adding control for Tilt (relative)
UVCIOC_CTRL_ADD – Error: Inappropriate ioctl for device
Adding control for Pan Reset
UVCIOC_CTRL_ADD – Error: Inappropriate ioctl for device
Adding control for Tilt Reset
UVCIOC_CTRL_ADD – Error: Inappropriate ioctl for device
Adding control for Pan/tilt Reset
UVCIOC_CTRL_ADD – Error: Inappropriate ioctl for device
Adding control for Focus (absolute)
UVCIOC_CTRL_ADD – Error: Inappropriate ioctl for device
mapping control for Pan (relative)
UVCIOC_CTRL_MAP – Error: Inappropriate ioctl for device
mapping control for Tilt (relative)
UVCIOC_CTRL_MAP – Error: Inappropriate ioctl for device
mapping control for Pan Reset
UVCIOC_CTRL_MAP – Error: Inappropriate ioctl for device
mapping control for Tilt Reset
UVCIOC_CTRL_MAP – Error: Inappropriate ioctl for device
mapping control for Pan/tilt Reset
UVCIOC_CTRL_MAP – Error: Inappropriate ioctl for device
mapping control for Focus (absolute)
UVCIOC_CTRL_MAP – Error: Inappropriate ioctl for device
mapping control for LED1 Mode
UVCIOC_CTRL_MAP – Error: Inappropriate ioctl for device
mapping control for LED1 Frequency
UVCIOC_CTRL_MAP – Error: Inappropriate ioctl for device
mapping control for Disable video processing
UVCIOC_CTRL_MAP – Error: Inappropriate ioctl for device
mapping control for Raw bits per pixel
UVCIOC_CTRL_MAP – Error: Inappropriate ioctl for device
o: www-folder-path…: /usr/local/www/
o: HTTP TCP port…..: 8080
o: username:password.: disabled
o: commands……….: enabled
Any help would be appreciated!!
Thanks
Follow these instructions to install a patch that should fix this.
Thanks a lot! got it working!
I have kept coming back to this tutorial for the last two years, thanks a lot!
No problem. I have been meaning to add those instructions into my post–I just haven’t made time to do it…
tried this
using a Raspberry Pi B+
and Logitech Quick Pro 9000
followed procedure
initially nothing appeared in the stream – blank page
applied Patch procedure (below)
still blank
then added the -y YUVY option
/usr/local/bin/mpg_streamer -i “/usr/local/lib/input_uvc.so -y YUYV” -o “/usr/local/lib/output_http.so -w /usr/local/www”
Now works great
tried Firefox on laptop and also safari on iPhone to watch stream
Thanks for the great post
Glad it is working! I have been meaning to update the post with the patch instructions, but just haven’t gotten around to it. Enjoy!
I must be missing the obvious. I had this working last year as a webcam on my Christmas tree, but now I can’t seem to get this to work.
My webcam is listed as /dev/video0, and the LED on my camera illuminates indicating it is working. However, when I visit the IP:8080, I get a webpage, but the camera images are blank. If I visit the site with the camera off, I am getting connection errors where the camera images should be.
I’m sure my camera is responding, but the images aren’t there. What the heck have I done wrong?
Somewhere in these comments there are instructions for applying a patch, which seems to fix the blank white area. I’m sorry, I haven’t had time to update that in the post yet.
I saw those comments and attempted the patch with multiple errors. Kept giving an error about invalid strings. I will have to try again and post my results, unless there is an updated patch.
Did you also try the different streaming format,
YUYV
?It’s also possible there may even be a newer version altogether that already includes the patch(es).
Nice guide 🙂
You have a small typo in “Using input_file.so to Capture Images” :
The commandline:
raspistill –nopreview -w 640 -h 480- q 5 (etc…)
Should be:
raspistill –nopreview -w 640 -h 480 -q 5 (etc…)
With kind regards
F
Thanks. I fixed the error.
Hey Jacob,
Thank you for the tutorial. However, i have a problem. I’m a bit new to all this..
I use Raspberry Pi 2 and Raspberry Pi Camera Board and i’ve tried the input_file.so way.
/usr/local/bin/mjpg_streamer -i “/usr/local/lib/input_file.so” -o “/usr/local/lib/output_http.so -w /usr/local/www”
It gives me this:
MJPG Streamer Version: svn rev: 3:172
i: ERROR: no folder specified
input_init() return value signals to exit
And if i start the mjpg_streamer and go to the ip address:8080 it shows:
404: Not Found!
Invalid input plugin number
So is it having issues with the input_file.so ?
Using raspistill gives me still pictures and they work properly.
Best regards,
Eero
Are you sure you have all the software installed? It seems to be complaining it cannot find a certain file/folder?
I think problem arising due to errors made in stage”EXPORT PATHS”. so i request you to please clarify the process of editing in detail.
I’ve used “nano” editor instead “vI” as having trouble with editing, how to define “export LIBRARY” inside bashrc.
thanks in advance.
i’m also having same problem by using RPi camera module. Please share solution if you got.
i dont know which part that i doing it wrong.
i keep getting this error when trying “/usr/local/bin/mjpg_streamer -i “/usr/local/lib/input_file.so” -o “/usr/local/lib/output_http.so -w /usr/local/www””
MJPG Streamer Version: svn rev: 3:172
i: ERROR: no folder specified
input_init() return value signals to exit
It seems one of the file paths is missing. Check to make sure they exist.
all of them exist (its mjpg_streamer, input_file.so, output_http.so, right ?)
but i keep getting the no folder error.
and when i am trying using input_uvc. i get this error
MJPG Streamer Version: svn rev: 3:172
i: Using V4L2 device.: /dev/video0
i: Desired Resolution: 640 x 480
i: Frames Per Second.: 5
i: Format…………: MJPEG
ERROR opening V4L interface: No such file or directory
Init v4L2 failed !! exit fatal
i: init_VideoIn failed
edit : and can you explain a bit more to me in the export path guide ?
i dont know where to put export LD_LIBRARY_PATH=/usr/local/lib/ in the bashrc
Are you sure your USB cam is working properly and that is uses V4L2?
im trying it with Logitech c270. somehow i got it done, but get some weird error message.
MJPG Streamer Version: svn rev: 3:172
i: Using V4L2 device.: /dev/video0
i: Desired Resolution: 640 x 480
i: Frames Per Second.: 5
i: Format…………: MJPEG
Adding control for Pan (relative)
UVCIOC_CTRL_ADD – Error: Inappropriate ioctl for device
Adding control for Tilt (relative)
UVCIOC_CTRL_ADD – Error: Inappropriate ioctl for device
Adding control for Pan Reset
UVCIOC_CTRL_ADD – Error: Inappropriate ioctl for device
Adding control for Tilt Reset
UVCIOC_CTRL_ADD – Error: Inappropriate ioctl for device
Adding control for Pan/tilt Reset
UVCIOC_CTRL_ADD – Error: Inappropriate ioctl for device
Adding control for Focus (absolute)
UVCIOC_CTRL_ADD – Error: Inappropriate ioctl for device
mapping control for Pan (relative)
UVCIOC_CTRL_MAP – Error: Inappropriate ioctl for device
mapping control for Tilt (relative)
UVCIOC_CTRL_MAP – Error: Inappropriate ioctl for device
mapping control for Pan Reset
UVCIOC_CTRL_MAP – Error: Inappropriate ioctl for device
mapping control for Tilt Reset
UVCIOC_CTRL_MAP – Error: Inappropriate ioctl for device
mapping control for Pan/tilt Reset
UVCIOC_CTRL_MAP – Error: Inappropriate ioctl for device
mapping control for Focus (absolute)
UVCIOC_CTRL_MAP – Error: Inappropriate ioctl for device
mapping control for LED1 Mode
UVCIOC_CTRL_MAP – Error: Inappropriate ioctl for device
mapping control for LED1 Frequency
UVCIOC_CTRL_MAP – Error: Inappropriate ioctl for device
mapping control for Disable video processing
UVCIOC_CTRL_MAP – Error: Inappropriate ioctl for device
mapping control for Raw bits per pixel
UVCIOC_CTRL_MAP – Error: Inappropriate ioctl for device
o: www-folder-path…: /usr/local/www/
o: HTTP TCP port…..: 8080
o: username:password.: disabled
o: commands……….: enabled
do you know what it is ?
Did you install this patch?
its worked ! thank you very much !
also do you happen know how to make it into internet using ngrok.com instread router ?
Nope, sorry.
hey, can i ask something again ?
is there any way we can save/record the video from the streaming ?
Probably, but not that I know of off hand.
With the webcam, the stream displays a blank page. How do I fix this?
I have tried different browsers with no luck.
Did you install this patch?
Thank you! It involved a little bit of tinkering with the steps but it works now! (Maybe you should add a note in your tutorial for ease of use.)
I have been meaning to or about a year now–I guess that’s what I get for part time blogging!
Good guide – well constructed and it works! I did the same for UDOO Quad. I had been trying to do the streaming with cvlc but the delay was terrible – unusable. From my UDOO quad I can get a pretty much flicker free live feed with a USB infrared camera.
Hello,
I got the mjpg-streamer working, and its very nice.
But when I use a USB serial device on another port, the python script reading from the serial port crashes. I don’t know if this is a USB driver, linux priority, or other issue. I tried using ‘niceness’ to start processes, etc. no luck. I also tried chrt to set both the video streaming and USB serial as round-robin and fifo processes with USB serial as higher priority.
When I stop the mjpg-streamer, the USB serial application works fine.
I’m using Raspberry Pi 3 with latest Raspbian released, etc.
Any ideas welcome. Has anyone else seen some issue like this?
Jerry
Thank you for your posting.
I found that I got good frame rate all be a bit jumpy “without” the mpeg-streamer. I just use Node set up as HTTP page server which can access the PI’s ram drive.
HTTP server down load one from npm HTTP-server
to test with node.js just try ;
— Camera test —-
Make file called “camtest.js” with this inside
var spawn = require(‘child_process’).spawn,
child = spawn(‘/opt/vc/bin/raspistill’, [“-w”, “320”, “-h”, “240”, “-o”, “/ram/image_stream3.jpg”, “-t”, “99999999”, “-tl”, “80” ,”-q”,”40″,”-n”, “-th”,”0:0:0″, “-awb”,”fluorescent”]);
console.log(“opened”);
—- HTML —
The Html page called “camtestpage.html” with this inside
var a=0;
function startFunc(){
setInterval(function(){ loadpic(); }, 90);
}
function loadpic(){
var image = document.getElementById(“pics”);
a++;
image.src = “image_stream3.jpg?_t=” + a;
}
Raspberry Pi Simple Image Test
make ram disk I stored it in /usr/local/bin with inside
#!/bin/bash
sudo mkdir -p /ram
sudo mount -t tmpfs -o size=100m tmpfs /ram
Works on Iphone/Ipad and Android
just set browser http://192.168.1.134:7400/camtest3.html
First of all Really nice tutorial. It works fine for me.
Is there any generic methods to get the stream through internet other than port forwarding? Means, I need to get the live stream whenever the pi is connected with internet, irrespective of the router. Is there any generic method to achieve this idea?
Thanks in advance…
You can put it in the DMZ, but I would really not suggest that. There may be some sort of software that does what you want, but even with the port forwarding I would be careful to make sure everything is secured; I knew a lot less about that kind of stuff when I first made the article…
Hey thanks for putting this together. I have used mjpg-streamer before, but not to this degree. Your tutorial here will help me greatly in my project.
I am trying to set up a baby cam using your excellent instructions. I have the video streaming just the way you outlined and although it would be nice if the frame rate were better, it is MUCH better than Motion. Here is my issue:
I want to pan and tilt using an Arduino Uno and 2 servos. That is easy, but what I am having trouble with is interfacing with Python. I cannot seem to get the buttons on the screen to work. This is the servos.rpy file:
import serial
from twisted.web.resource import Resource
Setup Arduino at correct speed
try:
arduino = serial.Serial(‘/dev/ttyACM0’, 9600)
except:
arduino = serial.Serial(‘/dev/ttyACM1’, 9600)
class MoveServo(Resource):
isLeaf = True
def render_GET(self,request):
try:
# Send value over serial to the Arduino
arduino.write(request.args[‘value’][0])
return ‘Success’
except:
return ‘Failure’
resource = MoveServo()
This is the html file:
Make Use Of DIY Security Camera
#container {
/* center the content */
margin: 0 auto;
text-align: center;
}
https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js
Left
Right
Up
Down
var servos;
$( document ).ready(function() {
servos = moveServos();
});
function moveServos() {
// Store some settings, adjust to suit
var panPos = 70,
tiltPos = 90,
tiltMax = 170,
tiltMin = 45,
panMax = 170,
panMin = 20;
return {
move:function(servo, adjustment) {
var value;
if(servo == ‘P’) {
if(!((panPos >= panMax && adjustment > 0) || (panPos <= panMin && adjustment < 0))) {
// Still within allowed range, “schedule” the movement
panPos += adjustment;
}
value = panPos + ‘P’;
}
else if(servo == ‘T’) {
if(!((tiltPos >= tiltMax && adjustment > 0) || (tiltPos <= tiltMin && adjustment < 0))) {
// Still within allowed range, “schedule” the movement
tiltPos += adjustment;
}
value = tiltPos + ‘T’;
}
// Use AJAX to actually move the servos
$.get(‘http://PI_IP_ADDRESS/servos.rpy?value=’ + value);
},
}
}
Do you have any ideas on how to get pan and tilt to work with mjpg-streamer? Thanks for getting me off to a good start in getting away from Motion. This is all that is left!
Upon further investigation, Python is expecting a clean, unused port. Mjpg-streamer uses port 8080 so when you start python twisted on port 8080 it says the port is in use. I can make the servos work (the cam pan/tilts fine) on any other port other than the image port. ANY ideas? I want the image and the buttons for movement on the same page!
After running the advanced script for running on Pi startup, what is the name of the config file where I can change the frame rate, etc?
I don’t recall, sorry; it’s been a while.
Thanks for the great blog post, it saved me a lot of time. The patch was key and is still valid and needed with the latest Raspbian (Buster) and mjpg streamer (seems that code has not change since patch was published).
The link to the patch comment is broken (comment is dated April 8, 2015 at 08:08). And the patch code in the comment is missing file names for the “#include” statements. The correct patch code is still available at https://www.raspberrypi.org/forums/viewtopic.php?f=28&t=97983 in the post dated Sat Feb 07, 2015 12:43 pm.
Thank you! Now for anyone finding this, I have finally updated the post to use mention the use of this patch–this link will take you right to my own writing of it: https://jacobsalmela.com/2014/05/31/raspberry-pi-webcam-using-mjpg-streamer-over-internet/#the_patch
You can also read the original topic linked above: https://www.raspberrypi.org/forums/viewtopic.php?f=28&t=97983#p687356
And for good measure, I also added it to the wayback machine: https://web.archive.org/web/20190922111756/https://www.raspberrypi.org/forums/viewtopic.php?f=28&t=97983
And thanks for the comment…I’m still pleasantly surprised when people are finding my old blog posts useful.