# Broadcaster nginx rtmp

1. install raspian
2. boot
3. configure default sound card

c
alsamixer

arecord -l

arecord -f cd -D plughw:0,0 | ffmpeg -i - -acodec libmp3lame -ab 128k -ac 1 -f rtp rtp://127.0.0.1:3000

sudo apt install git nginx vim zsh
sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"

https://www.digitalocean.com/community/tutorials/how-to-set-up-a-video-streaming-server-using-nginx-rtmp-on-ubuntu-20-04

sudo apt install libnginx-mod-rtmp
sudo vim /etc/nginx/nginx.conf

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

                application live {
                        live on;
                        record off;
                        hls on;
                        hls_path /var/www/html/portal/hls;
                        hls_fragment 3;
                        hls_playlist_length 60;

                        dash on;
                        dash_path /var/www/html/portal/dash;
                }
        }
}
```

sudo vim /etc/nginx/sites-available/portal.conf

```
server {
    listen 8080;
    server_name  localhost;

    # rtmp stat
    location /stat {
        rtmp_stat all;
        rtmp_stat_stylesheet stat.xsl;
    }
    location /stat.xsl {
        root /var/www/html/portal;
    }

    # rtmp control
    location /control {
        rtmp_control all;
    }
}

server {
    listen 80;

    location / {
        add_header Access-Control-Allow-Origin *;
        root /var/www/html/portal;
    }
}

types {
    application/dash+xml mpd;
}

```

sudo ln -s /etc/nginx/sites-available/portal.conf /etc/nginx/sites-enabled/portal.conf


sudo mkdir /var/www/html/portal
sudo chown -R $USER:$USER /var/www/html/portal

sudo vim /var/www/html/portal/stat.xsl
paste in https://github.com/arut/nginx-rtmp-module/blob/master/stat.xsl


https://github.com/arut/nginx-rtmp-module/blob/master/stat.xsl

sudo systemctl reload nginx

sudo apt install ffmpeg

vim ~/portal.sh
arecord -f cd -D plughw:3,0 | ffmpeg -i - -acodec aac -ab 128k -ac 1 -f flv rtmp://localhost/live/portal

chmod u+x ~/portal.sh

sudo vim /lib/systemd/system/portal.service

```
[Unit]
Description=portal
After=network.target

[Service]
Environment=NODE_ENV=production
Type=simple
User=grace
WorkingDirectory=/home/grace/
ExecStart=/home/grace/portal.sh
Restart=on-failure

[Install]
WantedBy=multi-user.target
```

sudo systemctl daemon-reload && sudo systemctl enable --now portal && sudo systemctl start portal


