kelvinmead
Posts: 44
Joined: Tue Feb 05, 2013 9:19 pm
Location: Bristol, UK

Re: Mjpg-Streamer

Fri Feb 15, 2013 1:57 am

In the lxterminal

And that sounds like the stupidly simple idea, but most obvious idea ever.

Ill try that!

Thanks

kelvinmead
Posts: 44
Joined: Tue Feb 05, 2013 9:19 pm
Location: Bristol, UK

Re: Mjpg-Streamer

Fri Feb 15, 2013 11:34 am

thanks, that worked.

SirLagz
Posts: 1705
Joined: Mon Feb 20, 2012 8:53 am
Location: Perth, Australia
Contact: Website

Re: Mjpg-Streamer

Sat Feb 16, 2013 7:37 am

You're Welcome :)
My Blog - http://www.sirlagz.net
Visit my blog for Tips, Tricks, Guides and More !
WiFi Issues ? Have a look at this post ! http://www.raspberrypi.org/phpBB3/viewtopic.php?f=28&t=44044

User avatar
raspBarryPi
Posts: 1
Joined: Sun Feb 17, 2013 6:46 pm

Re: Mjpg-Streamer

Sun Feb 17, 2013 6:59 pm

Hi,
followed this tutorial http://sirlagz.net/2012/08/04/how-to-st ... pberry-pi/ and it works fine! :D


For those struggling with viewing the stream:
You can't open http://10.0.0.10/webcam.mjpeg directly (at least i can't)
Had to install a webserver and embed the stream like this:

Code: Select all

<object id="MediaPlayer">
<param name="FileName" value="MyStream.mjpg">
<param name="AutoStart" value="True">
<param name="ShowControls" value="True">
<embed src="http://10.0.0.10/webcam.mjpeg" type="video/mpeg" debug="true">
</embed>
</object>
Works on Firefox, Chrome, Sarafi, Opera. But not on IE (because IE does not support mjpeg)

When you get "bind(port 80): Address already in use" run this:

Code: Select all

pkill -e ffserver
It kills the running ffserver process, so you can safely start it again!


I have just one problem.
How can i make webcam.sh run at system boot?
I would like the webcam to start streaming automatically, right after Raspberry is connected to the power supply.
Tried messing with symlinks in /etc/init.d and crontab, but it didn't work.
Ideas anyone?

SirLagz
Posts: 1705
Joined: Mon Feb 20, 2012 8:53 am
Location: Perth, Australia
Contact: Website

Re: Mjpg-Streamer

Mon Feb 18, 2013 12:10 am

Glad the tutorial helped :)

In Rasbpian -
If you want webcam.sh to start automatically, copy one of the existing /etc/init.d/ scripts to /etc/init.d/webcam.sh, modify the internals to what you need it to do, and then run

Code: Select all

update-rc.d webcam start defaults
<-- I think that's the command.
That will update the things needed.
My Blog - http://www.sirlagz.net
Visit my blog for Tips, Tricks, Guides and More !
WiFi Issues ? Have a look at this post ! http://www.raspberrypi.org/phpBB3/viewtopic.php?f=28&t=44044

danjperron
Posts: 3511
Joined: Thu Dec 27, 2012 4:05 am
Location: Québec, Canada

Re: Mjpg-Streamer

Mon Feb 18, 2013 2:08 am

Since I complete my system to control the heat of my pond and it has a web cam using mjpg_streamer.
I decide to capture one image every minute and create a small video.

I use wget application to stream one image and transfer it to a tmpfs folder. I don't like to write to the sdcard too often. Then I transfer the capture image via FTP to an external location (My cloud WD disk).

So this is my original streamer script. It is call at startup in /etc/rc.local .


script streamer1080p.sh

Code: Select all

killall mjpg_streamer
/usr/local/bin/mjpg_streamer -i "/usr/local/lib/input_uvc.so -n -f 10 -r 1920x1080" -o "/usr/local/lib/output_http.so -p 10088 -w /usr/local/www" &
This is the python script to capture one image and transfer it via FTP

Code: Select all

#!/usr/bin/python
import time
import os
import sys
import re
import subprocess
import datetime

now = datetime.datetime.now()

# capture image
SnapImage = "/var/www/chart/data/image.jpg"
subprocess.call(["/usr/bin/wget","-O",SnapImage,"http://127.0.0.1:10088/?action=snapshot"])

# create a stamp image file
StampImage = "PondImg_" + now.strftime("%Y_%m_%d_%H_%M_%S") + (".jpg")

# transfer image to mycloud WD disk
subprocess.call(["/usr/local/bin/FtpImage.sh",SnapImage,StampImage,"RPi","My8assword"])
This is the bash script to transfer via FTP

Code: Select all

#!/bin/bash

IN_LOCAL=$1
OUT_REMOTE=$2

USER=$3
PASSWD=$4
sleep 5
ftp -v -n 10.11.12.4 <<END_OF_SESSION
user $USER $PASSWD
cd /Daniel/PiData/Images
prompt off
binary
put $IN_LOCAL $OUT_REMOTE
bye
END_OF_SESSION
Also if your webcam has auto focus, mine does (logitech C-920), you will need to disable it.

use uvcdyctrl.
uvcdynctrl -c will show you a list of all parameters. Check for Focus or something similar.

Code: Select all

uvcdynctrl -s "Focus, Auto" 0

At the last thing is to combine all the images and create this video

http://dl.dropbox.com/u/48891705/TheSunFalling.mp4

be aware it is 1080P. (save the file and play it).


Daniel
Last edited by danjperron on Sun Mar 17, 2013 7:59 pm, edited 1 time in total.

danjperron
Posts: 3511
Joined: Thu Dec 27, 2012 4:05 am
Location: Québec, Canada

Re: Mjpg-Streamer

Thu Feb 21, 2013 5:46 pm

From all the images collected from the Snapshot.py script I decide that it could be nice to create a daily movie of it.


First I fix the code of the previous script. (replace subprocess.popen with the call function). I want the wait until the image is captured before sending it to the ftp server.


Code: Select all

#!/usr/bin/python
import time
import os
import sys
import re
import subprocess
import datetime

now = datetime.datetime.now()

# capture image

SnapImage = "/var/www/chart/data/image.jpg"

subprocess.call(["/usr/bin/wget","-O",SnapImage,"http://127.0.0.1:10088/?action=snapshot"])

# create a stamp image file
StampImage = "PondImg_" + now.strftime("%Y_%m_%d_%H_%M_%S") + (".jpg")


# transfer image to mycloud WD disk

subprocess.call(["/usr/local/bin/FtpImage.sh",SnapImage,StampImage,"RPi1","pass8ord"])


And now the script to convert captures images on every minutes from mjpeg_streamer to a mp4 video.


1 - mount images resource. For me is a remote network drive but it could be a USB stick.
2 - create software link with each image sorted in times and with filename using a number scheme.
3 - use avconv converter to create the mp4 video.
4 - Delete the link files.
5 - Delete the jpg files.
6 - Unmount images resource. (if your usb stick is always attach don't do it).

Code: Select all

#!/usr/bin/python
import datetime
import os
import sys
import subprocess
import glob
# ===================
# this routine will create a daily movie 
# from the collected jpg images of the previous day
# first it will create link using number order filename
# and then it will use ffmpeg to create a mp4 movie
#


# some define function
def mkdirp(directory):
    if not os.path.isdir(directory):
        os.makedirs(directory)


# Ok get the date of yesterday

yesterday = datetime.datetime.now() - datetime.timedelta(1)

# since I transfer the jpg to an other computer/or drive
# let's mount the device if it is not mounted
# I'm using a cloud WD network drive  so we will mount it


subprocess.call(["/bin/mount","-t","cifs","-o","user=RPi1,pass=pass8word","//10.11.12.4/Daniel/PiData","/mnt/wd"])

# now let's erase all link from my tmpfs folder

#first create the folder if it is not there

movieLink= "/var/www/chart/data/MovieLink"

mkdirp(movieLink)

#delete all link inside the folder if any


files = glob.glob(movieLink + "/*")
for f in files:
    os.remove(f)

#ok now set  the filename mask
mask= "/mnt/wd/Images/PondImg_"+ yesterday.strftime("%Y_%m_%d_") + "*.jpg"

#ok now creation of the link

counter=1

# python link doesn't work! crossdevice not permitted
# we will use  /bin/ln -s


files = sorted(glob.glob(mask))

for file in files:
   destlink = movieLink + ("/img%04d.jpg" % (counter))
   print "try to link: " + file + "with " + destlink
   subprocess.call(["/bin/ln","-s",file,destlink])
   counter += 1

#and now the main thing

mkdirp("/mnt/wd/DailyMovie")

MovieFile = "/mnt/wd/DailyMovie/Pond_" + yesterday.strftime("%Y_%m_%d") + ".mp4"

subprocess.call(["/usr/bin/avconv","-f","image2","-r","10","-i","/var/www/chart/data/MovieLink/img%04d.jpg","-b","4000k","-r","10","-c:v","mpeg4","-s","1024x576",MovieFile])

#ok done now let's remove the link

filelink = glob.glob(movieLink + "/*")
for f in filelink:
    os.remove(f)

# remove all the jpeg file

for file in files:
    os.remove(file);

#and now let's remove the mount

subprocess.call(["/bin/umount","/mnt/wd"])



Maybe it is a good idea to disable the images files removal until you know that everything is working


And the last thing to do will be to start the script every day using crontab -e . Add the following lines into it

Code: Select all

 */1 * *   *   *     /usr/local/bin/Snapshot.py
 0   0 *   *   *     /usr/bin/python /usr/local/bin/DailyMovie.py
This will capture an Image every minute and at midnight every day it will convert all the captured images into a mp4 video. (You could replace the */1 by *. It is just easier to read).

P.S. I changed the resolution of the image capture. I really don't need to be full 1080P.

Daniel

lauraspberryPI
Posts: 5
Joined: Tue Mar 12, 2013 11:11 am

Re: Mjpg-Streamer

Wed Mar 13, 2013 6:09 pm

¿alguien tiene el pluging de rtp o udp para hacer streaming con mjpg-streamer?

User avatar
skidoobond
Posts: 40
Joined: Mon Feb 25, 2013 8:26 pm

Re: Mjpg-Streamer

Thu Mar 28, 2013 7:36 pm

I have also tried these instructions and the various command line changes. I didn't get any make errors or any indication that something is wrong. When I point my pc browser to the pi, firefox says it is unable to connect. I can start and stop motion and the camera's led responds accordingly. It doesn't appear that the mjpg-streamer is doing anything.

cgenco
Posts: 1
Joined: Wed Apr 10, 2013 6:12 am

Re: Mjpg-Streamer

Wed Apr 10, 2013 6:16 am

The problem raised in one of the first posts when installing MJPG-streamer of:

Code: Select all

linux/videodev.h: No such file or directory
Is fixed by symlinking it as described in http://stackoverflow.com/questions/5842 ... untu-11-04:

Code: Select all

sudo apt-get install libv4l-dev
cd /usr/include/linux
sudo ln -s ../libv4l1-videodev.h videodev.h

leprasmurf
Posts: 1
Joined: Wed Aug 07, 2013 2:03 am

Re: Mjpg-Streamer

Wed Aug 07, 2013 2:08 am

Here's an init script that's working for me. I copied parts of it from the nginx init script.

Code: Select all

#!/bin/bash

### BEGIN INIT INFO
# Provides:          mjpg_streamer
# Required-Start:    $network
# Required-Stop:     $network
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: mjpg_streamer for webcam
# Description:       Stream a video device over http.  http://<ip>:<port>/?action=stream
### END INIT INFO

PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin";
DAEMON="/usr/bin/mjpg_streamer";
NAME="mjpg_streamer";
DESC="MJPEG Streamer";

VIDEO_DEV="/dev/video0";
RESOLUTION="640x480";
FRAME_RATE="20";
JPEG_QUALITY="75";
PORT="8080";
WEB_DIR="/var/www/mjpg_streamer";
PID_FILE="/var/run/${NAME}.pid";

TXT_RESET=$(tput sgr0);
TXT_RED=$(tput setaf 1);
TXT_GREEN=$(tput setaf 2);
TXT_YELLOW=$(tput setaf 3);
TXT_BLUE=$(tput setaf 4);
TXT_PURPLE=$(tput setaf 5);
TXT_CYAN=$(tput setaf 6);
TXT_WHITE=$(tput setaf 7);
TXT_BOLD=$(tput bold);

# Include defaults if available
if [ -f /etc/default/mjpg_streamer ];
then
        . /etc/default/mjpg_streamer;
fi

test -x ${DAEMON} || exit 0;

. /lib/lsb/init-functions;

function check_process {
        if [ -f /var/run/mjpg_streamer.pid ];
        then
                PID=`cat ${PID_FILE}`;
        else
                echo -n "${PID_FILE} does not exist";
        fi

        if [ "$( ps -p ${PID} -o comm= )" == "mjpg_streamer" ];
        then
                return 0;
        else
                return 1;
        fi
}

function start_mjpeg_daemon {
        echo -n "Starting ${DESC}";

        start-stop-daemon --quiet --background --pidfile ${PID_FILE} --make-pidfile --exec ${DAEMON} --start -- -i "/usr/lib/input_uvc.so -d ${VIDEO_DEV} -n -r ${RESOLUTION} -f ${FRAME_RATE} -q ${JPEG_QUALITY}" -o "/usr/lib/output_http.so -p ${PORT} -w ${WEB_DIR}" || true;

        sleep 1;

        # If check_process returns 0, process started successfully
        if check_process;
        then
                echo -e "\t\t[${TXT_GREEN}Done${TXT_RESET}]";
        else
                echo -e "\t\t[${TXT_RED}Failed${TXT_RESET}]";
        fi
}

function stop_mjpeg_daemon {
        echo -n "Stopping ${DESC}";
        start-stop-daemon --stop --quiet --pidfile ${PID_FILE} || true;

        sleep 1;

        # If check_process returns 1, process stopped successfully
        if check_process;
        then
                echo -e "\t\t[${TXT_RED}Failed${TXT_RESET}]";
                exit 1;
        else
                echo -e "\t\t[${TXT_GREEN}Done${TXT_RESET}]";
        fi
}

case "${1}" in
        start)
                start_mjpeg_daemon;
                ;;
        stop)
                stop_mjpeg_daemon;
                ;;
        restart)
                echo "Restarting ${DESC}: ";
                stop_mjpeg_daemon;
                sleep 1;
                start_mjpeg_daemon;
                ;;
        status)
                status_of_proc -p ${PID_FILE} "${DAEMON}" mjpg_streamer && exit 0 || exit $?;
                ;;
        *)
                echo "Usage: ${NAME} {start|stop|restart|status}" >&2;
                exit 1;
                ;;
esac;

exit 0;

masterpete
Posts: 1
Joined: Thu Jan 16, 2014 6:31 am

Re: Mjpg-Streamer

Thu Jan 16, 2014 6:32 am

Hi,
i ve read the thread and you use uvcdyctrl

How to get this?
Can i disable the LED o my logitech cams?

leopard891
Posts: 1
Joined: Mon Mar 24, 2014 3:35 pm

Re: Mjpg-Streamer

Mon Mar 24, 2014 3:41 pm

Can someone makes github repository for capturing video with python? I think it would be worthfull to anyone. or can some one explain step by step how to run code above?

hussain
Posts: 3
Joined: Wed Mar 19, 2014 9:32 am

Mjpg-Streamer

Sat Apr 12, 2014 7:21 am

i am streaming video using MJPG-STREAMER on my pi
and is working very fine
my problem is i want to store streamed video on my pi

sadiqodho
Posts: 3
Joined: Sat Jul 26, 2014 5:46 am
Location: Pakistan
Contact: Website

Re: Mjpg-Streamer

Sat Jul 26, 2014 6:11 am

I have installed successfully 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: 640x480 Init v4L2 failed !! exit fatal i: init_VideoIn failed

any suggestion

danjperron
Posts: 3511
Joined: Thu Dec 27, 2012 4:05 am
Location: Québec, Canada

Re: Mjpg-Streamer

Sat Jul 26, 2014 12:03 pm

Hi,

What kind of webcam are you using?

Did you check if your webcam is mjpeg compatible?

uvcdynctrl -f

There is another post about mjpeg-streamer http://www.raspberrypi.org/forums/viewt ... 68#p471868

Daniel

sadiqodho
Posts: 3
Joined: Sat Jul 26, 2014 5:46 am
Location: Pakistan
Contact: Website

Re: Mjpg-Streamer

Sun Jul 27, 2014 4:44 am

I am using this device

Bus 001 Device 006: ID 041e:4034 Creative Technology, Ltd Webcam Instant

Kindly tell me step by step i am new on linux.

danjperron
Posts: 3511
Joined: Thu Dec 27, 2012 4:05 am
Location: Québec, Canada

Re: Mjpg-Streamer

Mon Jul 28, 2014 12:41 am

The first thing to test is the mjpeg compatibility

First install uvcdynctrl

sudo apt-get install uvcdynctrl

and run it

sudo uvcdynctrl -f

and check if you have MJPG format . If you don't have "MJPG" , it won't work.

Code: Select all

pi@raspberrypiRobot:~# sudo uvcdynctrl -f
Listing available frame formats for device video0:
Pixel format: YUYV (YUV 4:2:2 (YUYV); MIME type: video/x-raw-yuv)
  Frame size: 640x480
    Frame rates: 30, 25, 20, 15, 10, 5
...
...
Pixel format: MJPG (MJPEG; MIME type: image/jpeg)
  Frame size: 640x480
    Frame rates: 30, 25, 20, 15, 10, 5
...
...
  Frame size: 1024x576
    Frame rates: 30, 25, 20, 15, 10, 5
  Frame size: 1280x960
    Frame rates: 30, 25, 20, 15, 10, 5
pi@raspberrypiRobot:~# 

This will list all the available format with the resolution and frame rate.

Daniel

ranma1988
Posts: 10
Joined: Wed Nov 21, 2012 7:02 pm

Re: Mjpg-Streamer

Mon Jul 28, 2014 7:04 am

masterpete wrote: How to get this?
Can i disable the LED o my logitech cams?
keep it simple: use electrical tape to disable led;)

TheQWERTYCoder
Posts: 5
Joined: Sat Dec 15, 2018 5:44 pm

Re: Mjpg-Streamer

Wed Sep 04, 2019 8:00 pm

Just clone the newest version of mjpg-streamer from github (use the one with added raspberry pi support), open the "mjpg-streamer-experimental" folder and run

Code: Select all

make -B -i | make install -B -i
, then you can run mjpg-streamer with the command

Code: Select all

mjpg_streamer
.

TheQWERTYCoder
Posts: 5
Joined: Sat Dec 15, 2018 5:44 pm

Re: Mjpg-Streamer

Wed Sep 04, 2019 8:05 pm

danjperron wrote:
Mon Jul 28, 2014 12:41 am
The first thing to test is the mjpeg compatibility

First install uvcdynctrl

sudo apt-get install uvcdynctrl

and run it

sudo uvcdynctrl -f

and check if you have MJPG format . If you don't have "MJPG" , it won't work.

Code: Select all

pi@raspberrypiRobot:~# sudo uvcdynctrl -f
Listing available frame formats for device video0:
Pixel format: YUYV (YUV 4:2:2 (YUYV); MIME type: video/x-raw-yuv)
  Frame size: 640x480
    Frame rates: 30, 25, 20, 15, 10, 5
...
...
Pixel format: MJPG (MJPEG; MIME type: image/jpeg)
  Frame size: 640x480
    Frame rates: 30, 25, 20, 15, 10, 5
...
...
  Frame size: 1024x576
    Frame rates: 30, 25, 20, 15, 10, 5
  Frame size: 1280x960
    Frame rates: 30, 25, 20, 15, 10, 5
pi@raspberrypiRobot:~# 

This will list all the available format with the resolution and frame rate.

Daniel
The Raspberry Pi Camera has built-in hardware support for JPEG, H.264, and MJPEG. You do realize that if OP was going to try MJPEG streaming, they would get a camera with support for MJPEG, right?

danjperron
Posts: 3511
Joined: Thu Dec 27, 2012 4:05 am
Location: Québec, Canada

Re: Mjpg-Streamer

Wed Sep 04, 2019 9:57 pm

@TheQWERTYCoder

You do realize that you comment something I wrote in 2014!

And yes at that time it was for an USB camera. The application mjpegstreamer is for mjpeg usb cam anyway. Why I will use that application with a none mjpeg camera.
B.T.W. Is still the best web cam application for video streaming since the cpu usage is minimal.

Return to “General discussion”