Cloud server live streaming
Foreword
If you have a free server, you can try these. I bought a server for 58 yuan per year on the third anniversary of a Tencent Cloud product event.
Introduction to KPlayer
KPlayer is an application designed and developed by ByteLang Studio
for pushing media resources in a Linux environment. You only need to simply modify the configuration file to achieve the purpose of using it out of the box. You do not need to know the details of many push streaming adaptations and video codecs to conveniently broadcast media resources on mainstream live broadcast platforms. The intention is to provide a live streaming scenario that is easy to use, rich in extensions, and has excellent performance suitable for long-term uninterrupted streaming.
Compatibility
KPlayer currently only supports the Linux environment and needs to run on a hardware environment that meets the x86_64(amd64)
and aarch64
(arm64) CPU architectures. We have statically linked the relevant dependent libraries to the main In the program, this means that you do not need to install any additional third-party libraries to support the operation of KPlayer.
View conditions
If you want to determine whether the operating conditions are met, you can use the following command to confirm whether your server meets the following expected output
Make sure that the output results of executing the following commands are the same
uname
Make sure that the output result of executing the following command is x86_64
or aarch64
uname -m
Download and install
KPlayer
provides two methods for you to obtain the current version of the installation package to your server.
One-click download is the download and installation script we provide. It will obtain the corresponding download version based on the architecture version of your server and decompress it into the current directory. It’s more suitable for architecture versions where you don’t need to care about the server.
Manual download is more suitable if you need to download the build version of the corresponding architecture and corresponding version.
1. Use one-click download
One-click download will always download the latest version of KPlayer. If you download a historical version, please use the second installation method.
Enter your server via ssh, find the appropriate directory and run the following command to download
curl -fsSL get.kplayer.net | bash
After the execution is completed, the download process and complete file list are output.
2. Manually download the compressed package
For manual download, please confirm that your server CPU architecture version matches the target download address.
Check the download address of the current version here and select the http client program on the server to download locally. If your machine architecture is amd64
, the following is its example command
wget http://download.bytelang.cn/kplayer-v0.5.8-linux_amd64.tar.gz
Wait for the file download to complete, and you will get the compressed package corresponding to the downloaded version. Execute decompression operation
tar zxvf kplayer-v0.5.8-linux_amd64.tar.gz
Complete the download. If you successfully completed the above steps, KPlayer has been installed on your server.
Execute cd kplayer
to enter the kplayer
folder to view the file list ls -lh
and you will see the output of all files
View current version number
To view the current version number of the downloaded KPlayer, run the following command. View major version number
You need to enter the unzipped kplayer directory to view
cd kplayer
./kplayer
I (using centos7) use the second method, the rendering:
Modify configuration file
Open the config.json.example
file to see the default configuration
{<!-- --> "version": "2.0.0", "resource": {<!-- --> "lists": [ "/video/example_1.mp4", "/video/example_2.mp4" ] }, "output": {<!-- --> "lists": [ {<!-- --> "path": "rtmp://127.0.0.1:1935/push" } ] } }
Modify the video resource path. Be sure to use the absolute path. I created the /home/lighthouse/kplayer/video
folder in the root path.
Upload the video file into
Modify push address
The push address is the communication address that will push the picture and sound of the video resource to the server. If it is a live broadcast platform like bilibili, Huya, Douyu… etc., you usually need to go to the personal center and start the live broadcast, and you will get the push address and Push streaming code. After appending the push code to the push address, you can get the push address
The effect of the final configuration file
Recommendations:
cp config.json.example config.json
Modify the configuration file in config.json
Run kplayer
Because the server is connected to via ssh, the push will stop as soon as the connection window is closed. Therefore, the command running in the background of kplayer is used here, and the push stream will not stop even if the window of the ssh connection is closed.
Run in foreground
./kplayer play start
By default, you enter the server through ssh, and the parent process of the current program is ssh-agent. When exiting the terminal, the program will be terminated
You can support background operation through tools such as nohup, screen, and tmux
Background process
./kplayer play start --daemon
Of course, you can also use tools such as nohup, screen, and tmux to support background operations. Enter my live broadcast room (you can click directly) and you can see
Summary
kPlayer, an application for pushing media resources, also supports various plug-ins and interfaces. If you are interested, you can check out the official documentation.
Question
Question 1
Solution:
cp config.json.example config.json
Modify the configuration file in config.json
The program supports identifying configuration files ending with json. Both config.json
and config.yaml
exist. The json format will have a higher priority.
Question 2
Just kill the pid occupying this port
For specific operation inquiries, refer to the blog
Question 3
Official solution
error: I/O error [-5] The inability to communicate normally with the server leads to connection rejection. If it is an online live broadcast room, it is usually because the live broadcast room has not started live broadcast or the push address has expired and the push address needs to be refreshed.
Reference blog:
Start HTTP server error: listen tcp :7890: bind: address already use solution
There may be many minor problems, please include them.
Thank you all for your support, attention, comments, and likes!