Display 4 Camera RTSP Streams on Ubuntu with Mplayer and Screen

  1. Type the followins “sudo” commands in a Terminal window
  2. Install Screen

    [code]sudo apt install screen[/code]

  3. Create Configuration file named cams
  4. [code]sudo nano /etc/init.d/cams[/code]

  5. Paste the following into nano editor:

    # Provides: mplayer
    # Required-Start:
    # Required-Stop:
    # Default-Start: 2 3 4 5
    # Default-Stop: 0 1 6
    # Short-Description: Displays camera feeds for monitoring
    # Description:

    # Output mplayer to remote device if using ssh remotely
    if [ -n "$SSH_TTY" ]; then
    export DISPLAY=:0.0

    # Camera Feeds & Positions
    top_left="screen -dmS top_left sh -c ‘mplayer -noborder -x 640 -y 400 -geometry 0:0 rtsp://admin:admin@’";
    top_right="screen -dmS top_right sh -c ‘mplayer -noborder -x 640 -y 400 -geometry 640:0 rtsp://admin:admin@’";
    bottom_left="screen -dmS bottom_left sh -c ‘mplayer -noborder -x 640 -y 400 -geometry 0:400 rtsp://admin:admin@’";
    bottom_right="screen -dmS bottom_right sh -c ‘mplayer -noborder -x 640 -y 400 -geometry 640:400 rtsp://admin:admin@’";

    # Camera Feed Names
    # (variable names from above, separated by a space)
    camera_feeds=(top_left top_right bottom_left bottom_right)

    #—- There should be no need to edit anything below this line —-

    # Start displaying camera feeds
    case "$1" in
    for i in "${camera_feeds[@]}"
    eval eval ‘$’$i
    echo "Camera Display Started"

    # Stop displaying camera feeds
    sudo killall mplayer
    echo "Camera Display Ended"

    # Restart any camera feeds that have died
    for i in "${camera_feeds[@]}"
    if !(sudo screen -list | grep -q $i)
    eval eval ‘$’$i
    echo "$i is now running"

    echo "Usage: /etc/init.d/cams {start|stop|repair}"
    exit 1

    esac [/code]

  • Save the file after adjusting the rtsp url/ip address to match your cameras
  • We need to let the system use the file so we need to change the permissions on the file we just created by issuing the following command:

    [code]sudo chmod 755 /etc/init.d/cams[/code]

  • Now we can start the cameras:

    [code]sudo /etc/init.d/cams start[/code]

  • Alternately, to stop the cameras:

    [code]sudo /etc/init.d/cams stop[/code]

  • To repair (not working):

    [code]sudo /etc/init.d/cams repair[/code]

4 thoughts on “Display 4 Camera RTSP Streams on Ubuntu with Mplayer and Screen”

  1. Hey this works great!
    Is there a way to control the volume on each stream once they are running. I would like to be able to mute and unmute each stream as needed?

      • I should have looked a little harder before asking about volume.
        Alt + Tab(ing) through each instance of mplayer gets me to what ever stream I want to control and then hitting ‘m’ on the keyboard mutes and unmutes it. Perfect for my use case.
        Thanks again for the bash script!


Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.