Skip to main content

Latest post

Exploring Android Emulators: A Closer Look at MemuPlay and BlueStacks

Are you an avid gamer looking to enjoy your favorite Android games on a bigger screen? Android emulators like MemuPlay and BlueStacks are your go-to solutions. However, the question of safety often looms large when installing such software. I decided to take a plunge into the world of Android emulators, aiming to play the enthralling Warcraft Rumble, but was greeted by antivirus alerts. This prompted a deeper exploration - are MemuPlay and BlueStacks safe to use? Let’s delve into what I found out. MemuPlay: A Gamer’s Delight, but is it Safe? MemuPlay markets itself as a safe and free-to-play platform for Android gaming on PC. According to the official MemuPlay blog, it is portrayed as a safe platform that does not harbor malware, compromise Google accounts, or indulge in any shady practices like cryptocurrency mining or selling user data​1​. It earns its revenue from ads, which seems like a fair trade-off for a free gaming experience. However, as I dug deeper, I found some unsettling r

Adding Webcam support to MainsailOS

Mainsail is a beautiful, responsive and modern interface for Klipper Firmware and in this guide I will show you how to add webcam support (usb/pi webcam) to allow you to keep an eye on your 3D printer remotely!

This guide will assume that you already have a working Raspberry Pi with Klipper and Mainsail installed.

If you don’t, please check the 3DPrintBeginner tutorial on how to install Klipper and MainsailOS.

 

To add webcam support to Mainsail, we'll use mjpg-streamer—a command line application that copies JPEG frames from your camera input and combines them into a video stream that can be picked up by Mainsail's interface. 

 

Installing dependencies

Before we install mjpg-streamer we need to be sure that our host system has all the dependencies installed.

To do this, we need to open a SSH instance with our Raspberry Pi:

ssh pi@mainsailos.local 

 

If you didn’t change the password at install of after the install, the pass should be: “raspberry”

 

After that we need to install the dependencies:

sudo apt-get install build-essential libjpeg8-dev imagemagick libv4l-dev cmake git -y

 

Installing mjpeg-streamer

Now, we need to create a clone of mjpg-streamer (to checkout the sources so we can install it):

For that, just run the below commands in the terminal:

mkdir ~/mjpg-streamer
cd ~/mjpg-streamer
git clone https://github.com/jacksonliam/mjpg-streamer.git
cd mjpg-streamer/mjpg-streamer-experimental
make
sudo make install

 


Testing the webcam stream

Now we need to test the stream of the webcam.

You can use either a USB Webcam or a Raspberry Pi camera module attached via ribbon cable.

The commands are a bit different for a USB webcam or a Pi camera

USB Camera:

/usr/local/bin/mjpg_streamer -i "input_uvc.so -f 15 -r 1280x720" \
-o "output_http.so -w /usr/local/share/mjpg-streamer/www"

Pi camera:

/usr/local/bin/mjpg_streamer -i "input_raspicam.so -fps 15 -x 1640 -y 922" \
-o "output_http.so -w /usr/local/share/mjpg-streamer/www"

 

If you are using a Pi camera and the command above is not working, please make sure you have enabled pi cam support:

sudo raspi-config

 

In both cases we're telling mjpg-streamer to start a stream using your camera (USB, or Raspi), to output the stream at a framerate of 15fps and a resolution of 1280 horizontal by 720 vertical pixels (720P), and to enable http access to the stream. 

 

Test the stream

You can access(test) the webcam stream by accessing via your webbrowser the url

http://<raspberry-pi-IP>:8080?action=stream

 

If all has gone well your camera should be streaming. Congratulations! You can now stop the stream by entering CTRL+C in your terminal window. 

 

Run MJPEG-streamer on startup

First thing we need is to create a shell script:

sudo nano /etc/init.d/mainsail-stream.sh

 

This will open nano editor. Paste the following into the editor (credits for the script to Jacob) :

This is for the Pi Camera:

#!/bin/sh
# /etc/init.d/mainsail-stream.sh
### BEGIN INIT INFO
# Provides: mainsail-stream.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 "input_raspicam.so -fps 15 -x 1640 -y 922" -o "output_http.so -w /usr/local/share/mjpg-streamer/www"-b
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 "input_raspicam.so -fps 15 -x 1640 -y 922" -o "output_http.so -w /usr/local/share/mjpg-streamer/www"
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

 

And this one is for the USB Camera:

 

#!/bin/sh

# /etc/init.d/mainsail-stream.sh

### BEGIN INIT INFO

# Provides:          mainsail-stream.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 "input_uvc.so -fps 15 -x 1640 -y 922" -o "output_http.so -w /usr/local/share/mjpg-streamer/www"-b 

                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 "input_uvc.so -fps 15 -x 1640 -y 922" -o "output_http.so -w /usr/local/share/mjpg-streamer/www"

                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 you have your script pasted and any changes configured, press CTRL+X to exit the editor. The editor will ask Save modified buffer? Press Y and hit Enter/Return.

 

Enable MJPEG to run at startup

So now we need to enable the script to run at startup, if somehow Pi shutdowns/restarts, we need to start the MJPEG script also:

 

sudo chmod 755 /etc/init.d/mainsail-stream.sh
sudo update-rc.d mainsail-stream.sh defaults

 

Now we need to start the service:

sudo service mainsail-stream start

 

And also, test to see if the service is running and working as expected:

sudo service mainsail-stream status

 

Press CTRL+C to exit the above command.





Adding your webcam to Mainsail

Head over to your web browser, open Mainsail, and navigate to Settings > Interface. Here we can configure several different options related to your webcam:

  1. Access Mainsail's interface options

  2. Webcam URL: enter webcam/?action=stream in this field.

  3. Toggle this option to enable the webcam menu item on the left.

  4. Toggle this option to display your webcam in the dashboard menu item. 

 

That’s all folks :) !

 

Hope you enjoyed it!

 

Comments

  1. Many thanks for this tutorial. I followed it and was able to get the cam working (once). When i tried to start the service with "sudo service mainsail-stream start" i get the following message:

    pi@mainsailos:~ $ sudo service mainsail-stream.sh start
    Job for mainsail-stream.service failed because the control process exited with e rror code.
    See "systemctl status mainsail-stream.service" and "journalctl -xe" for details.
    pi@mainsailos:~ $ sudo service mainsail-stream status
    ● mainsail-stream.service
    Loaded: loaded (/etc/init.d/mainsail-stream.sh; generated)
    Active: failed (Result: exit-code) since Sun 2022-02-20 15:22:42 GMT; 20s ago
    Docs: man:systemd-sysv-generator(8)
    Process: 4302 ExecStart=/etc/init.d/mainsail-stream.sh start (code=exited, status=2)


    What am I doing wrong here?

    ReplyDelete
  2. I have to ssh this (/usr/local/bin/mjpg_streamer -i "input_uvc.so -y -q 75 -f 15 -r 640x480" \
    -o "output_http.so -w /usr/local/share/mjpg-streamer/www") in everytime i boot the pi. it doesnt seem to be automagicaly starting. any help on where to look or what to do. thanks this got me camera after week and i mean weeks of trying different options with my ps3 cam.

    ReplyDelete
  3. Thank you for the great article. Any way of having both of these running at the same time?

    ReplyDelete
  4. Great article. What about multiple cameras?

    ReplyDelete

Post a Comment

Popular posts from this blog

The great Twitch hack!

Twitch appears to have been hacked, leaking ALL the source code of  the streaming service, an unreleased competitor for the Steam app and also the details of creator payouts. The hacker said the purpose of the leak was to “foster more disruption and competition in the online video streaming space”, which he described as a “disgusting toxic cesspool”, according to the 4Chan post which was reviewed by the Bloomberg News. Twitch confirmed the breach and said it would provide updated when it has more information.   We can confirm a breach has taken place. Our teams are working with urgency to understand the extent of this. We will update the community as soon as additional information is available. Thank you for bearing with us. — Twitch (@Twitch) October 6, 2021 I'll recommend everyone to go and reset the password and add also a 2nd factor authentication and not the one with the SMS. You can use the Authy  app as a MFA for Twitch (it's really easy to use).

Exploring Android Emulators: A Closer Look at MemuPlay and BlueStacks

Are you an avid gamer looking to enjoy your favorite Android games on a bigger screen? Android emulators like MemuPlay and BlueStacks are your go-to solutions. However, the question of safety often looms large when installing such software. I decided to take a plunge into the world of Android emulators, aiming to play the enthralling Warcraft Rumble, but was greeted by antivirus alerts. This prompted a deeper exploration - are MemuPlay and BlueStacks safe to use? Let’s delve into what I found out. MemuPlay: A Gamer’s Delight, but is it Safe? MemuPlay markets itself as a safe and free-to-play platform for Android gaming on PC. According to the official MemuPlay blog, it is portrayed as a safe platform that does not harbor malware, compromise Google accounts, or indulge in any shady practices like cryptocurrency mining or selling user data​1​. It earns its revenue from ads, which seems like a fair trade-off for a free gaming experience. However, as I dug deeper, I found some unsettling r