Raspberry Pi is kept increasing its capabilities with its developing computing power with passing time. Its small size with less price makes it an awesome tool to use in many digital projects. We feel excited to share information about one such digital project. Yes, we are going to show you how you can set up a free media server on Raspberry Pi in this blog.
There are different ways to do this. And, there are several third-party products are available in the market to help you do this. Some of them are free and some come for a price. But, our intentions are to show you how to set up a free media server on Raspberry Pi in a native way using DLNA protocol. Let’s get started right from the beginning.
Contents
What Is A Media Server? And, How It Is Different From A File Server?
File servers are some centralized place to store the data in the forms of files. For a typical file server, everything it stores is a file, no matter it is a text, picture, video, pdf, or script file. It just provides you to store the data in an organized way. You should need to navigate the data on your own to access it.
On the other hand, a media server is a layer above the file server. It indexes and catalogues the media files like pictures, audio, and video for you to play. On top of that, it allows to play them over the network. You don’t have to bother where the movie files are stored. You can just send your queries and get the results on your screen. As an example, Search all the songs by a singer or an artist. All these additional capabilities make the media server more user friendly, easier to manage, and more attractive to the user.
What is DLNA?
Let’s give you a short description of the DLNA. First of all, DLNA stands for Digital Living Network Alliance. It is a media sharing protocol standards developed by SONY and Intel with a joint association. It is mainly developed to create standards to share the media over the network. Most of the smart devices like smart TV, smartphones, smart set-top boxes, any smart devices which have the capability to share the media content, supports DLNA. moreover, computer media players like windows media player, VLC, Plex, will also support DLNA.
DLNA enabled computers to act as media servers. Two things are required to work DLNA, DLNA server & client. Media share always happens from server to multiple clients. You can’t share the content between servers or clients alone. Your next question might be what are these client & servers? How do they look? DLNA client could be any device that supports DLNA. Example all the so-called smart devices which can play media over the network. Don’t be scared that you need a big size server to set up a DLNA server. It’s a small application, any buddy can download it on their computers and build their own server. Just to tell you, your windows media player can act as a DLNA server. And, most of the NAS devices are shipped with DLNA server applications to stream media stored on them. Let’s see how to set up a free media server on Raspberry Pi using miniDLNA.
What Is Required To Build A Media Server On A Raspberry Pi?
- A running Raspberry Pi with Raspberry PI OS, miniDLNA app installed on it. Please check out our posts “How to set up a Raspberry Pi for the first time?” and “Five easiest ways to connect Raspberry Pi remotely in 2021:” if you are working on the Pi for the first time.
- Your choice of clean formatted and partitioned storage drives connected to Pi to store and stream media. Please check out our post “How to Partition and Format the Hard Drives on Raspberry Pi:” to know more about adding a hard drive to a Raspberry Pi.
- We also recommend you to read this post “The ultimate guide to build a personal cross-platform file server on Raspberry Pi!” prior to starting this mini project. This post gives a background of our directory file structure on which we are going to build miniDLNA.
How To Setup MiniDLNA On The Raspberry PI?
Its lightweight nature allows you to run it on any versions of Raspberry Pi. In this section, we are going to show you how to set up miniDLNA server on Raspberry Pi and stream media files to other smart devices over the network.
We have divided this section into four major subsections which would gives you a better understanding of complete setup process.
- Installation of miniDLNA on the Raspberry Pi.
- Create directories to store database and log files.
- Configuration of miniDLNA to pickup media files.
- Restart the miniDLNA service.
Time needed: 10 minutes.
How to setup miniDLNA on the Raspberry PI?
- Installation of miniDLNA on the Raspberry Pi:
It’s simple to install as other packages. Let’s install from apt repositories.
$ sudo apt-get install minidlna - Create directory ‘minidlna’ to store its database and log files:
We are creating all the directory under /mnt/data-ext4/ for the demonstration purpose.
$ cd /nmt/data-ext4
$ sudo mkdir minidlna - Changing the ownership of the ‘minidlna’ directory to the ‘minidlna’ user and ‘minidlna’ group:
If you see the permissions for minidlna directory, one can write to the directory other than root. It’s never the best idea to grant full permission for all. Instead, we create a new user ‘minidlna’ and a group ‘minidlna’ and change the ownership to the minidlna user and group. This allows the database and logs to be written in the directory.
$ sudo chown minidlna:minidlna minidlna: chown is the command used to change the ownership of the file. The syntax looks like this, chown user:group directory - Ensure the correct permissions on miniDLNA directories:
Let’s take a look at the ownership of minidlna directory after chown command.
- Create a directory to store the music files:
Navigate inside the ‘public’ directory and create a new directory called ‘Music’ inside of it. This time you need not use the sudo command as the ‘public’ directory has full permissions to all users. Upon creating the ‘Music’ directory, see the permissions, this directory is under the user ‘user’ and the group ‘pi’ and others don’t have write permission on it.
$ cd public
$ mkdir Music - Fix the write permissions on the Music directory:
Use the same ‘chown’ command to change the ownership of the Music directory to everyone and give write permission. User ‘noboddy’ and Group ‘nogroup’ eventually makes everyone the owner of the file/directory.
- Create few more directories to organize the media content:
Similarly, create whatever directories you want to organize your media files. We have created few more directories for demonstration.
Create few more directories inside the public directory inside /mnt/ntfs. And, copy some music and movie files into all these directories. - Configure miniDLNA config file:
Now, it’s time to direct miniDLNA to pick up the media files from the place it stored. Use your choice of text editor and edit the config file.
$ sudo nano /etc/minidlna.conf - Configure the media directories:
Scroll down to the line where you see ‘media_dir’ and create a list of additional directories that you have created to store media. After = sign there is a letter, ‘,’ and the path where the files are stored.
A: Audio files
P: Picture files
V: Video files
PV: Picture and Video files - Configure directories to store the database and log files:
Scroll down just below further and set the directories to store the database and log files. Save the changes and close the text editor.
- Restart the minidlna service:
After making all the required changes restart the minidlna service to write all the changes and it to take effect. Check the status, service should be up and running if everything is correct.
$ sudo service minidlna restart - Set max user watches limit temporarily:
Make sure everything is correct by looking into the log file.
$ cat /mnt/data-ext4/minidlna/log/minidlna.log
Just pay attention to a warning log. It says that it can monitor up to 8192 directories and subdirectories for changes. If your collection is larger than this then you can increase the value by editing /proc/sys/fs/inotify/max_user_watches. But, this will not survive a reboot. - Set max user watches limit permanently:
To set the value for forever. Edit the file /etc/sysctl.conf
$ sudo nano /etc/sysctl.conf
Scroll to the bottom and add this line: fs.inotify.max_user_watches = 65536 - Configure minidlna service to start on reboot:
There are many ways to do this. One such simple way is here:
$ sudo update.rc.d minidlna defaults
That’s all. But, bear in your mind, large files would take a large time to index and catalogue media files. Sometimes it may take few hours to complete the catalogue process.
Now, your Pi is ready to stream media files over the network. This is how you can set up a free media server on Raspberry Pi using miniDLNA.
Thank you for reading this article. Please visit the below links to read more such interesting articles. Please leave your comments here below and let us know your feedback. This helps us to bring more such articles.
原创文章,作者:ItWorker,如若转载,请注明出处:https://blog.ytso.com/269941.html