将你的树莓派用作流媒体服务器
流媒体 树莓派
![](/data/attachment/album/202303/11/101802ajd68nnzn6788h6i.jpg)



> 
> 用树莓派串流网络摄像头的实时视频，并将视频重新串流到社交网络。
> 
> 
> 


出于各种原因，人们需要流式传输网络摄像头的实时视频。树莓派平台很适合此类应用。对于实时流媒体服务器等连续应用，它只需要很少的电力。可以与 Raspicam 相机模块、USB 摄像头或其他网络视频信号进行通信。该系统是一个 RTMP、HLS 和 SRT 服务器。这篇文章展示了如何将树莓派设置为流媒体服务器以使用 HLS 流媒体。你需要一个视频源才能把它作为流媒体服务器使用。


即使没有树莓派，你也可以完成这里描述的步骤。此外，还有针对 [Windows](https://docs.datarhei.com/restreamer/installing/windows)、[Linux](https://docs.datarhei.com/restreamer/installing/linux) 和 [macOS](https://docs.datarhei.com/restreamer/installing/mac) 的进一步安装说明。


### 设置


该应用程序是 datarhei [Restreamer](https://github.com/datarhei/restreamer)，是 datarhei [Core](https://github.com/datarhei/core) 的图形用户界面。datarhei Core 在底层运行著名的媒体框架 FFmpeg。开始使用 datarhei Restreamer 的最简单方法是安装官方的 Docker 容器。通过 Docker Hub 的程序下载和安装是通过 `docker pull` 命令自动进行的。安装后，Restreamer 立即启动。如果你没有树莓派，可以使用 datarhei [Restreamer GitHub](https://github.com/datarhei/restreamer) 页面上的其他 Docker 容器之一（例如，支持 AMD64 或 GPU Cuda）。


datarhei Restreamer 和 datarhei Core 都是 [Apache 许可证 2.0](https://github.com/datarhei/restreamer/blob/2.x/LICENSE) 下的开源软件。


以下是在支持 GPU 的树莓派 3 及以上机型上的安装命令：



```
docker run -d --restart=always --name restreamer \
   -v /opt/restreamer/config:/core/config -v /opt/restreamer/data:/core/data \
   --privileged \
   -p 8080:8080 -p 8181:8181 \
   -p 1935:1935 -p 1936:1936 \
   -p 6000:6000/udp \
   datarhei/restreamer:rpi-latest

```

无论你使用哪条命令，你只需要 `--privileged` 选项来访问本地设备，如 USB 摄像头。


安装后，将 Raspberry Pi 连接到本地网络。然后在浏览器中进入 <http://device-ip:8181/ui> 打开基于 Web 的 GUI。


你应该看到以下屏幕：


![First login into datarhei Restreamer](/data/attachment/album/202303/11/101901m2xv06297vnc6he5.jpg)


分配好密码，系统就可以进行首次登录了。向导正在开始配置第一个视频源。


提示：上述 Docker 命令将带有登录名和密码的配置数据永久保存在 `/opt/restreamer/config` 文件夹中。


### 实施


该应用程序由三个逻辑部分组成：视频输入、系统仪表板和视频输出。视频输入和输出相互独立运行。


### 视频输入


该向导将帮助你从头开始创建一个视频源。这可以是一个 USB 视频源、树莓派摄像头，或者是一个网络源，如 IP 摄像头或来自网络的 m3u8 文件。HLS、RTMP 和实时 SRT 协议都可以使用。该向导可以帮助正确配置视频分辨率和声音。在最后一步，你可以分配不同 <ruby> 知识共享 <rt>  Creative Commons </rt></ruby> 许可证。值得看一下视频信号的设置。你会发现几个选项，例如为垂直视频平台转码或旋转视频。


### 仪表板


成功创建视频信号后，你将进入仪表板。


![datarhei Restreamer dashboard](/data/attachment/album/202303/11/101901sjruhhrx33lz0juv.jpg)


它是所有其他设置的中心起点。要看到程序的全部功能，你可以在系统偏好中切换到专家模式。


仪表板包含以下内容：


* 视频信号设置。
* RTMP、SRT、HLS 服务器和快照的活动内容 URL。
* 用于重新流式传输的所有活动发布服务。
* 启动向导来创建额外的视频源。
* 系统菜单。
* 实时视频信号统计。
* 实时系统监控。


### 视频输出


有不同的方法来播放视频信号。


这个 [发布网站](https://demo.datarhei.com/) 是 Restreamer 最简单、即时可用且内部托管的登录页面。播放页面也可以传输到 Chromecast 和 AirPlay。调整背景图片和在播放器中添加标识等基本设置可以直接在 Restreamer 中进行。那些懂 HTML 的人可以为自己定制页面。高级用户可以注入代码，以使用网站的外部模块，如聊天。视频播放器下的统计模块显示活跃的观众和所有视图。“<ruby> 分享 <rt>  Share </rt></ruby>” 按钮支持直播流的分发。网站的 HTTPS 证书通过 Let's Encrypt 激活，无需太多努力。通过简单的 HTTPS 端口转发到树莓派的 LAN IP，网站就可以公开访问。


![Landingpage from datahrei Restreamer](/data/attachment/album/202303/11/101901c4zva85xz45bx8d6.jpg)


发布服务是重新传输内容的一个好方法。对于流行的网站，如 YouTube、Twitch 或 PeerTube，有许多现成的模块。同样，对于其他流媒体软件、流行的 CDN 也是如此。对视频协议的完全控制允许流式传输到所有支持 RTMP、HLS 和 SRT 的目标地址。一个带有视频播放器的 HTML 片段代码在网页上工作。


![Presets for publication services](/data/attachment/album/202303/11/101902rddbnj5jcfeacdaj.jpg)


### 使用树莓派播放流媒体节省电力


这篇文章展示了如何将树莓派变成一个流媒体服务器。树莓派平台允许你以省电的方式与各种视频信号互动。预先的设置使配置服务器变得很容易，高级用户可以对系统进行一些调整。你可以用它来做回放，在网站上托管实时流式传输，或使用 [OBS](https://opensource.com/article/20/6/obs-websockets-streaming) 集成到系统环境中。使用不同的视频源和传输协议作为项目的基础，提供了极大的灵活性，使这个系统具有高度的可定制性。此外，带有 FFmpeg 的 datarhei Core 使软件开发者很容易扩展所有的应用进程。


该程序将树莓派变成一个专门的流媒体服务器。你可以独立地直播到网站或多路直播到不同的视频网络，而无需额外的视频提供商。


可以使用登录名 “admin” 和密码 “demo” 在项目网站上安装之前测试功能齐全的 [演示](https://demo.datarhei.com/ui)。




---


via: <https://opensource.com/article/23/3/raspberry-pi-streaming-server>


作者：[Sven Erbeck](https://opensource.com/users/erbeck) 选题：[lkxed](https://github.com/lkxed/) 译者：[geekpi](https://github.com/geekpi) 校对：[wxy](https://github.com/wxy)


本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译，[Linux中国](https://linux.cn/) 荣誉推出


OK
There are various reasons to stream live video transmissions from webcams. The Raspberry Pi platform is perfect for such applications. It requires little power for continuous applications such as live-streaming servers. Communication with a Raspicam camera module, USB cam, or other network video signals is possible. The system is an RTMP, HLS, and SRT server. This article shows how to set up the Raspberry Pi as a streaming server to use HLS streaming. You need a video source to use it as a streaming server.

Even without a Raspberry Pi, you can do the steps described here. In addition, there are further installation instructions for [Windows](https://docs.datarhei.com/restreamer/installing/windows), [Linux](https://docs.datarhei.com/restreamer/installing/linux), and [macOS](https://docs.datarhei.com/restreamer/installing/mac) available.

## Setup

The application is datarhei [Restreamer](https://github.com/datarhei/restreamer), a graphical user interface for the datarhei [Core](https://github.com/datarhei/core). The datarhei Core runs the well-known media framework FFmpeg under the hood. The easiest way to start with datarhei Restreamer is to install the official Docker container. The download and installation of the program via Docker Hub are automatic with the `pull`

command. Restreamer starts immediately after the installation. If you don't have a Raspberry Pi, use one of the other Docker containers on the datarhei [Restreamer GitHub](https://github.com/datarhei/restreamer) page (e.g., AMD64 or GPU Cuda support).

datarhei Restreamer and datarhei Core are both open source software under the [Apache License 2.0](https://github.com/datarhei/restreamer/blob/2.x/LICENSE).

Here's the command for an installation on a Raspberry Pi 3 and above with GPU support:

```
``````
docker run -d --restart=always --name restreamer \
-v /opt/restreamer/config:/core/config -v /opt/restreamer/data:/core/data \
--privileged \
-p 8080:8080 -p 8181:8181 \
-p 1935:1935 -p 1936:1936 \
-p 6000:6000/udp \
datarhei/restreamer:rpi-latest
```


Regardless of which command you use, you only need the `--privileged`

option to access local devices, like a USB camera.

After installation, connect the Raspberry Pi to the local network. Then open the web-based GUI in a browser by navigating to [http://device-ip:8181/ui](http://device-ip:8181/ui).

You should see the following screen:

![First login into datarhei Restreamer](https://opensource.com/sites/default/files/2023-01/fig2-first-login-datarhei.jpg)

(Sven Erbeck, CC BY-SA 4.0)

Assign the password, and the system is ready for the first login. A wizard is starting to configure the first video source.

Hint: The above Docker command permanently stores the configuration data with the login name and password in the `/opt/restreamer/config`

folder.

## Implementation

The application consists of three logical parts: Video input, system dashboard, and video output. The video input and output run independently of each other.

## Video input

The wizard will help you to create a video source right from the start. This can be a USB video source, the Raspberry Pi camera, or a network source like an IP cam or an m3u8 file from a network. HLS, RTMP, and real-time SRT protocol are ready to use. The wizard helps to configure the video resolution and sound correctly. In the last step, you can assign different licenses from Creative Commons. It is worth taking a look at the video signal settings. You will find several options, like transcoding or rotating the video for vertical video platforms.

## Dashboard

After successfully creating the video signal, you will land in the dashboard.

![datarhei Restreamer dashboard](https://opensource.com/sites/default/files/2023-01/fig1-title-dashboard-datarhei.jpg)

(Sven Erbeck, CC BY-SA 4.0)

It is the central starting point for all other settings. To see the program's full functionality, you can switch to expert mode in system preferences.

The dashboard contains the following:

- Video signal settings.
- Active content URL for RTMP, SRT, HLS server, and snapshot.
- All active Publication Services for restreaming.
- Start the wizard to create additional video sources.
- The system menu.
- Live-Statistics for the video signal.
- Live-System monitoring.

## Video output

There are different ways to play the video signal.

The [publication website](https://demo.datarhei.com/) is the simplest, immediately-ready, and internally hosted landing page by Restreamer. The player page can also transmit to Chromecast and AirPlay. Basic settings like adjusting the background image and adding a logo in the player are possible directly in the Restreamer. Those who know HTML can customize the page for themselves. Advanced users can inject code to use the site with external modules like a chat. A statistics module under the video player shows the active viewers and all views. The **Share** button supports the distribution of the live stream. HTTPS certificates for the website are active with Let's Encrypt without much effort. With a simple port forwarding for HTTPS to the LAN IP of the Raspberry Pi, the website is publicly accessible.

![Landingpage from datahrei Restreamer](https://opensource.com/sites/default/files/2023-01/fig3-int-publication-website-datarhei.jpg)

(Sven Erbeck, CC BY-SA 4.0)

The publication services are a great way to restream content. There are numerous ready-made modules for popular websites like YouTube, Twitch, or PeerTube. Likewise, for other streaming software, to popular CDNs. Complete control over the video protocols allows streaming to all RTMP, HLS, and SRT-capable destination addresses. An HTML snippet code with the video player works on web pages.

![Presets for publication services](https://opensource.com/sites/default/files/2023-01/fig4-preset-publication-services-datarhei.jpg)

(Sven Erbeck, CC BY-SA 4.0)


## Save power while streaming with Raspberry Pi

This article shows how to turn the Raspberry Pi into a streaming server. The Raspberry Pi platform allows you to interact with various video signals in a power-saving way. The pre-settings make it easy to configure the server, and advanced users can make some adjustments to the system. You can use it for restreaming, hosting for live-streaming on a website, or integration into system landscapes with [OBS](https://opensource.com/article/20/6/obs-websockets-streaming). Using different video sources and transport protocols offer great flexibility as a basis for a project and make this system highly customizable. Furthermore, the datarhei Core with FFmpeg makes it easy for software developers to extend all application processes.

The program turns the Raspberry Pi into a dedicated streaming server. Depending on your internet upload, you can live stream to websites or multi-stream to different video networks independently and without an additional video provider.

Test a fully functional [demo](https://demo.datarhei.com/ui) before installation on the project website with the login name **admin** and password **demo**.

## Comments are closed.