f0videoplayerOsc
Making use of some old original Raspberry Pi Model A...
Despite having very little RAM (256MB) the Raspberry Pi Model A from 2012 can play video and sound in high resolution via HDMI. So here is how I set up four of them as independent remote-controlled video players. I used the program OMXplayer and the pyliblo and omxplayer-wrapper Python libraries. This setup will also work great with Raspberry Pi Zero and any other low-end model.
To control the players I use SuperCollider and send Open Sound Control messages, but other OSC capable programs or mobile apps will also work. There is a similar system that is controller via physical buttons (GPIO) described in the /f0blog/cheap-4-channel-videoplayer post.
Instructions for installing
This will require at a minimum a 4 GB SD card and a way to connect the Raspberry Pi to the internet.
Prepare the RPi
-
Burn the Raspberry Pi OS Lite image (2020-08-20-raspios-buster-armhf-lite) to the SD card
-
Enable SSH by creating an empty file in the root directory of the SD card called
ssh
.touch /Volumes/boot/ssh
-
Put the SD card in the Raspberry Pi and log in via SSH.
-
Run the following...
sudo raspi-config #set password and hostname, overclock RPi1 to 800MHz, RPi1 GPU memory = 64 sudo apt-get update sudo apt-get upgrade sudo apt-get dist-upgrade
-
And run these commands to install the required libraries...
sudo apt-get install omxplayer libdbus-1-dev python3-pip python3-liblo pip3 install omxplayer-wrapper
Copy over files
- On your laptop find a video file and name it
video.mp4
. - Download the Python script from here below (f0videoplayerOsc.py).
- Put the video and the python file in a directory (here Downloads) and in Terminal type...
cd ~/Downloads scp video.mp4 pi@192.168.1.102: #edit IP of your Raspberry Pi scp f0videoplayerOsc.py pi@192.168.1.102:
Autostart
-
Log in to your Raspberry Pi again and type...
crontab -e
-
Add the following to the end of the crontab file...
@reboot cd /home/pi && python3 f0videoplayerOsc.py video.mp4
-
Type ctrl+o and ctrl+x to save and exit.
-
Restart...
sudo reboot
Now the player should launch at boot and start looping a file in the home directory called video.mp4
. Send OSC messages to port 9999 to control it (see below).
It is fairly easy to adapt and add new commands to the Python player script. See the omxplayer-wrapper documentation. One can also query and send back information - for example about current position in video.
Test
Here is some SuperCollider code for testing...
n= NetAddr("192.168.1.102", 9999); //edit IP of your Raspberry Pi
n.sendMsg(\pause);
n.sendMsg(\play);
n.sendMsg(\set_position, 1000);
n.sendMsg(\set_position, 100);
n.sendMsg(\set_position, 10);
n.sendMsg(\hide);
n.sendMsg(\show);
n.sendMsg(\set_dimensions, 100, 100, 200, 200);
n.sendMsg(\set_dimensions, 0, 0, 1920, 1080); //display dim
n.sendMsg(\set_crop, 100, 100, 200, 200);
n.sendMsg(\set_crop, 0, 0, 640, 360); //movie dim
n.sendMsg(\set_volume, 0.0); //0.0-10.0
n.sendMsg(\set_volume, 5.0);
n.sendMsg(\set_volume, 1.0); //default
n.sendMsg(\set_rate, 1.0);
n.sendMsg(\set_rate, 0.75);
n.sendMsg(\set_rate, 0.5);
n.sendMsg(\set_rate, 0.01);
n.sendMsg(\set_rate, 1.0); //default
//slow down
(
Routine.run({
100.do{|i|
n.sendMsg(\set_rate, i.linlin(0, 99, 1.0, 0.01));
0.025.wait;
};
});
)
n.sendMsg(\set_rate, 1.0);
//zoom out
(
Routine.run({
var num= 100;
var w= 1920, h= 1080; //display dim
num.do{|i|
n.sendMsg(
\set_dimensions,
i.linlin(0, num-1, 0, w/2).asInteger,
i.linlin(0, num-1, 0, h/2).asInteger,
i.linlin(0, num-1, w, w/2+1).asInteger,
i.linlin(0, num-1, h, h/2+1).asInteger
);
0.025.wait;
};
});
)
n.sendMsg(\set_dimensions, 0, 0, 1920, 1080);
//zoom in
(
Routine.run({
var num= 100;
var w= 640, h= 360; //movie dim
num.do{|i|
n.sendMsg(
\set_crop,
i.linlin(0, num-1, 0, w/2).asInteger,
i.linlin(0, num-1, 0, h/2).asInteger,
i.linlin(0, num-1, w, w/2+1).asInteger,
i.linlin(0, num-1, h, h/2+1).asInteger
);
0.025.wait;
};
});
)
n.sendMsg(\set_crop, 0, 0, 640, 360);
//stop and shut down the Raspberry Pi
n.sendMsg(\shutdown)
References
github.com/redFrik/yetanotheroscmovieplayer
github.com/avilleret/rpi_osc_video_player
Attachments: | |
---|---|
f0videoplayerOsc.py |