Methods of payment Abuse

How to broadcast your videos on YouTube using VPS

21.06.2023, 18:55

How to make it so that it is the broadcast of video files? So that it goes 24/7, is flexible, as autonomous as possible and at the same time does not depend on the computer in any way. This will be discussed further.

Step 1 - Server Selection

The ideal solution would be to rent a virtual server. You can choose VPS/VDS from the range of offered tariffs on our website. Prices are affordable. The quality is high.

Step 2 - Server Setup

After creating the server, the first step is to connect to it via SSH. You can use the Secure Shell App, which runs in Google Chrome. After that, you need to change the host name, configure time synchronization, update the system, configure iptables and perform a number of other actions. Although these actions are optional, but I was interested in configuring the server and getting satisfaction from the successful completion of tasks.

There are several specific steps that need to be performed:

  • Connect the EPEL repository.
  • Install an FTP server (vsftp).
  • Install ffmpeg.

ffmpeg is a free set of open source libraries that allows you to record, convert and transfer digital audio and video recordings in various formats.

Using ffmpeg, you can extract audio from a video, cut a video fragment without transcoding, convert from one format to another, and perform many other actions. For example, a file can be converted into a stream and redirected to YouTube.

You need to follow some specific steps and use the appropriate tools to configure the server for video streaming and conversion.

Step 3 - Setting up the broadcast

Next, we create a broadcast on YouTube, for this we will need a link and a broadcast key, which we will need to use at the broadcast setup stage. The easiest way to quickly find them is on the YouTube page where the broadcast is being created.

Next, you need to upload the video files that we want to broadcast to the server. If you have a more convenient way to upload files, then it is not necessary to raise the FTP server.

To start the broadcast, you need to run ffmpeg with several attributes. Creating a short command for this purpose was quite a complicated process, but if done correctly, YouTube should successfully detect the stream being transmitted.

As soon as YouTube detects the stream, click the "Start Streaming" button in the control panel, and the broadcast will be launched successfully.

Step 4 - Autonomy

The above script will help you create a round-the-clock broadcast from video files. It is important to run the process in the background using the nohup bash command. Now you can set up your broadcast and let it work regardless of your presence. Do not forget that the key to your broadcast must be registered in the appropriate command.

Command 1... (starting the broadcast of the lecture1.mp4 file)

Command 2... (starting the broadcast of the lecture2.mp4 file)

Command 3... (starting the translation of the lecture3.mp4 file) bash start.sh

Script version:

ffmpeg -re -i lecture1.mp4 -f flv rtmp://a.rtmp.youtube.com/live2/%KEY_TRANSLATION%ffmpeg -re -i lecture2.mp4 -f flv rtmp://a.rtmp.youtube.com/live2/%KEY_TRANSLATION%ffmpeg -re -i lecture3.mp4 -f flv rtmp://a.rtmp.youtube.com/live2/%KEY_TRANSLATION %nohup bash start.sh $

We wish you a successful broadcast!

Step 5 - Add ffmpeg

We will perform additional tuning for a better broadcast

ffmpeg -re -i lecture1.mp4 -vf "drawtext=text='Lecture 1':x=(w-text_w)/2:y=(h-text_h)/2:fontcolor=white:fontsize=30:box=1:boxcolor=black@0.5" -f flv rtmp://a.rtmp.youtube.com/live2/%KEY_TRANSLATION%

In this example, the text "Lecture 1" will be superimposed on the center of the video. The font size is 30 pixels. The text background will be transparent with a black outline.

For each lecture, you will need to change the text in the command. And to automate this process and get rid of manual input, you will need to create a .sh file with a list of all lectures and their names. Like this:

lecture1.mp4 Lecture 1
lecture2.mp4 Lecture 2
lecture3.mp4 Lecture 3

Next, you need to write a script that will read this file and automatically add text to the video.

Here is such a script:

while read line; do
file=$(echo $line | cut -d' ' -f1)
text=$(echo $line | cut -d' ' -f2-)
ffmpeg -re -i $file -vf "drawtext=text='$text':x=(w-text_w)/2:y=(h-text_h)/2:fontcolor=white:fontsize=30:box=1:boxcolor=black@0.5" -f flv rtmp://a.rtmp.youtube.com/live2/%KEY_TRANSLATION%
done < lectures.txt

In this script, we read each line from the file lectures.txt , highlighting the file name and the lecture title. Then we use the ffmpeg command to add text to the video.

Thus, now we have a broadcast with lecture titles, which will make it more convenient for viewers and make it easier for them to find the content they need.