Compare commits

...

32 Commits

Author SHA1 Message Date
Filip Borum Poulsen a0f3153c26 audio device 2 years ago
Filip Borum Poulsen eee6e3cdce FIX wrong path 2 years ago
Filip Borum Poulsen dc26148e4d Restart video-player before network 2 years ago
Filip Borum Poulsen 1db8e721fa REMOVED sudo from install command 2 years ago
Filip Borum Poulsen 41a77d954d UPDATE title 2 years ago
Filip Borum Poulsen 5636eddf67 REVERT 2 years ago
Filip Borum Poulsen 60d69c6769 FIX home dir 2 years ago
Filip Borum Poulsen f04358a71c FIX 2 years ago
Filip Borum Poulsen 688e1e31cd ADD restart 2 years ago
Filip Borum Poulsen b6f41b34ae ADD H2 2 years ago
Filip Borum Poulsen 893e147cc3 REVERT and add video file name notice 2 years ago
Filip Borum Poulsen 12869d9060 FIX file location 2 years ago
Filip Borum Poulsen df4b9ffc0c AUTO start video.mp4 2 years ago
Filip Borum Poulsen e7cbcfdd18 FIX 2 years ago
Filip Borum Poulsen a5a5b81b06 FIX restart 2 years ago
Filip Borum Poulsen 02f0457143 FIX permissions 2 years ago
Filip Borum Poulsen d4a4811352 FIX user 2 years ago
Filip Borum Poulsen 94f5576449 FIX username 2 years ago
Filip Borum Poulsen 06c19a6eb7 ADD play video after reboot 2 years ago
Filip Borum Poulsen 85b5121a45 FIX install script 2 years ago
Filip Borum Poulsen ecd6cef529 Refactor video directory handling 2 years ago
Filip Borum Poulsen af1e8c780c Update video directory path 2 years ago
Filip Borum Poulsen cb236b8b45 Add web interface access instructions 2 years ago
Filip Borum Poulsen d04d14374f Add installation instructions for Raspberry Pi video player 2 years ago
Filip Borum Poulsen dfb6add3e1 Add check for directory existence in video route 2 years ago
Filip Borum Poulsen 2222d27b55 Add styling for video player 2 years ago
Filip Borum Poulsen 8f3a7d320c FIX git pull in working dir 2 years ago
Filip Borum Poulsen 636d261002 Add display and user configuration to video-player.service 2 years ago
Filip Borum Poulsen a4c48aafb5 Add git pull command to install script 2 years ago
Filip Borum Poulsen 27b2190ceb UPDATED install script to reload systemd service file 2 years ago
Filip Borum Poulsen 27d6af629d FIXED samba directory 2 years ago
Filip Borum Poulsen 5bf9abe89f FIX WorkingDirectory in service file 2 years ago

@ -0,0 +1,32 @@
# Raspberry pi video player
## How to install
1. Install Raspberry Pi Imager on your local computer from <https://www.raspberrypi.com/software/>
![Install Raspberry Pi Imager](/docs/install-imager.png)
1. Select `Raspberry Pi OS (64-bit)` in Pi Imager
![Select Pi Os](/docs/pi-os.png)
1. Configure Wifi details and `pi` user credentials using the settings in the imager.
![Imager Settings](/docs/imager-settings.png)
1. Flash the SD card
1. Insert it into the Pi and boot it up.
1. Run the following command on the Pi either via ssh or in the terminal from the desktop
```bash
curl https://git.bpfilip.dk/fbp/video-player/raw/branch/main/install.sh | bash
```
1. Access the web interface by typing the ip address of the pi in a web browser followed by the port `:8080`. Fx:
```
http://192.168.25.219:8080
```

@ -0,0 +1,4 @@
[Desktop Entry]
Type=Application
Name=Clock
Exec=sudo systemctl start video-player2.service

Binary file not shown.

After

Width:  |  Height:  |  Size: 86 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 164 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

@ -17,7 +17,7 @@ app.use(express.static('public'));
let videoDirs = [
'./public/videos',
'/media/pi/USB',
'/media/pi',
'/video'
];
@ -42,46 +42,76 @@ app.get('/videos', (req, res) => {
const list = [];
for (const dir of videoDirs) {
fs.readdirSync(dir, { recursive: true }).forEach(fileName => {
if (!fileEndings.includes(path.extname(fileName))) {
return;
try {
if (!fs.existsSync(dir)) {
continue;
}
const file = {
name: fileName,
path: path.resolve(dir, fileName)
};
list.push(file);
});
fs.readdirSync(dir, { recursive: true }).forEach(fileName => {
if (!fileEndings.includes(path.extname(fileName))) {
return;
}
const file = {
name: fileName,
path: path.resolve(dir, fileName)
};
list.push(file);
});
}
catch (error) {
console.error(error);
}
}
res.json(list);
});
let process = null;
let mayRestart = false;
// if (fs.existsSync('/tmp/video')) {
// const initialVideo = fs.readFileSync('/tmp/video');
// startVideo(initialVideo);
// }
function startVideo(path) {
process = require('child_process').spawn('ffplay', ['-fs', '-loop', '2147483647', '-hide_banner', '-loglevel', 'error', path]);
process.stdout.on('data', (data) => {
console.log(`stdout: ${data}`);
});
process.stderr.on('data', (data) => {
console.error(`stderr: ${data}`);
});
process.on("exit", () => {
if (!mayRestart) {
startVideo(path);
}
});
}
fs.mkdirSync('/video', { recursive: true });
app.post('/play', (req, res) => {
if (process) {
mayRestart = true;
process.kill();
mayRestart = false;
}
let video = req.query.video;
console.log(video);
if (video.startsWith('/media/pi/USB')) {
fs.copyFileSync(video, path.join('/tmp/', path.basename(video)));
video = path.join('/tmp/', path.basename(video))
if (video.startsWith('/media/pi')) {
fs.copyFileSync(video, path.join('/video/', path.basename(video)));
video = path.join('/video/', path.basename(video))
}
process = require('child_process').spawn('ffplay', ['-fs', '-loop', '2147483647', '-hide_banner', '-loglevel', 'error', video], { stdio: 'overlapped' });
process.stdout.on('data', (data) => {
console.log(`stdout: ${data}`);
});
fs.writeFileSync('/tmp/video', video);
process.stderr.on('data', (data) => {
console.error(`stderr: ${data}`);
});
startVideo(video);
res.json({ status: 'ok' });
});
@ -95,11 +125,17 @@ app.post('/upload', function (req, res) {
// The name of the input field (i.e. "sampleFile") is used to retrieve the uploaded file
const uploadPath = path.join(__dirname, '/public/videos/');
req.files.file.mv(uploadPath + req.files.file.name, function (err) {
req.files.file.mv(uploadPath + "video.mp4", function (err) {
if (err) {
return res.status(500);
}
});
try {
require('child_process').spawn('sudo', ['systemctl', 'restart', 'video-player2.service']);
} catch (error) {
console.error(error);
}
res.redirect('/');
});

@ -1,6 +1,6 @@
#!/bin/bash
cd /home/pi
cd ~
# Install the required packages
sudo apt update -y
@ -8,13 +8,17 @@ sudo apt install -y git curl wget nodejs npm samba samba-common-bin
git clone https://git.bpfilip.dk/fbp/video-player.git
pushd /home/pi/video-player
sudo chown -R steady:steady ~/video-player
pushd ~/video-player
git pull
npm install
# Create the samba share
sudo mkdir -p /video
sudo chown -R pi:pi /video
sudo chown -R steady:steady /video
sudo chmod -R 777 /video
cat smb.conf | sudo tee -a /etc/samba/smb.conf
@ -22,7 +26,14 @@ cat smb.conf | sudo tee -a /etc/samba/smb.conf
sudo systemctl restart smbd
sudo cp video-player.service /etc/systemd/system/video-player.service
sudo cp video-player2.service /etc/systemd/system/video-player2.service
sudo systemctl daemon-reload
sudo systemctl enable video-player.service
sudo systemctl start video-player.service
sudo systemctl disable video-player2.service
sudo systemctl restart video-player.service
sudo systemctl restart video-player2.service
mkdir ~/.config/autostart
cp clock.desktop ~/.config/autostart/clock.desktop
popd

@ -4,8 +4,22 @@
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>PI Video Player</title>
<style>
#videos {
display: flex;
flex-wrap: wrap;
justify-content: center;
flex-direction: column;
width: fit-content;
margin: 0 auto;
}
#videos button {
margin: 2px;
}
</style>
</head>
<body>
<h1>Upload a file and it should start playing</h1>
<form ref='uploadForm'
id='uploadForm'
action='/upload'

@ -1,5 +1,5 @@
[video]
path = /path/to/video/folder
path = /video
writable = yes
guest ok = yes
create mask = 0777

@ -3,7 +3,12 @@ Description=Video Player
After=multi-user.target
[Service]
ExecStart=node /home/pi/video-player/index.js
WorkingDirectory=/home/steady/video-player
ExecStart=node /home/steady/video-player/index.js
Environment=DISPLAY=:0
User=1000
Group=1000
Restart=always
[Install]
WantedBy=multi-user.target

@ -0,0 +1,11 @@
[Unit]
Description=Video Player
[Service]
WorkingDirectory=/home/steady/video-player
ExecStart=ffplay -fs -loop 2147483647 /home/steady/video-player/public/videos/video.mp4
Environment=DISPLAY=:0
Environment=AUDIODEV="hw:2,0"
User=1000
Group=1000
Restart=always
Loading…
Cancel
Save