We used Vimeo for hosting product videos (9000 videos, 3 TB) for placement on our own websites, but due to partial blocking of Cloudflare in Russia, Vimeo has been working intermittently since the middle of last year.

The goal is to host video for products on our own platform, so as not to depend on third-party providers.

What was important:

  • no advertising for users;

  • absence of erroneous blocking by moderators or algorithms;

  • implementation in industry standards for video hosting;

  • preferably geo distribution to speed up video delivery, because many come "from" EU / US.

The existing social platforms VKvideo / Rutube were not suitable due to the presence of advertising, potential moderation, changing rules and the lack of a global CDN. Yandex Cloud Video video hosting was considered, but it also did not have a global CDN, and now there are added risks of data loss.

Basic Requirements

We needed a video player like Vimeo and YouTube that users are used to:

  • Automatic selection of video quality depending on the user’s Internet speed;

  • Manual quality switching;

  • Instant start of the video, no need to wait for it to fully load;

  • Instant transition when scrolling to the desired point;

  • Ability to move the cursor/finger along the timeline during playback and see a preview;

  • Marking by time codes (not necessary, but wanted to).

In terms of management:

  • administration interface with the ability to upload videos;

  • change title and description - for editors;

  • availability of API - for automation.

Finding a solution

When studying the issue, I found out that to play videos on a website, just as it worked for Vimeo, it is not enough to place an MP4 file on the server and insert a standard HTML player.

With each video file you need to perform a number of actions:

  • Convert to multiple resolutions (360 / 480 / 720 / 1080 / 1440 / 2160);

  • Convert to Fragmented MP4 format - the video is cut into small fragments, which the player accesses as it plays, without downloading the entire file;

  • Create HLS playlists - they store information about the timing of fragments used by the player;

  • Generate a Storyboard - an image with frames from the entire video that the user sees when swiping along the timeline, with timing markings.

All these actions on the back were performed by Vimeo. It is impractical to implement all this on your own - the labor costs are too high, and any repeated conversion with our volume will take months.

In addition to the prepared files, you need a modern player that supports all this.

Among the ready-made solutions on the global market, I found the free open-source project PeerTube. It has existed since 2018, and at the time of installation last year the current version was 7, now it’s already 8.​

The product is alive and developing. There is documentation and ready-made examples with the API. It is deployed on its own server (self-hosted).

As a result, to switch to your own video hosting you will need:

  • The main server (in our case VDS) in RU location;

  • Additional nodes (VDS in EU and US).

  • Services on the server responsible for background processing and video transmission - provided by PeerTube;

  • A modern player on the site responsible for playback is provided by PeerTube.

Плеер с изменяемым качеством и размеченными главами
Плеер с изменяемым качеством и размеченными главами
Разметка видео по эпизодам и storyboard.
Разметка видео по эпизодам и storyboard.

Installation

Installation requires a leading domain on the server IP, in my case this is a 3rd level domain - peertube.[my-domain].

On an Ubuntu 24 OS server, PeerTube was installed on a host without docker.

The deployment process is described in detail in the documentation on the PeerTube website and comes down to 3 blocks:

  • Installing dependencies (nodejs, postgres, redis, nginx, ffmpeg);

  • Installation of PeerTube itself;

  • Setting up peertube and nginx configs for the domain and launching.

Testing

First of all, I tried to manually upload several videos and understand the capabilities and settings.

Everything works and looks like classic video hosting, and at the same time on its own server.

After downloading the video, we immediately get the ID, for example: tB1z3tSyx8YcRo2mq4ZcRs. In this case, the video itself will be converted further in the background, as was the case with Vimeo.

Next, I checked the download via the API, everything was as standard and familiar as it was with Vimeo.

Video addresses will be of two types

  • inside the interface - [my-domain]/w/tB1z3tSyx8YcRo2mq4ZcRs

  • when embedded on a website - [my-domain]/videos/embed/tB1z3tSyx8YcRo2mq4ZcRs

Embedded on the site in a standard way via an iframe, or a more advanced version of the js api:

<iframe title="Демо видео 4" width="560" height="315" src="https://[мой-домен]/videos/embed/tB1z3tSyx8YcRo2mq4ZcRs" style="border: 0px;" allow="fullscreen" sandbox="allow-same-origin allow-scripts allow-popups allow-forms"></iframe>

This option completely covered all our needs, and allowed us to organize an alternative to Vimeo under our control out of the box without our own development.

Загрузка видео через интерфейс PeerTube
Загрузка видео через интерфейс PeerTube
Редактирование уже загруженного видео
Редактирование уже загруженного видео

Technical requirements

To operate the platform, the developers claim a minimum of 1 core + 2 GB of memory + 20 megabit channel. And 4 cores + 4 GB of memory + 1 gigabit channel for 1000 simultaneous views.

For the required bandwidth of 60 - 80 megabits, I took 2 cores, 4 GB of memory, HDD and a 100 megabit channel.

I purposefully took cheaper HDDs instead of SSDs, because... it is more profitable in terms of price per terabyte. The theoretical speed of the HDD is 100 megabytes per second, which is enough for a gigabit channel.

It is important to note here that playing finished videos does not consume significant resources. The main difficulty is conversion, especially the initial one when switching to the platform.

Converting 300 gigabytes on 2 cores takes 3 weeks. Accordingly, 3 TB is already 30 weeks.

The built-in conversion option on external servers (runners) helped. I temporarily made 2 servers with 20 cores each and PeerTube sent all downloaded videos to them, and stored the finished ones locally.

Later I deleted the external servers. For regular conversions, two cores are enough for us. Even when they are fully downloaded, users can easily watch the available ready-made videos.

Общий вид главной страницы PeerTube
Общий вид главной страницы PeerTube

Geo distribution

It was important for us to have a complete server with all videos in RU locations under our control, and geo distribution as an additional option.

In this regard, I did not consider any options with geo-distributed S3 storage, and apparently there are no reliable options that support RU+Global.

I note that PeerTube supports storing finished video files on external S3 storage.

Potentially, you can use the self-hosted S3 service Garage, which allows you to organize geo-distributed storage of files on your own servers, but more nodes are required and the scheme becomes more complicated when using GeoDNS.

We wanted to distribute the files to 2-3 additional locations as simply as possible and, depending on the IP, send video from the EU or US via nginx.

Implementation

On the main RU server additionally installed:

  • MaxMind GeoIP2 module for nginx;

  • GeoIP bases themselves;

  • utility from MaxMind for automatic database updates.

GeoIP2 Lite databases are free, but you need to register and get an API key from MaxMind. All these procedures are standard and are described in the MaxMind documentation.

On nodes from the software, only nginx with configs from the main one with changed domains is required:

  • peertube-eu.[my-domain]

  • peertube-us.[my-domain]

Synchronizing video to nodes

From the main RU server via rsync I completely synchronize the PeerTube /var/www/peertube/ folder to EU and US nodes.

I synchronize several times a day. If necessary, you can do this at the time of video loading, but for this you need to write a nodejs plugin for peertube, which catches the video loading event. We didn't need this complication.

Detecting the country by IP via nginx

On the main RU server, I determine the country by the user’s IP through the previously installed GeoIP database:

geoip2 /usr/share/GeoIP/GeoLite2-Country.mmdb {
        auto_reload 24h;

        $geoip_country_code country iso_code;
}

For a specific country I make a prefix for the node:

map $geoip_country_code $peertube_node {
        default "";
        "NL" "-eu";
        "ES" "-eu";
        "DE" "-eu";
        "FR" "-eu";
        "IT" "-eu";
        "FI" "-eu";
        "US" "-us";
}

And in the case of EU or US, I provide videos from additional VPS.

To do this, through sub_filter in the nginx peertube config (in the Application section) I add a prefix to the domain:

##
# Application
## 

sub_filter_types application/javascript application/json text/css;
sub_filter 'peertube.[мой-домен]/static/streaming-playlists/' 'peertube$peertube_node.[мой-домен]/static/streaming-playlists/';  

The sub_filter scheme allows you to replace the entire output of js/json, and does not require changing PeerTube scripts and, accordingly, further updates can be easily installed, everything will work.

As a result

PeerTube and all the logic work on the RU server, and directly heavy video files for visitors from the EU and US are sent in the background from separate nodes directly, bypassing RU.

Additional options

I’ll note some options that I haven’t used myself, but I think they deserve attention.

1. Ability to connect S3 storage.

With its help, you can change the storage logic and do the conversion on a main fast server with a small disk. At the same time, finished videos are stored in cheaper S3 storage. This additionally removes disk space limitations.

2. Automatic creation of AI subtitles.

Out of the box, PeerTube can generate subtitles through a built-in engine based on Whisper, an open-source model from OpenAI that runs locally on the server without any API keys or external requests.

The task is resource-intensive - like conversion, and it can also be performed on external servers (runners with GPU).

3. Built-in video studio.

Allows you to edit videos directly in the interface, add intro/outro, logos, cut fragments.

4. Ability to separate the audio track from video files during conversion.

This reduces the size as there is no need to embed audio in all resolutions.

5. Video description supports markdown markup.

You can place timecodes, links, etc.

#SLM #LocalAI #GPU