Data Streams

From Modding Fridays
Jump to navigation Jump to search

Prerequisites

Project examples

Installation

A data stream server consists out of the webserver nginx and the nginx-mod-rtmp module. To eventually stream the data to our server, we use a command line utility for audio and video called ffmpeg

nginx

Start with updating and upgrading Alpine

sudo apk update && sudo apk upgrade -U

Followed by installing nginx

sudo apk add nginx

nginx-mod-rtmp

sudo apk add nginx-mod-rtmp

After installing the nginx-mod-rtmp we need to add a configuration block to the nginx configuration file that tells nginx where the stream will be available. Open the configuration file found at /etc/nginx/nginx.conf and add the following contents to the end of the file.

rtmp {
        server {
                listen 1935;
                chunk_size 4096;
                allow publish 127.0.0.1;
                deny publish all;

                application live {
                        live on;
                        record off;
                }
        }
}

PostmarketOS has a very strict firewall as stated in the PostmarketOS General Tips. If we want to eventually make our stream publicly accessible, we need to disable the firewall. Run the following command to temporary disable the firewall.

sudo rc-service nftables stop

When we reboot the phone, the firewall will be enabled again. So in order to completely disable the firewall you can run the following command

sudo rc-update del nftables

ffmpeg

To stream an audio or video file to our rtmp server, we need to install ffmpeg.

sudo apk add ffmpeg

After installing we are almost ready to start streaming

Usage

Uploading files

If you've followed along with installing PostmarketOS, you've enabled the SSH daemon. This also allows us to upload files to your phone over SFTP. Open your favorite (S)FTP client (ex.: filezilla) and enter the ip address and username of your PostmarketOS installation. An example:

server: 192.168.2.130
port: 22
username: user
password: 147147

After connecting to your phone, you should be able to upload files. As an example, we're uploading a file named video.mp4 to the home folder of the user named user.

Streaming video files

ffmpeg -stream_loop -1 -re -i video.mp4 -c:v copy -f flv rtmp://localhost/live/stream

References

Useful Links