Videos on YouTube look easy. Someone uploads it, you hit Play and watch.
But making this? Whole different story.
Big files = lot of disk space. Yes - that's the easiest piece of all that custom video storage is. It goes into everything - webserver, network, code, disk ...
It's years now, when first video creator client came to me. And that was a whole lot of discoveries from then to even recently.
Even though the client, namely local yoga star Zuzana Klingrova, brought her sizable following from social media, it wasn't that exciting (technically). Subscribers started trickling in. And as techs know, "serial" isn't difficult to handle.
But videos, they are not like any other content...
Internet Connection Speed Mirrage
Like any other content - let admin upload it, give them instructions, all good. Afterall, typical internet connections are 25 mbit/s and more even on bad days. Yeah, sure...
Reality doesn't follow optimistic numbers. Here's how it actually is.
You have 50 000 kbit/s connection. The hubby's watching Netflix. Son's playing Roblox. Daughter's on TikTok. Some home appliances downloading updates, maybe it's not a perfect day and suddenly your videos can take unstable 3 500 kbit/s of that pie.
That's where quickly came limits - 3 500 kbit/s for larger fullHD (1080p) and 1 500 kbit/s default HD (720p) videos.
I want the best for users, so we made the bigger videos default. You wouldn't believe how dumb decision that was...
Web Browsers Requirements
Beside sizes, browsers require specific format. Well, one format works in all of them.
MP4, MPEG-4 with recommended H.264 encoding.
Is it guaranteed? By browsers specs, you would think so, wouldn't you?
This Was New For A Web Dev - videos and drive speeds
At this point, the website was running on a mid-sized VPS. It could fit the videos just fine. Connectivity was just fine.
But disk speeds, never met a challenge for those. And that's where I realized that they are not infinite. In practice on VPS, they are quite low and hardly reliable. 10 videos streaming, the website run, MySQL with it, some normal processing like indexing and all the limits we got? Gone.
Do not trust NVMe speeds on VPS - they are not just for you.
VPS Sucks For Videos
There was a day with an influx of users. This always makes me happy, my clients are growing. But few complaints came. I never dismissed any complaint, there's always a reason. These were saying that videos are buffering (in different words) - they are choppy, hard to watch. That's how I found out.
I was planning a move to a dedicated machine soon. So, I sped it up and did it during the night of this discovery. This particular website went first. That literally solved it completelly in the second of the move.
And now, we keep monitoring disk usage, not just its occupancy. And videos are the sole reason it may actually ever reach near limits again. Still, on the bussiest days, the disk is sitting at 30% of reads.
More Clients, More Videos, More Mess - auto-transcoding and previews
If you have one admin taking care of videos, it's a discussion. More of them? It needs boundaries. And boundaries allow for automation.
Let the admin upload one video and do whatever is needed for the project. We have set sizes, bitrates and formats, let's do it.
But, hmm, few years before even resizing images from original photos took a server to a crawl. Granted, it was VPS and possibly wouldn't be any problem on a Ryzen, but still...
Keeping websites running 100% is the priority.
So, hey, if the websites already transform images, why not videos?
Couple changes. Pictures run synchronously, videos are too large to wait and too unreliable to finish. Or even finish transfer of 10GB+ file.
Alright, similar method, just asynchronous. Send a note about new video with its links and key, have the remote server download it, process it and send a webhook with "processing done" so the website can download it back.
Oh Those Limits ...
One provider, internal network, speed is not an issue.
WTF?! A video transfer actually saturated a VPS' networking....
That needs limiting. The same VPS processes those pictures and other clients' videos too. Can't kill it with a video download.
I could use two separate VPSs. But their processing power is still not utilized, not even close. Yeah, let's limit.
Luckily, or "luckily", these websites still use PHP. Just send smaller chunks, smaller buffers over the wire. If not enough, let's add a millisecond sleep somewhere in the loop.
Oh yeah, dramatic slowdown (good to know to not fuck it up for users). Perfect!
I get that separate processing machine is a very typical thing, but it felt like a brilliant idea. And it literally solved all the problems at once. It's scalable (just scale up the tiny VPS).
Those Users - 320p and vacations
If a user tells you "But YouTube works!", take it with a grain of salt. Works? Probably - they won't tell you with what quality though.
A subscriber goes on a vacation, some shack in woods or mountains, and writes email how it doesn't work, but YouTube and Netflix are ok.
Long story short - I added "super low res" that is around 350 kbit/s of 320p video without audio changes. It actually helped. Those users are happy now.
That was a big lesson. Users really don't care that much about video quality. Audio is really important. YouTube made a research about it, but proving it for your use case, your clients, it hits differently.
In fact - a second lesson. More personal. I wouldn't watch that crappy resolution. But I am not my clients subscriber. Others may be perfectly used to it and that's just OK.
What Do Subscribers Work With - on the front side
YouTube for example, they chunk videos, right? Each video is split into pieces and each piece is coded in different resolution, different bitrate. Then they send you the best one.
I went at it a little differently.
I have full videos in those 3 resolutions. 2 - 3 works for every client we have.
The default is the HD 720p - as said, viewers don't really care, so let's save some on bandwidth, disk read speeds and networking limits.
When the viewer changes resolution, the code changes src and it starts the playback from the beginning, right? That's a bad UX!
So, the code keeps info about last tick (position) and when src changes, it applies the same position to the new video.
And it works surprisingly beautifully!
No reason to invent complicated solutions if those simple work just great.
Users And Devices Are Fun
Yes, it's not perfect. Works for vast majority, for the absolute most, but not for the absolute all.
Occasionally, we get a support ticket about black screens with just audio or choppiness.
Black screen typically means the device can't play the video. And typically - it's a TV. Oh yeah, that was surprising to me. Turns out, people have much older and obscure TVs than phones or tablets or laptops. And some have a hard time playing a video. They may need older formats, specific formats, maybe not a web browser video at all.
I am not perfectly certain. And from business perspective, it's not worth the troubles. If you have 2 of 500 subscribers that can't watch on specific devices, you want to consider returning them the subscription fees instead of investing into buying those devices, testing, probably making more video formats and other updates.
2 of 500 can become very expensive.
Looking Good! The Current Status
It works beautifully. Admins upload one file, it gets automatically resized, transcoded and served. We are keeping three sizes
Those few blocks of texts, they were in span of few years. There wasn't a reason for a sophisticated solution.
The meme was (or still is?) "more microservices than users". Create as you need it. Or when you have an idea that helps now or to what's coming soon.
We keep monitoring disk usage, disk speeds, networking, processing server utilization and all in all, this is a pretty great solution.
What's In The Video Hosting's Future?
So far, I've had clients presenting in a single language. But to not be limited and having translation options, I want to make an experiment.
Split video and audio, change only audio for different languages. It could save so much storage space.
But I suspect it can be really tricky. How much do I trust web browsers to not put video and audio out of sync? That's to be tested. Not much.
I just usually trust external dependencies less with growing risks.
What's The Business Of All That?
Why even start this this thing? YouTube hosting, actual enterprise video hosting. CDNs...
Dependency, price, self-containment. If the client wants to leave current providers for any reason, this is simple, this is easy. If they maybe ever want to sell the business, independence and predictability is far more valuable. If they need a change, it's easy to provide.
I have a history of not screwing with my clients. No absurd price hikes. Hard to say about a lot of other businesses. If I choose a dependency and they mess up, it's on me. It's a business risk.
If You Want The Same...
Take care of all limits. Videos are hungry. When a webpage is loading, it's 50 milliseconds. When a video is loading, it's sustained load for minutes. You may be blocking disk, database connection, networking, ...
Make helpful FAQs.
Smoothness over video quality.
And tip FFmpeg few bucks



Comments 2
If the 720p stream stalls twice, could you switch to 320p at the same timestamp? You already have the seek logic for manual switches.
Technically, this setup can do that. Can see buffering, can see pauses. Not sure which events fire. But yeah, can do the same automatically as manually.
I just don't want to do that, not yet. I am not sure how reliable it is. What if the user pauses? Closes and reopens the browser tab? Or the connection is just briefly hitching.
If the client ever requests, that's entirely possible. It's not there because it has a lot of uncertainty and I believe in user's choice instead of pushing a behavior on them. Can't tell you enough how I hate when YouTube does that...