Building a home media streaming server. Part 2: The streaming server

Now that I got my TV hook up to the laptop and the PC working as the media server serving those FullHD x264 film over the air. I can simply install  on it and got top notch home media experience,  just look at this beautiful picture, it sure speak more than thousands word:

However, the problem with those massive HEVC(x265)10bit high bitrate film remain. My laptop simply can’t open those files. I will have to transcode those file and stream it to the laptop. In short, my work station will have to be Youtube, or something like this:

The survey

I tried to build a streaming server but to no avail. First is making a trip to the guide:

That link provide quite a few streaming software available on  arch that can stream over DLNA/UPnP protocol. Now as far as I’m concerned, DLNA is meant to stream to media player device that doesn’t have full capacitiy of a laptop computer and thus the server has to transcode the file to a more easier to read format and that’s exactly my use case. Looking on the list of streamer sever software, some catch the eye:

  1. ReadyMedia, formerly known as minidlna, this is a simple and no fussy solution, just like it’s name suggest. You edit the config file, start the server and the media appear on your client, just that.
  2. Gerbera, formerly known as MediaTomb. I did try this server to a horrible experience. It was so buggy and the config file was so so complex that I find no way to make it work and abandon the streaming stuff all together. But with it’s code fork  and make into gerbera, maybe thing will be a bit better
  3. Emby. This software is new and it has a beautiful website for an opensource app. I don’t like the fact that it was coded in C# though but if it work good I can make a pass for that.
  4. Plex. This is a closed-source solution so I was deterred to try it last time. It requires you to registered a free account to get token to access your own media collection. It has an option to make stream your data over the internet, but, for a closed-source solution that sound more scary than cool. But if you don’t concerned about closed-source, Plex has a really good reputation of working find and looking beautiful.

So, how can a tech savvier choose his favourite streaming server among those? He tried them all on 🙂


This software is a resurrection of MiniDLNA, and as its name suggests, this software is lightweight and simple to use. Archwiki already got a pretty decent article on this piece: However, since I also need transcoding feature, I have to install patched version from bitbucket. Arch’s AUR ease up the installation a bit but the old source code won’t compile with the shinny and new ImageMagick version 7.

A little hack is required, and I left a comment in arch’s aur page (linked above). After the minidlna server is up and running, any media player that support dlna protocol can see and open file from my homePC. Kodi con do it but I setting kodi is story for part 3 of this series, one can test if dlna server is up by using the quick and easy vlc :

Just open VLC, then go to View -> Playlist (Ctrl + L) and select Universial Plug 'n' Play under Local Network section.

Your sever will be listed on the right side and you can browse it by  folders of just get a list of every media file that the server understand.

# list of video containers that needs to be transcoded
# possible values can be obtained by running "ffmpeg -formats"
# The format in which the settings should be written is the same
# as the format used for the "transcode_audio_codecs".
# list of video codecs that needs to be transcoded
# possible values can be obtained by running "ffmpeg -codecs"
# The format in which the settings should be written is the same
# as the format used for the "transcode_audio_codecs".
# full path to the transcoder that is used for video transcoding
# for details, see comments on transcode_audio_transcoder


You can either specify the containers (the extensions) you want to transcode or the codecs that will be transcode, or both. Since my laptop only struggle with x265 (HEVC) file, I simply add hevc at the end of the line transcode_video_codecs.

transcode_video_transcoder specify the wrapper script to call a program at your choosing that will be used to actually perform the transcoding. The example script that come with ReadyMedia is easy enough to grasp:



ffmpeg -ss $STARTPOSITION -t $DURATION -i "$SOURCE" -loglevel quiet -threads auto -async 2 -vcodec mpeg4 -f mpegts pipe:1 -scodec copy 


That script take 3 arguments then call ffmpeg to perform the transcoding. The output will be put into standard pipe and then stream to the client.

However, I soon run into a big problem: I CANNOT SEEK

Yeah, no matter how much I tweak ffmpeg argument and ReadyMedia setting, seeking doesn’t seem to work. The seek button on client won’t work, some client even won’t report movie run time. Now that is impossible to use, I can bare with no subtitle or some film, but the most important of watching film at home is that you can forward and backward to the scene you love the most, with no seeking, the experience is nothing more than and old TV.

I did try  but even though it works much better and bug free then the old MediaTomb, I couldn’t find any improvement on transcoding and seeking. In fact, the old transcoding guide for MediaTomb flat out says that seeking is IMPOSSIBLE.


(sidenote: old like to mediatomb website seem dead but the old guide is available in google search’s cache). The only improvement over ReadyMedia that Gerbera can bring to the table is a web interface to do the configuration. That’s it. No improvement in transcoding than I can found. So my search for the solution continue into the realm of proprietary software.

Plex and Embry

The thing I found out when tried on  is that their reputations are well deserved. Installation is easy, configuration is easy and everything just work. After install the server package onto my HomePC, I can access the MY Plex homepage from the local network via the default port 32400. And Man, it was beautiful. Just hover your mouse on the LIBRARY section then click the Plus (+) icon, one will be greeted with the dialog to add a new library.

First, we choose Library type, then browse to  a folder on the disk where the media file is stored. Now just like Kodi, if you choose either Films or TV Programmes, Plex will automatically pull all metadata for those movie and TV shows from imdb, and it will show ONLY the file it recognize as Films or TV Programmes respectively. It’s mean some clip that one really mean to hide won’t show up on the plex library, hooray!

About the transcoding, well, I must say it’s not quite as easy as the rest. Plex support transcoding out of the box but the option to transcoding 4K resolution only “automatically” appear if I really watching the video on a 4K window

Therefore, I cannot test it out on my laptop alone without plugging it into the TV, and that’s inconvenience. And even though the transcoding work, I can enjoy the movie without those massive frame dropping, it put a huge strain on both client and server. Even without the need to decoding, putting all the pixel at that massive bitrate on the screen is back breaking work for my laptop


With CPU jumping between 70% to 90% utilizing across all 2 core, 4 threads, all I can do is enjoy the movie because the laptop hardly response to anything else.

On the server side thing is also pushed to the very edge. My homePC is not equipped with streaming oriented hardware and just decode those HEVC codec alone already put 60% CPU usage on it. Having to re-encode those pixel and transport it over the network and the CPU usage jump to 80-90%.

And the strain on network is also enormous. I’m not a professional in setting up high speed network so my WiFi can only push out about 28Mbps, barely enough for some 4K movie, some other will suffer from stuttering play back. That’s a little bit disappointing at first, I didn’t think a home WIFi network with me as the only primary user would be insufficient for 4K playback. But since a HTPC with dedicate wired Ethernet connection was in plan, I guess I have to bare with the stuttering for now.


Emby is the closest thing to Plex. Unlike Plex, it employs a Free/Open source version along side a “Premiere” version. The Free/Open source part provide enough features and usability for me. It automatically recognize files in your chosen folder and pull all metadata from the internet. Emby provide native app for a barrage of Mobile and TV devices but I haven’t the need for any of them yet.

For PC platform emby provide just the web application and it’s seem good enough, though the interface is not as glamorous as Plex’s.

The playback however is not as smooth. Due to the lack of a PC client app, Emby have to transcode almost every single mkv file or mine to suitable codec for web playaback. And the transcoding process is just Monstrosity. The CPU usage on my HomePC quickly jump to 100% and keep staying there, the whole system become lagging and even then I suffer stuttering playback. It seem like my system was just not strong enough for Emby and by the time I have money to upgrade it I won’t need emby anymore so that was the end of my Emby experience.

The conclusion

So, at the moment, whenever I want to enjoy a 4K movie, I fire up plexmediaserver on my HomePC and Plex Client on my laptop then hookup the laptop to TV and voila. It’s not perfect but at least I decent.

The next part of this series will deal with how I equip my laptop to double as a poor-man-HTPC, include both software and hardware modification needed.


Building a home media streaming server. Part 1: The media server

This will be a multi part blogging of my journy to build a Home Theatre PC (HTPC), becasue so many things was learned to put all in a single post.

The context

The TV

After a very long long long time of ear whispering and diner table talking, I finally persuade mom to get rid of the old junk CRT TV to make space for my new 4K TV.  Even though I had long saved up enough for that TV, I simply couldn’t find a place to put it because the house is cramping and Mom was reluctant to part way with the good old  and sentimentally valuable furniture.

So I quickly dash to the electronic store and bring back the Panasonic TH-43EX605V 

The TV look good but the room in the advertisement look even better

It was the cheapest, none Chinese brand, 4K TV with HDR support in the store, nothing fancy but to the one who never use big screen before, it was HUGE!!!

The TV in action

The plan

So the challenge is finding content to be watched on this TV. My cable company provide TV services but they are capped at FullHD 1080p. The majority of my 4K content come from private torrent tracker where  I can leech a bunch of movies or TV-series RIP in 4K x265 format:

some movie in my favorite tracker

Even though my TV promote itself as “smart”-TV, I pretty much don’t care about those features since it has a slow as hell processor and completely helpless against file with x265 codec. My long term goal is to build a HTPC and connect it to the TV  since I has got tons of experience using PC anyway, it would be a less step learning curve than having to deal with the TV’s peky apps. The plan is to upgrade my current PC then scavenge old parts to build the HTPC. But with the meltdown and spectre haunting all CPU giants, it’s best to delay upgrading the PC until new hardware with no vulnerable come out.

And so, I decided to use my laptop to double as the HTPC and my current PC will double as the Home media server (HMS). And this blog post will document what change need to be made for those to computer to serve as their double role.

The server

The easy start

First of all, since I’m pretty much the sole user of this HTPC-HMS setup, there are a lots of use-case that I won’t have to wory about. First of, I don’t have to get all of my movie archive online at all time. There’s no need to setup NAS or huge storage server, I can keep the film I already watched archive and stashed away in backup hard disk, only hot-swap them in the server when I’m really in the mood. So it’s pretty much “just install openssh” and the server is done.

On the server, install openssh and start it

# pacman -S openssh 
# systemctl start sshd

Then on the client (my laptop) just open Nautilus and connect:

In just type the ip address, preceded by sftp:// and then enter your server’s account username and password then you’re all set. In fact I love file sharing on linux so much more than it is on windows. No twiddling with “Network and sharing settings” and stuff. Then same protocol that’s used to control computer can be used for file sharing with traffic encryption and all. After you connect, it’s only the matter of drag and drop the mkv file into your favourite media player on the laptop.

However, I soon ran into trouble when I download a movie that was encode with so high bitrate my laptop can’t open :O

The Problem.

My laptop is the first-gen Dell XPS13 (9343 model) with only a Broadwell CPU (i5-5200U), and only the next gen with Skylake CPU would support decoding HEVC (x265) 10bit profile. 

The 3:10 to Yuma with it’s 14204 kbps bitrate would drive my laptop CPU to 99% usage and the fan was screeching like crazy.

So, Dunkirk with its  24258 kbps is simply too much for my laptop CPU to handle. Frame was dropping left and right and audio was going a full second and a half before video can catch up. Totally unwatchable.

Now my PC doesn’t fair much better, neither the i5-3550 nor the Geforce GTX750 have native x265 decoding capability but at least my PC CPU can open that file with 60% CPU usage.  So now I’m left with a few choice while saving up for new hardware:

  1. Buy a 15 meters HDMI cable to connect the TV to PC.  This would ensure best performance but that’s almost the maximum length on HDMI 1.2 cable and it won’t come cheap. Moreover, zigzagging 15m of hard cable around the house is no fun job! Where’s the “coolness” in this method? It quickly passed up.
  2. Decode the file on my PC and stream the decoded video over wifi to the laptop. Now that solution would stretch my tech exprience to it’s limit and one cannot expect a more cool solution. I got a chance to face-off with my old enemy “the task of setting up media streaming server”.

And it’s time to wrap up part 1. Part 2 will document my expermiment with various streaming solution.



[Vestacp] Increase database username length limit

For so long mysql has a harcoded 16 characters length limit on username. And vestacp enforce this limitation, every database username have to be less than 17 characters long.

The problem is mysql has increase this length limit to 32 charcaters and mariadb even remove this limit completely but vestacp hadn’t lift their limit yet for the sake of compatibility. So, until this issue closed:, if you have mysql 5.7+ and want to make really long username, you have to change vesatacp’s code.

Open file /usr/local/vesta/func/

Find those line

 if [ 17 -le ${#1} ]; then
 check_result $E_INVALID "mysql username can be up to 16 characters long"

Now change the number 17 to 33 and you essentially double the username length limit.


Glass castle film review.

I seldom write film review, even though I pirated and watched lots of film, mostly because I am lazy, but more often than not I only talk about film than I can reflect upon my own life, like “Rain man” for example.

Recently I stumble upon Glass castle (

The rating was mediocre but I love it because I can relate to the protagonist feeling about her alcoholic father. If an alcoholic can manage to get a family, you can be sure that he/she is very charming when given enough liquor to function. Really, an unattractive alcoholic can only end up in a grave or a prison cell alone, no one would come near them. A charming and family alcoholic man on the other hand, is a roller coaster ride of emotion. He can give you hope that never materialize. He can give you joy that immediately follow by sadness. He can make you feel safe, only to terrifies you himself moment later. And he is never never reliable.

The film was based on a memoir of a famous writer, so it’s good source material. And the acting was superb. Man! If it was up to me I would award an Oscar for both leading actor and actress. Even though her screen time was limited, Brie Larson did a good job in the film. She has already kick Jennifer Lawrence out of my heart, and only rival with Emma Watson. I will be sure to follow her films in the future. The lead actor has been twice nominated for Oscar but never won. He did a good job in this film, I hope it can be his time to shine.

And finally I’m always bias toward film that I can relate to my own life but this film was really a good watch.


Using Code Igniter pagination class with bootstrap 4.0-beta2

Code igniter have a helper class to generate pagination for a page. This class is fairly primitve but highly customizable, and since I’m lazy mood I gooogle around finding some ways to customize it to work with bootstrap 4.0-beta2. So at first I came across this snippet: but this snippet do well in mimicking the look but was annoying to use.
The problem is: Codeiginiter pagination class allow you to wrap the link ( <a> tag) between some others custom tags. Bootstrap however require you add class .page-link in those tag directly. The snippet above solve this by wrapping tag around a tag, produce something like this:

This look good but you cannot click on the <span> square, you have to click on the number itself to change page. And this is quite annoying on touch interface. And so I set out to create my own snippet. And the first thing in order  is to get rid of all those <span> wrapping class. Then we can add all those class with a simple javascript line:

<script type="text/javascript">$("nav > ul.pagination a").addClass("page-link");</script>

The full snippet can be found here:

This is definitely not some complex hack. But since the problem is so subtle that it slips pass my notice for months, I thougth it would worth the effort to take note in case I ran into this problem sometimes later.