Advertisement
sneaky4oe

Setup UBUNTU NGINX 2019.06 (sneakyjoe.ru config)

Nov 30th, 2014 (edited)
3,784
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 9.06 KB | None | 0 0
  1. # This is nginx setup of sneakyjoe.ru
  2. # Based on obs forums and helping squad articles.
  3. # Made for personal use and sharing with the crowd.
  4. # Updated with new tweaks for the best job each time I learn something new.
  5.  
  6. # WARNING! Streaming WILL drop all the fucking time if you stream to server higher than 1920x1080/60
  7.  
  8. # WARNING! This will 100% work only on UBUNTU 16.04 with HWE Kernel enabled on installation.
  9.  
  10.  
  11. LOCALE change file set to "LANG=en_EN.UTF-8"
  12.  
  13. /etc/default/locale
  14.  
  15. ________________________________________________________________________
  16.  
  17. SETUP IP AND DNS:
  18.  
  19. sudo mcedit /etc/network/interfaces
  20.  
  21. # This file describes the network interfaces available on your system
  22. # and how to activate them. For more information, see interfaces(5).
  23.  
  24. source /etc/network/interfaces.d/*
  25.  
  26. # The loopback network interface
  27. auto lo
  28. iface lo inet loopback
  29.  
  30. # The primary network interface
  31. auto enp35s0
  32. iface enp35s0 inet static
  33. address 192.168.0.55
  34. netmask 255.255.255.0
  35. gateway 192.168.0.1
  36.  
  37. dns-nameservers 208.67.222.222 8.8.8.8
  38. _______________________________________________________________________
  39.  
  40. FFMPEG install
  41.  
  42. sudo wget https://johnvansickle.com/ffmpeg/releases/ffmpeg-release-amd64-static.tar.xz
  43. sudo wget http://sneakyjoe.ru/go/ffmpeg-release4.1.3-amd64-static.tar.xz
  44. sudo tar -xJf ffmpeg-release-amd64-static.tar.xz
  45. sudo mkdir /usr/bin/ffmpeg-dir
  46. sudo mv -v ~/ffmpeg-4.1.3-amd64-static/* /usr/bin/ffmpeg-dir
  47. sudo ln -s /usr/bin/ffmpeg-dir/ffmpeg /usr/bin/ffmpeg
  48. ______________________________________________________________________
  49.  
  50. NGINX install:
  51.  
  52. sudo mkdir nginx
  53. cd nginx
  54. sudo apt-get install build-essential libpcre3 libpcre3-dev libssl-dev
  55. sudo wget http://nginx.org/download/nginx-1.13.8.tar.gz
  56. sudo wget https://github.com/sergey-dryabzhinsky/nginx-rtmp-module/archive/dev.zip
  57. sudo tar -zxvf nginx-1.13.8.tar.gz
  58. sudo apt-get install unzip
  59. sudo unzip dev.zip
  60. cd nginx-1.13.8
  61. sudo ./configure --with-http_ssl_module --without-http_gzip_module --add-module=../nginx-rtmp-module-dev
  62. sudo make
  63. sudo make install
  64. sudo /usr/local/nginx/sbin/nginx
  65.  
  66. ______________________________________________________________________
  67.  
  68. CONFIGURE template:
  69.  
  70. sudo mcedit /usr/local/nginx/conf/nginx.conf
  71. sudo /usr/local/nginx/sbin/nginx -s stop
  72. sudo /usr/local/nginx/sbin/nginx
  73.  
  74. ______________________________________________________________________
  75.  
  76. AUTOSTART with diagnostics:
  77.  
  78. sudo mcedit /etc/rc.local
  79.  
  80. exec 2> /tmp/rc.local.log  # send stderr from rc.local to a log file
  81. exec 1>&2                  # send stdout to the same log file
  82. set -x                     # tell sh to display commands before execution
  83.  
  84. sleep 5s
  85.  
  86. # sudo ethtool -s enp35s0 speed 1000 ## This is for gigabit networks to enable higher speeds
  87.  
  88. /usr/local/nginx/sbin/nginx
  89.  
  90. ______________________________________________________________________
  91.  
  92. If cant stream to youtube because of IPv6 error add 3 lines to the end of file:
  93.  
  94. sudo mcedit /etc/sysctl.conf
  95.  
  96. net.ipv6.conf.all.disable_ipv6 = 1
  97. net.ipv6.conf.default.disable_ipv6 = 1
  98. net.ipv6.conf.lo.disable_ipv6 = 1
  99.  
  100. ______________________________________________________________________
  101.  
  102. RESTART template:
  103.  
  104. sudo /usr/local/nginx/sbin/nginx -s stop
  105. sudo /usr/local/nginx/sbin/nginx
  106.  
  107. ______________________________________________________________________
  108.  
  109. VODCAST template:
  110.  
  111. # Streams files from such template adding a text over my webcam position. File formats my custom %Y.%m.%d___%H-%M___1080.flv and OBS no spaces:
  112. # 2018.12.31___23-59___1080.flv     for 1080p files
  113. # 2018-02-06 03-31-46.mkv           for 1440p files
  114. # Requires a read-access for file /home/sneakyjoe/RECS/font/consolas.ttf
  115. filename=$1
  116. extension=${filename:26:3}
  117. echo $extension
  118. if [ "$extension" = "flv" ]; then
  119.         fdate=${filename:0:10}
  120.         ftime=${filename:13:5}
  121.         vodtime="$fdate $ftime"
  122.         echo $vodtime
  123.         sudo ffmpeg -re -i ~/RECS/$1 -b:v 6000k -minrate 5500k -maxrate 6500k -bufsize 7000k -vcodec libx264 -preset faster -s 1920x1080 -sws_flags bicubic -r 60 -x264-params nal-hrd=cbr:force-cfr=1:keyint=120 -vf drawtext="fontfile=/home/sneakyjoe/RECS/font/consolas.ttf:text='Запись от $vodtime':fontcolor=white:fontsize=12:box=1:[email protected]:boxborderw=5:x=(w-text_w)-150:y=(h-text_h)-10" -acodec aac -ab 160k -f flv rtmp://localhost/vodcaster/
  124. else
  125.         fdate1=${filename:0:4}
  126.         fdate2=${filename:5:2}
  127.         fdate3=${filename:8:2}
  128.         ftime=${filename:11:5}
  129.         vodtime="$fdate1.$fdate2.$fdate3 $ftime"
  130.         echo $vodtime
  131.         sudo ffmpeg -re -i ~/RECS/$1 -ss 00:00:03 -b:v 6000k -minrate 5500k -maxrate 6500k -bufsize 7000k -vcodec libx264 -preset faster -s 1920x1080 -sws_flags bicubic -r 60 -x264-params nal-hrd=cbr:force-cfr=1:keyint=120 -vf drawtext="fontfile=/home/sneakyjoe/RECS/font/consolas.ttf:text='Запись от $vodtime':fontcolor=white:fontsize=33:box=1:[email protected]:boxborderw=5:x=(w-text_w)-380:y=(h-text_h)-20" -acodec aac -ab 160k -map 0:v:0 -map 0:a:5 -strict -2 -f flv rtmp://localhost/vodcaster/
  132. fi
  133.  
  134. ______________________________________________________________________
  135.  
  136. Stream to receiver application.
  137. NGINX template:
  138.  
  139. rtmp {
  140.     server {
  141.         listen 1935;
  142.         chunk_size 4000; # max size 16777215
  143.  
  144.                     ## Uncomment in case of frequent disconnections
  145.                     ## PacKoMMEHTuPyu ECJlu O6C 4ACTO OTKJll04AETC9\
  146.                     # ping 1m;
  147.                     # ping_timeout 10s;
  148.                     # drop_idle_publisher 10s;
  149.  
  150.             application receiver
  151.                 {
  152.                     live on;
  153.                     meta copy;
  154.                    
  155.                     # This sends stream to transcoder
  156.                     push rtmp://127.0.0.1/transcoder/;
  157.  
  158.                     # Add source streams here you don't want to transcode
  159.  
  160.                     # Twitch source
  161.                 #     push rtmp://live-fra.twitch.tv/app/************************;
  162.  
  163.                     # Youtube source
  164.                 #     push rtmp://b.rtmp.youtube.com:1935/live2/************************;
  165.                 }
  166.  
  167.  
  168.             application transcoder
  169.                 {
  170.                     live on;
  171.                     meta copy;
  172.  
  173.                 # 1080 all sites
  174.                     exec ffmpeg -i rtmp://127.0.0.1/transcoder/
  175.  
  176.                     -b:v 6000k
  177.                     -minrate 5500k
  178.                     -maxrate 6500k
  179.                     -bufsize 7000k
  180.  
  181.                     -vcodec libx264
  182.                     -preset faster
  183.                     -s 1920x1080
  184.                     -sws_flags bicubic
  185.  
  186.                   #  -vf unsharp=3:3:1.5 # Video sharpening
  187.  
  188.                     -r 60
  189.                     -x264-params nal-hrd=cbr:force-cfr=1:keyint=120
  190.  
  191.                     -acodec aac
  192.                     -ab 160k
  193.                   #  -strict -2
  194.  
  195.                     -f flv rtmp://127.0.0.1/transcoded-1080/
  196.  
  197.                   #  -loglevel verbose
  198.                   #  2>>/home/sneakyjoe/ffmpeg-log.txt
  199.                     ;
  200.  
  201.                 # 560 periscope
  202.                   #  exec ffmpeg -i rtmp://127.0.0.1/transcoder/
  203.  
  204.                   #  -b:v 740k
  205.                   #  -minrate 600k
  206.                   #  -maxrate 800k
  207.                   #  -bufsize 800k
  208.  
  209.                   #  -vcodec libx264
  210.                   #  -preset fast
  211.                   #  -s 960x540
  212.                   #  -sws_flags lanczos
  213.  
  214.                   #  -r 30
  215.                   #  -x264-params nal-hrd=cbr:force-cfr=1:keyint=60
  216.  
  217.                   #  -acodec aac
  218.                   #  -ab 90k
  219.                   #  -strict -2
  220.  
  221.                   #  -f flv rtmp://127.0.0.1/transcoded-560/;
  222.                 }
  223.  
  224.  
  225.             application transcoded-1080
  226.                 {
  227.                     live on;
  228.                     meta copy;
  229.  
  230.                     # Twitch transcoded
  231.                #     push rtmp://live-fra.twitch.tv/app/************************;
  232.  
  233.                     # youtube transcoded
  234.                #     push rtmp://b.rtmp.youtube.com:1935/live2/************************;
  235.  
  236.                     # Restream.io transcoded
  237.                #     push rtmp://eu-east.restream.io/live/************************;
  238.  
  239.                     # dailymotion transcoded
  240.                #     push rtmp://publish.dailymotion.com/publish-dm/************************;
  241.  
  242.                     # Cybergame transcoded
  243.                #     push rtmp://premium.cybergame.tv:1953/************************;
  244.  
  245.                     # GoodGame transcoded
  246.                #     push rtmp://msk.goodgame.ru:1940/live/************************;
  247.  
  248.                     # Mixer (beam.pro) transcoded
  249.                #     push rtmp://ingest-fra.mixer.com:1935/beam/************************;
  250.  
  251.                    ## This block will save your transcoded stream to record_path. Remember to create ~/RECS and do "chmod 777 ~/RECS"
  252.                    # recorder myrec
  253.                    #       {
  254.                    #           record all;
  255.                    #           record_path /home/sneakyjoe/RECS;                    #Change sneakyjoe with your username
  256.                    #           record_suffix _%Y.%m.%d___%H-%M___1080.flv;
  257.                    #       }
  258.  
  259.             }
  260.     }
  261. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement