Skip to content

Instantly share code, notes, and snippets.

@theho
Last active November 29, 2017 15:57
Show Gist options
  • Save theho/5dd521b6ccf0fe548e804ba6ae649af0 to your computer and use it in GitHub Desktop.
Save theho/5dd521b6ccf0fe548e804ba6ae649af0 to your computer and use it in GitHub Desktop.
C920 streaming using nginx-rtmp

Setup Nginx


# /usr/local/nginx/conf/nginx.conf
worker_processes  auto;
events {
    worker_connections  1024;
}

# RTMP configuration
rtmp {
    server {
        listen 1935; # Listen on standard RTMP port
        chunk_size 4000;

        application show {
            live on;
            # Turn on HLS
            hls on;
            hls_path /mnt/hls/;
            hls_fragment 3;
            hls_playlist_length 60;
            # disable consuming the stream from nginx as rtmp
            # deny play all;
        }
    }
}

http {
    sendfile off;
    tcp_nopush on;
    aio on;
    directio 512;
    default_type application/octet-stream;

    server {
        listen 8080;

        # rtmp statistics
        location /stat {
            rtmp_stat all;
            rtmp_stat_stylesheet stat.xsl;
        }

        location /stat.xsl {
            # you can move stat.xsl to a different location
            # under linux you could use /var/user/www for example
            root html;
        }

        location / {
            # Disable cache
            add_header 'Cache-Control' 'no-cache';

            # CORS setup
            add_header 'Access-Control-Allow-Origin' '*' always;
            add_header 'Access-Control-Expose-Headers' 'Content-Length';

            # allow CORS preflight requests
            if ($request_method = 'OPTIONS') {
                add_header 'Access-Control-Allow-Origin' '*';
                add_header 'Access-Control-Max-Age' 1728000;
                add_header 'Content-Type' 'text/plain charset=UTF-8';
                add_header 'Content-Length' 0;
                return 204;
            }

            types {
                application/dash+xml mpd;
                application/vnd.apple.mpegurl m3u8;
                video/mp2t ts;
            }

            root /mnt/;
        }
    }
}

ffmpeg streaming using hardware h264

ffmpeg -re -ar 44100 -ac 2 -acodec pcm_s16le -f alsa -ac 2 -i hw:CARD=C920 -f v4l2 -input_format h264 -i /dev/video0 -codec:v copy -acodec aac -ab 128k -g 50 -strict experimental -f flv rtmp://127.0.0.1:1935/show/stream

links

https://docs.peer5.com/guides/setting-up-hls-live-streaming-server-using-nginx/

rtmp://192.168.21.16/show/stream Which will later be available as http://192.168.21.16:8080/hls/stream.m3u8

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment