Media center setup
Go to file
2024-04-16 19:27:39 +02:00
etc Reorganization and scripts fixing 2024-04-16 19:27:39 +02:00
utilities Reorganization and scripts fixing 2024-04-16 19:27:39 +02:00
README.md Reorganization and scripts fixing 2024-04-16 19:27:39 +02:00

media-center-setup

This is my setup for my media center. Its main purpose is for me to be able to replicate it, in case of need. However, with a few modifications, it can be a great way for you to have a Raspberry Pi with the following features:

  • an mpd server to stream local music, with an equalizer and snapcast support to stream.
  • an Airplay capable machine (for Apple Music for example).
  • a place to organize and stream videos through Samba and NFS.

Prerequisites

  • An SD card, with the latest 64-bit Raspberry Pi OS installed on it. Use Raspberry Pi imager for that purpose.
  • A Raspberry Pi, where the firmware has been updated with the possibility of USB booting.

First configuration

  • Insert the SD card in the Pi, start up, and SSH to it.
  • Be sure to be in the wanted distribution target. For instance, I regularly need to be in testing, for mpd to be up to date. This can be done my modifying /etc/apt/sources.list. I usually type in the explicit name of testing (currently trixie) to be sure where I'm at.
  • Run sudo apt update && sudo apt dist-upgrade && sudo apt upgrade to update the system to the last version we need.
  • Run sudo apt install mpd mpc libasound2-plugin-equal shairport-sync snapserver samba nfs-kernel-server vim to install the needed packages.

Copying the SD card data to the USB media

Please note that this step can be done after the other configurations are performed, as most of the things will be copied from the SD card to the USB media device.

  • Transfer the utilities folder to your Pi.
  • Inside, there is a folder called usb-boot. It comes from RonR, a user from the Raspberry Pi forums. You can also download it here. The version included in this repository is from Feb 11, 2024.
  • Run usb-boot.sh.
  • You can now remove your SD card and boot the system from the USB media device.

Configuring the audio

  • I use a HifiBerry DAC. For that purpose, I need to do the following:
    • update /boot/config.txt
    • remove dtparam=audio=on
    • add dtoverlay=hifiberry-dacplusadc (find what you need on the documentation)
    • while you're on this file, you can also disable things you probably don't need like bluetooth (dtoverlay=disable-bt) or WiFi (dtoverlay=disable-wifi).
  • Copy the /etc/asound.conf file.
  • You can use the equalizer.sh script to configure the equalizer. A value I like is 74-66-64-66-72-72-66-64-66-74.

Troubleshooting audio

If you're having trouble with the Raspberry Pi audio, try one of the following things:

  • sudo raspi-config => 1 System Options => S2 Audio.
  • list your devices with aplay -l.
  • try speaker-test -c 2, it should output sound.
  • you can also try speaker-test -D hw:<card number>,<device number>.

Configuring mpd

My music is copied with rsync through my NAS. For that purpose I use a set of scripts, that you would have to modify to suit your needs.

  • Fist, we create a folder where we'll mount to NAS: mkdir /media/mantis-music.
  • Then a folder where to copy the music: mkdir /home/pi/music.
  • Use to script to copy locally the music: utilities/1-update-music.sh.
  • Edit /etc/mpd.conf and add the content from this repository.
  • Run mpc update, then mpc ls to try to play something with mpc play.
  • Test right away, it should output sound if you've rightly configured your audio.

Going further

  • You can extract the cover of audio files and uploading them to your NAS by running utilities/2-cover-upload.sh.
  • You can remove unwated files (such as .DS_Store and Thumbs.db) and uploading these changes to your NAS by running utilities/3-remove-unwanted-files.sh.

Configuring sharing

Samba

I use Samba to be able to organize my videos through my Windows machine.

  • Edit /etc/samba/smb.conf and add the content from this repository.
  • Then set up a password for the user pi: sudo smbpasswd -a pi
  • You should be able to connect to it.

NFS

NFS is used to communicate with my Linux machine reading videos through Kodi.

  • Edit /etc/exports and add the content from this repository.
  • You should be able to connect to it.

video-info.sh

Use case

I bought a machine named Vero 4K+, running OSMC, to read my video library on my TV. It works fine on a number of files, but was struggling on some others, when no hardware decoder was available. I found this thread that gave a first hint. I then decided to made a quick list of all the format of my files, to be able to test them.

Usage

video-info.sh generates a CSV file with the format, the format profile, and the codec ID. It can be opened with any spreadsheet software. If it is interrupted, an option to resume the operation is available, so that it is possible to launch it multiple time on huge video libraries.

It generates a file named videoinfo-date_hour.csv in the folder where the videos are located.

By default, only the following file extensions are taken into account: mkv, mp4, and avi. You can easily add more by modifying the script. You can know which file extensions you have in your library by typing the following command (more on this thread):
find . -type f | sed -e 's/.*\.//' | sed -e 's/.*\///' | sort | uniq -c | sort -rn

Utilities

  • 1-update-music.sh mounts the NAS and downloads music to the Raspberry Pi.
  • 2-cover-upload.sh extracts a cover.jpg file from songs and uploads it to the NAS.
  • 3-remove-unwanted-files.sh removes unwanted files such as .DS_Store and pushes those modifications to the NAS.
  • equalizer.sh allows you to modify the equalizer values of Alsamixer.
  • temperature.sh displays the current Raspberry Pi temperature.
  • video-infos.sh extract infos from the videos to verify if they're readable as needed.
  • usb-boot a set of script documented here.