大多数直播工具和网站对公众免费,但它们往往会要求您创建一个帐户,提供您可能不希望出现在网上的信息。他们可以(can )在广告后面保留一些内容,并包含他们甚至可能不会坚持自己 的令人困惑的服务条款。(Service)
有些人喜欢直播的能力,但不需要将他们的视频提供给大众。相反,他们更愿意更好地控制他们的流和他们制作的内容。开源(Open-source)软件,如Linux,是解决这一障碍的最佳方法。
往前想(Thinking Ahead)
在开始设置自己的个人流媒体服务器之前,您应该问自己几个问题。首先(First),您在寻找什么质量的流?接下来(Next),您希望吸引多少观众?您将在哪里存储所有流媒体内容?谁将有权访问该内容?
系统要求也可以被视为一个问题。但是,对于您在这方面需要什么,并没有明确的规定,所以请帮自己一个忙,尝试一下,看看什么最适合您的目标。
您需要弄清楚哪个协议将处理流的音频和视频部分。实时消息传递协议(Messaging Protocol)( RTMP ) 是一个不错的选择,但还有其他一些协议,例如WebRTC,在您的情况下可能会更好。RTMP具有广泛的支持,因此我们将在本文中重点介绍它。
另一件需要担心的事情是您的“实时”流媒体可能会出现延迟。仅仅因为你上线并不意味着一切都会完美排列。视频(Video)流需要编码、传输、缓冲和显示,因此需要对流的属性进行一些调整。
Linux 服务器设置(Linux Server Setup)
Ubuntu Linux是我个人最喜欢的版本,所以这将是这里的首选版本。对于那些喜欢GUI选项的人,可以使用Ubuntu 桌面(Ubuntu Desktop)。
- (Fire)启动Ubuntu安装(Ubuntu)程序并选择最适合您需要的设置。您可能需要设置一些静态网络设置,因为这将用作服务器。
- (Reboot)如果安装后没有自动重新启动系统,请重新启动系统。一旦Ubuntu系统启动,安装所有可用的更新:
sudo apt update
sudo apt upgrade
我们将为此流服务器使用Nginx Web服务器。(Nginx web server)安装它:
sudo apt install nginx
采购RTMP模块,以便Nginx可以处理您的媒体流:
sudo add-apt-repository universe
sudo apt install libnginx-mod-rtmp
调整 Nginx 的配置,使其能够接受和传递您的媒体流。
sudo nano /etc/nginx/nginx.conf
将以下代码添加到配置文件的底部:
rtmp {
server {
listen 1935;
chunk_size 4096;
application live {
live on;
record off;
}
}
}
保存配置文件,因为我们稍后将使用它来创建工作流服务器。
(Restart Nginx)使用新配置重启 Nginx :
sudo systemctl restart nginx
流媒体软件设置(Streaming Software Setup)
服务器已准备就绪,现在是时候设置您的流媒体软件了。让我们在本次演练中使用Open Broadcaster Software (OBS)。
- 前往该站点并选择适用于Linux的构建。软件启动后,使用与您的硬件最匹配的设置配置OBS 。
- 通过单击 Source 下方的 + 添加流媒体源(Source)。
- 为了测试起见,选择Display Capture,然后输入源名称。
- 单击确定(OK)按钮,OBS将镜像您的桌面。
- 接下来,单击File选项卡并选择Settings。
在 Stream 部分,选择set Stream Type to Custom...并在Server字段中输入以下URL :
rtmp://IPaddress/live
代替IPaddress,输入您的流媒体服务器的 IP 地址。
现在创建您自己的Stream Key并将其输入到Stream key 框中。让它成为你会记住的东西并写下来。为了增加安全性,请选中使用身份验证(Use authentication )框并添加您的首选凭据。
使用Apply(Apply)完成,然后单击 OK(OK)按钮。
现在应该将所有内容配置为流式传输。要开始您的第一个流,请点击“立即流”(Stream Now)按钮。只要一切都正确完成,该按钮将变为“停止流”。(Stop Streaming)您的流的带宽指标将显示在OBS窗口的底部。
成为您的第一位观众(Be Your First Viewer)
支持RTMP(RTMP)的开源媒体播放器有很多,其中最著名的是VLC 媒体播放器(VLC media player)。安装并启动此软件,单击媒体(Media)选项卡,然后从菜单中 选择打开网络流。(Open Network Stream)
方便(Got)您的流密钥(Stream Key)吗?键入您的流的路径,并将您之前设置的流密钥包括到它的末尾。(Stream Key)应该看起来像:
rtmp://IPaddress/live/SecretKey
单击播放(Play),您将获得您自己的流的实时视图。
附加措施(Additional Measures)
现在已经实现了基础,限制对流媒体服务器的访问以及能够录制和保存视频是您可能感兴趣的另外两个因素。
默认情况下,任何人都可以查看您的信息流。这可能与最初创建服务器的目的背道而驰。您需要使用Linux防火墙、.htaccess 文件(.htaccess file)或RTMP 模块中的内置访问控制(built-in access controls in the RTMP module)来设置受限访问。这个选择留给你。
此处提供的Nginx配置只能让您流式传输视频,但不能保存它们。要添加存储选项,在Nginx配置中, (Nginx)RTMP部分下方,您可以设置流录制选项并提供您希望保存和存储内容的位置。
设置(Set)现有路径以允许Nginx对其进行写入。输入以下内容:
应用直播 {(application live {)
直播; ( live on;)
全部记录;( record all;)
record_path /var/www/html/recordings;
record_unique 开启;( record_unique on;)
}
这就是使用Ubuntu Linux OS(Ubuntu Linux OS)设置实时流媒体服务器所需的全部内容。如果您对非实时媒体流服务器更感兴趣,我建议使用Plex代替 OBS。
Create Your Own Live Video Streaming Server With Linux
Most live streaming tools and sites are frеe to thе public but they often tend to require that уou creatе an accоunt, providіng information you may nоt wish to appear online. They can hold some content behind advertisements and incorporate confusing Terms of Service that they may not even stick to themselves.
There are those who enjoy the ability to stream live, but don’t have a need to have their videos be available to the masses. Instead, they’d prefer to have more control over their stream and the content they produce. Open-source software, like Linux, is the best answer to this obstacle.
Thinking Ahead
Before you begin setting up your own personal streaming server, you should ask yourself a few questions. First, what quality of stream are you looking for? Next, how many viewers do you expect to pull in? Where will you store all of your streamed content? Who will have access to that content?
System requirements can also be seen as a concern. However, there are no set rules on exactly what you’ll need in this regard, so do yourself a favor and experiment to see what works best for your goals.
You’ll need to figure out which protocol will handle the audio and video portion of the streaming. Real-Time Messaging Protocol (RTMP) is a great choice but there are others, such as WebRTC, that might fare better in your situation. RTMP has broad support so we’ll focus on that for this article.
Another thing to worry about is likely delays in your “live” streaming. Just because you go live doesn’t mean that everything will line up perfectly. Video streams need to be encoded, transferred, buffered, and displayed, so expect the need for a bit of tweaking in the stream’s attributes.
Linux Server Setup
Ubuntu Linux is my personal favorite, so that will be the version of choice here. For those who prefer a GUI option, Ubuntu Desktop is available.
- Fire up the Ubuntu installer and choose the settings that best fit your needs. You’ll probably want to set some static network settings since this is going to be used as a server.
- Reboot the system after installation if it doesn’t do so automatically. Once the Ubuntu system boots up, install any updates that are available:
sudo apt update
sudo apt upgrade
We’ll be using Nginx web server for this streaming server. Install it:
sudo apt install nginx
Procure the RTMP module so Nginx can handle your media stream:
sudo add-apt-repository universe
sudo apt install libnginx-mod-rtmp
Adjust Nginx’s configuration so that it can accept and deliver your media stream.
sudo nano /etc/nginx/nginx.conf
Add the following code to the bottom of the config file:
rtmp {
server {
listen 1935;
chunk_size 4096;
application live {
live on;
record off;
}
}
}
Save the config file as we’ll be using it later to create a working streaming server.
Restart Nginx with its new configuration:
sudo systemctl restart nginx
Streaming Software Setup
The server is ready, so now it’s time to set up your streaming software. Let’s use Open Broadcaster Software (OBS) in this run-through.
- Head to the site and select the build for Linux. After the software launches, configure OBS with the settings that best match your hardware.
- Add a streaming source by clicking the + just under Source.
- For testing sake, choose Display Capture, and enter a name for the source.
- Click the OK button, and OBS will mirror your desktop.
- Next, click the File tab and choose Settings.
In the Stream section, select set Stream Type to Custom… and enter the following URL into the Server field:
rtmp://IPaddress/live
In place of IPaddress, enter the IP address of your streaming server.
Now create your own Stream Key and enter it into the Stream key box. Make it something you’ll remember and write it down. For added security, check the Use authentication box and add your preferred credentials.
Finish with Apply followed by the OK button.
Everything should now be configured for streaming. To begin your first stream, hit the Stream Now button.The button will change to Stop Streaming so long as everything was done correctly. Your stream’s bandwidth metrics will appear at the bottom of the OBS window.
Be Your First Viewer
There are plenty of open source media players that support RTMP, the most well-known of which is VLC media player. Install and launch this software, click the Media tab, and select Open Network Stream from the menu.
Got your Stream Key handy? Type the path to your stream, and include the Stream Key you set up earlier, to the end of it. Should look like:
rtmp://IPaddress/live/SecretKey
Click Play and you’ll get a live view of your very own stream.
Additional Measures
Now that the basics have been achieved, limiting access to your streaming server and being able to record and save your videos are two other factors you may be interested in.
By default, anyone can view your stream. This may go against the purpose of creating the server in the first place. You’ll want to set up limited access using a Linux firewall, .htaccess file, or the built-in access controls in the RTMP module. This choice is left up to you.
The Nginx configuration provided here will only enable you to stream videos, but not save them. To add a storage option, in the Nginx config, just below the RTMP section, you can set up the stream recording options and provide a location to where you want your content saved and stored.
Set an existing path in order to allow Nginx to write to it. Enter the following:
application live {
live on;
record all;
record_path /var/www/html/recordings;
record_unique on;
}
That’s all you should need when setting up a live streaming server using the Ubuntu Linux OS. If you’re more interested in a non-live media streaming server, I would suggest the use of Plex in place of OBS.