Prairie Rim Tech

Plex Media Server on Ubuntu Linux

I had lunch recently with a friend who, like me, doesn’t pay for TV service.  All of our viewing options are over the air or off the Internet.  During that discussion, he told me about the Plex Media Server that he uses to manage many of the Internet video options in his house, as well as many of the DVD movies that he owns.  It sounded like a pretty slick system, so that night, I installed it myself on my Ubuntu Linux 14.04 home computer.

The Plex system consists of a single media server (Plex Media Server, or PMS) and multiple clients that access that server.  The Plex Home Theater runs on a traditional computer for viewing content there.  Plex Mobile Apps enable viewing from phones & tablets, and are the only part of the Plex ecosystem that cost anything.  Finally, many home entertainment systems like Roku, Chromecast, Fire TV, and smart TV’s have Plex apps built in for accessing content on the big screen.  The computer & mobile options can be downloaded from the Plex web site.
Configuring Plex Media Server
My Ubuntu Linux 14.04 desktop computer is where most of my disk space lives, and that computer stays on 24×7, so it was the logical choice for running the PMS.  Once I downloaded the .deb file, I installed it with:
# dpkg -i plexmediaserver_0.9.9.10.458-008ea34_amd64.deb
To configure the newly installed server, use your web browser to connect to port 32400 on the server.  This port probably isn’t accessible from outside your local network, which is wise, so you’ll have to do this from your LAN.
Create a free account with Plex.
Select which TV channels from Plex’s offerings will be visible through your Plex server.

Select the disk location for locally-housed movies, music, and photos.

My photo collection, at which I pointed PMS, contains well over 100,000 images.  The first time I ran a backup after Plex indexed the photo repository, the backup took forever.  It turns out that PMS indexes all of the metadata for every file that it knows about, and places this index in the directory:
/var/lib/plexmediaserver/Library/Application Support/Plex Media Server/Media
On my server, that Media folder contained 18GB of very tiny files.  It wasn’t a problem for the server (it sat on a nearly empty SSD), but it made the backups take forever.  Because PMS can regenerate all of that info from the existing media files, there’s no reason to back it up anyway.  The two ways around this are to (A) exclude the Media directory from the backup script, or (B) move the Media folder to a different drive that’s already not backed up, then create a symlink to it from its original location.  Since all of my ripped DVD’s are already on an un-backed-up drive, I chose (B).  [Edit: I later decided to back that drive up anyway, but manually excluded the PMS Media.]

After a while of use, I found that the interactive console on my server machine would occasionally lock up on me for minutes at a time.  “top” told me that during these lock-ups, the Plex Media Scan was running with a nice priority of -5.  If I reniced the process to 0, everything would work well again until the next time a scan was initiated.  You can set the CPU priority for Plex to 0 from the outset by editing the file “/etc/init/plexmediaserver.conf” and changing the “nice” line from -5 to 0.  This may not be a good idea for a dedicated Plex server, but if you’re running the Plex server on a multi-purpose desktop box, I highly recommend it.

Configuring Plex Home Theater
Once your server is configured far enough to serve up content, you’ll want to setup a client from which to access the server.  I installed Plex Home Theater (PHT) on our Windows 7 laptop as my initial client, because (A) it’s a free download, unlike the mobile apps, and (B) it has the largest display in our home other than the server.
It’s relatively simple to download the program from Plex and install it.
One troublesome feature is that the Plex client takes over the entire screen and hides the mouse.  The first time each user runs the Plex client, you’ll be presented with a PIN, and asked to log into your account on the Plex.tv web site and authorize that PIN.  That’s difficult to do without a mouse, because you can’t just pop open a web browser on the same machine.  I ended up authorizing the PIN using the web browser on my cell phone.
The PHT seems to work just fine, but I find the user interface to be very confusing.  It appears to have two separate GUI’s merged into one, and the method it uses to switch between them is still unclear to me.  I expect my 7-year-old, who will watch many of our ripped DVD’s via Plex, to be very confused for a while.  I can only hope that the Android mobile app is more intuitive.
Ripping DVD’s for Plex Media Server
While the online TV channels are nice, I’m sure one of our biggest uses will be watching movies that we currently own on DVD.  Once those movies are ripped from the DVD and stored on the PMS, you can watch them from any device in the house without having to dig out the disc.  My kids are all pretty excited about watching their favorite movies on their tablets.
At this writing, I’ve figured out how to rip DVD’s using Linux, but the resulting image quality seems pretty poor.  Here’s what I’m doing so far:
Rip the DVD or Blu-Ray to the hard drive using MakeMKV.  This creates a rather large .MKV file on the drive.  PMS can handle these files directly, but it will have to transcode them on the fly for each device that views the stream.  You’re generally better off transcoding them ahead of time to a smaller, more efficient codec such as MP4 using a program like Handbrake.

To install MakeMKV on Ubuntu, you’ll need to download the two source code tarballs.  It builds very easily, once you’ve installed all the development packages that you’re told to.  Handbrake is already in the default Ubuntu repository.  Here’s the commands to run, from this Plex forum post:

# apt-get install handbrake build-essential pkg-config libc6-dev libssl-dev libexpat1-dev libavcodec-dev libgl1-mesa-dev libqt4-dev
# tar zxvf makemkv-oss-1.8.10.tar.gz
# cd makemkv-oss
# ./configure && make && make install
# ..
# tar zxvf makemkv-bin-1.8.10.tar.gz
# cd makemkv-bin
# make && make install

Alas, the DVD drive on my Linux box can’t even recognize many commercial DVD’s, so I’ve been doing all my ripping on a Windows 7 laptop.  I’ve yet to encounter a DVD that won’t work there, although a few pre-ripped ISO’s have given me some trouble.  On my Win7 computer, it takes about 20-30 minutes to rip a typical movie.  After you rip each track, rename the “titleXX.mkv” files to something a little more sane before you start transcoding them.  This will allow you to then rip another disk while the first one is transcoding, without overwriting the first file.If you want to maintain maximum image quality and don’t care about disk usage, you can use the ripped MKV files directly.  Plex will transcode them on the fly, if your server has enough horsepower.  However, if you care about disk usage, or if you want to copy the files to a mobile device for off-line viewing, you’ll be better off transcoding the MKV’s into MP4’s right now.  Transcoding the files with Handbrake takes about 1.5 to 2 hours on my computer.  Handbrake on Win7 is also somewhat different than on Ubuntu 14.04.  On the Win7 box, I set up a custom user preset with my common settings.  Here’s what I changed from the defaults:

  • Container:  Mp4.  The MP4 container plays nice with our Android mobile devices if we decide to copy the file there directly for off-line viewing.  I haven’t encountered a situation where MP4 causes problems.
  • Filters tab:  Decomb:  Default.  The decomb filter removes the ugly interlacing artefacts that are present on cheaper discs.  There are several settings for the decomb filter, but “default” gives the best results.  The system default setting is actually “off.”
  • Video tab:  Video Codec:  H.264.  The alternative is MP4, but H.264 gives much better image quality, especially in areas filled by a nearly solid color.  H.264 may actually be the system default, but I messed with it a lot, so I don’t remember any more.
  • Video tab:  Constant Quality:  19.  Typical settings for H.264 quality are 18-20, with higher numbers yielding smaller files with lower picture quality.  The difference in file size is significant, but the difference in picture quality is hard to see.  19 seemed like a happy medium.

While they’re not set in the user preset, here are some other changes I make with each video:

  • Make sure the destination filename matches the name of the movie as closely as possible.  This helps Plex correctly guess the movie title, and it helps you find the movie when you’re looking for an mp4 to download.
  • Check the Audio table to ensure that your desired audio track is being used.
  • Check the Subtitles track and click the Add button to add the subtitle track.  This adds very little to the file size, and my kids really enjoy having subtitles available when watching quiet dialogue in a movie with loud noises.
Once the videos have been transcoded, I copy them over to my linux Plex Media Server machine, where they can be viewed on any device in the house.  I’m also able to copy the resulting MP4 files directly to the kids’ tablets so they can watch movies on long road trips without Internet connectivity.
All in all, I’m reasonably happy with Plex, and would definitely recommend it to a friend.  What Internet TV options do you prefer, and why?  I’m always looking for other options.

One thought on “Plex Media Server on Ubuntu Linux

Leave a Reply

Your email address will not be published. Required fields are marked *