Multiple instances of omxplayer as background processes

I originally bought myself a raspberry pi for all sorts of automation needs, and as a possible means to replace the arduinos that I have running.

My first project was to get XBMC running and make use of its player to playback 720p rtsp streams from my IP cameras. This worked well, but was excessive and only allowed the playback of a single stream at a time. I was in need of a solution that allowed me to present multiple streams simultaneously and making use of as GPU acceleration as much as possible.

Finally, I reverted back to running the pure Rasbian OS for the Raspberry Pi and additionally installing the latest OMXPlayer builds. These are available from here.

Initially, this worked very well as I was able to get the OMXPlayer to present the live stream over HDMI with relative ease. It was also possible to scale and present this video in a specific area on screen.

omxplayer.bin --win x1 y1 x2 y2 rtsp://ip_address/live

However, OMXPlayer only allows a single instance be run from a session as it requires a interactive console to be alive. This was solved easily by making use of the screen function. The example below illustrates how to create a 2×2 matrix (four rtsp streams) for display on a 1920×1080 capable display. My raspberry pi averages around 15% CPU utilisation in this configuration.

screen -dmS camera1 sh -c 'omxplayer --win "0 0 960 540" rtsp://ip_address/live; exec bash'
screen -dmS camera2 sh -c 'omxplayer --win "960 0 1920 540" rtsp://ip_address/live; exec bash'
screen -dmS camera3 sh -c 'omxplayer --win "0 540 960 1080" rtsp://ip_address/live; exec bash'
screen -dmS camera4 sh -c 'omxplayer --win "960 540 1920 1080" rtsp://ip_address/live; exec bash'

From a bash scripting perspective, it is then easy to control, create and kill.

screen -X -S camera3 kill

An alternative approach would be

nohup omxplayer --win "0 0 960 540" rtsp://ip_address/live &

and to stop

killall omxplayer.bin

In a future post, I will explore cycling of feeds, dynamic allocation for any size grid, rendering of text and capturing motion.