Warning: preg_match(): Unknown modifier '-' in /home/akl1986/public_html/support/wp-content/plugins/redux-framework/redux-core/inc/extensions/metaboxes/class-redux-extension-metaboxes.php on line 783

Warning: preg_match(): Unknown modifier '-' in /home/akl1986/public_html/support/wp-content/plugins/redux-framework/redux-core/inc/extensions/metaboxes/class-redux-extension-metaboxes.php on line 783

Warning: preg_match(): Unknown modifier '-' in /home/akl1986/public_html/support/wp-content/plugins/redux-framework/redux-core/inc/extensions/metaboxes/class-redux-extension-metaboxes.php on line 783

Warning: preg_match(): Unknown modifier '-' in /home/akl1986/public_html/support/wp-content/plugins/redux-framework/redux-core/inc/extensions/metaboxes/class-redux-extension-metaboxes.php on line 783

Warning: preg_match(): Unknown modifier '-' in /home/akl1986/public_html/support/wp-content/plugins/redux-framework/redux-core/inc/extensions/metaboxes/class-redux-extension-metaboxes.php on line 783

Warning: preg_match(): Unknown modifier '-' in /home/akl1986/public_html/support/wp-content/plugins/redux-framework/redux-core/inc/extensions/metaboxes/class-redux-extension-metaboxes.php on line 783

Warning: preg_match(): Unknown modifier '-' in /home/akl1986/public_html/support/wp-content/plugins/redux-framework/redux-core/inc/extensions/metaboxes/class-redux-extension-metaboxes.php on line 783

Warning: preg_match(): Unknown modifier '-' in /home/akl1986/public_html/support/wp-content/plugins/redux-framework/redux-core/inc/extensions/metaboxes/class-redux-extension-metaboxes.php on line 783

Warning: Cannot modify header information - headers already sent by (output started at /home/akl1986/public_html/support/wp-content/plugins/redux-framework/redux-core/inc/extensions/metaboxes/class-redux-extension-metaboxes.php:783) in /home/akl1986/public_html/support/wp-includes/rest-api/class-wp-rest-server.php on line 1794

Warning: Cannot modify header information - headers already sent by (output started at /home/akl1986/public_html/support/wp-content/plugins/redux-framework/redux-core/inc/extensions/metaboxes/class-redux-extension-metaboxes.php:783) in /home/akl1986/public_html/support/wp-includes/rest-api/class-wp-rest-server.php on line 1794

Warning: Cannot modify header information - headers already sent by (output started at /home/akl1986/public_html/support/wp-content/plugins/redux-framework/redux-core/inc/extensions/metaboxes/class-redux-extension-metaboxes.php:783) in /home/akl1986/public_html/support/wp-includes/rest-api/class-wp-rest-server.php on line 1794

Warning: Cannot modify header information - headers already sent by (output started at /home/akl1986/public_html/support/wp-content/plugins/redux-framework/redux-core/inc/extensions/metaboxes/class-redux-extension-metaboxes.php:783) in /home/akl1986/public_html/support/wp-includes/rest-api/class-wp-rest-server.php on line 1794

Warning: Cannot modify header information - headers already sent by (output started at /home/akl1986/public_html/support/wp-content/plugins/redux-framework/redux-core/inc/extensions/metaboxes/class-redux-extension-metaboxes.php:783) in /home/akl1986/public_html/support/wp-includes/rest-api/class-wp-rest-server.php on line 1794

Warning: Cannot modify header information - headers already sent by (output started at /home/akl1986/public_html/support/wp-content/plugins/redux-framework/redux-core/inc/extensions/metaboxes/class-redux-extension-metaboxes.php:783) in /home/akl1986/public_html/support/wp-includes/rest-api/class-wp-rest-server.php on line 1794

Warning: Cannot modify header information - headers already sent by (output started at /home/akl1986/public_html/support/wp-content/plugins/redux-framework/redux-core/inc/extensions/metaboxes/class-redux-extension-metaboxes.php:783) in /home/akl1986/public_html/support/wp-includes/rest-api/class-wp-rest-server.php on line 1794

Warning: Cannot modify header information - headers already sent by (output started at /home/akl1986/public_html/support/wp-content/plugins/redux-framework/redux-core/inc/extensions/metaboxes/class-redux-extension-metaboxes.php:783) in /home/akl1986/public_html/support/wp-includes/rest-api/class-wp-rest-server.php on line 1794
{"id":2148,"date":"2019-11-26T06:25:40","date_gmt":"2019-11-26T06:25:40","guid":{"rendered":"https:\/\/support.aklwebhost.com\/?post_type=manual_kb&p=2148"},"modified":"2019-12-06T23:45:37","modified_gmt":"2019-12-06T23:45:37","slug":"setup-nginx-rtmp-on-ubuntu-14-04","status":"publish","type":"manual_kb","link":"https:\/\/support.aklwebhost.com\/knowledgebase\/setup-nginx-rtmp-on-ubuntu-14-04\/","title":{"rendered":"Setup Nginx-RTMP on Ubuntu 14.04"},"content":{"rendered":"

RTMP is great for serving live content. When\u00a0RTMP<\/strong>\u00a0is paired with\u00a0FFmpeg<\/strong>, streams can be converted into various qualities. AKLWEB HOST is great for these applications as they provide fast and dedicated\u00a0CPU performance<\/strong>. AKLWEB HOST global network also ensures that you can deliver high quality live content with minimal delay. Lets get started!<\/p>\n

Installing Nginx and Nginx-RTMP<\/strong><\/h3>\n

Install the tools required to compile Nginx and Nginx-RTMP from source.<\/strong><\/p>\n

sudo apt-get install build-essential libpcre3 libpcre3-dev libssl-dev\r\n<\/code><\/pre>\n

Make a working directory and switch to it.<\/strong><\/p>\n

mkdir ~\/working\r\ncd ~\/working\r\n<\/code><\/pre>\n

Download the Nginx and Nginx-RTMP source.<\/strong><\/p>\n

wget http:\/\/nginx.org\/download\/nginx-1.7.5.tar.gz\r\nwget https:\/\/github.com\/arut\/nginx-rtmp-module\/archive\/master.zip\r\n<\/code><\/pre>\n

Install the Unzip package.<\/strong><\/p>\n

sudo apt-get install unzip\r\n<\/code><\/pre>\n

Extract the Nginx and Nginx-RTMP source.<\/strong><\/p>\n

tar -zxvf nginx-1.7.5.tar.gz\r\nunzip master.zip\r\n<\/code><\/pre>\n

Switch to the Nginx directory.<\/strong><\/p>\n

cd nginx-1.7.5\r\n<\/code><\/pre>\n

Add modules that Nginx will be compiled with. Nginx-RTMP is included.<\/strong><\/p>\n

.\/configure --with-http_ssl_module --add-module=..\/nginx-rtmp-module-master\r\n<\/code><\/pre>\n

Compile and install Nginx with Nginx-RTMP.<\/strong><\/p>\n

make\r\nsudo make install\r\n<\/code><\/pre>\n

Install the Nginx init scripts.<\/strong><\/p>\n

sudo wget https:\/\/raw.github.com\/JasonGiedymin\/nginx-init-ubuntu\/master\/nginx -O \/etc\/init.d\/nginx\r\nsudo chmod +x \/etc\/init.d\/nginx\r\nsudo update-rc.d nginx defaults\r\n<\/code><\/pre>\n

Start and stop Nginx to generate configuration files.<\/strong><\/p>\n

sudo service nginx start\r\nsudo service nginx stop\r\n<\/code><\/pre>\n

Installing FFmpeg<\/h3>\n

Add the FFmpeg PPA.<\/strong><\/p>\n

sudo apt-get install software-properties-common\r\nsudo add-apt-repository ppa:kirillshkrogalev\/ffmpeg-next\r\n<\/code><\/pre>\n

Update the package lists.<\/strong><\/p>\n

sudo apt-get update\r\n<\/code><\/pre>\n

Install FFmpeg.<\/strong><\/p>\n

sudo apt-get install ffmpeg\r\n<\/code><\/pre>\n

Note: The apt-add-repository command may not be installed in some cases. To install it run\u00a0sudo apt-get install software-properties-common<\/code>.<\/p><\/blockquote>\n

Configuring Nginx-RTMP and FFmpeg<\/strong><\/h3>\n

Open the Nginx configuration file.<\/strong><\/p>\n

sudo nano \/usr\/local\/nginx\/conf\/nginx.conf\r\n<\/code><\/pre>\n

Append the following.<\/strong><\/p>\n

rtmp {\r\n    server {\r\n            listen 1935;\r\n            chunk_size 4096;\r\n\r\n            application live {\r\n                    live on;\r\n                    record off;\r\n                    exec ffmpeg -i rtmp:\/\/localhost\/live\/$name -threads 1 -c:v libx264 -profile:v baseline -b:v 350K -s 640x360 -f flv -c:a aac -ac 1 -strict -2 -b:a 56k rtmp:\/\/localhost\/live360p\/$name;\r\n            }\r\n            application live360p {\r\n                    live on;\r\n                    record off;\r\n        }\r\n    }\r\n}\r\n<\/code><\/pre>\n

After you’ve added the above, you can customize settings such a video bitrate, audio bitrate and resolution. These changes will only be applied to the lower quality stream. To add more qualities, copy and paste the exec ffmpeg line and change the settings. You’ll also need to create a new application. You can do this by copying and pasting the live360 example that has been included. Don’t forget to update the exec ffmpeg line with the address of the new application. You can do this by changing the final RTMP address in the exec ffmpeg line.<\/p>\n

Note:<\/strong>\u00a0Changing the value after\u00a0-b:v<\/code>\u00a0will change the video bitrate. This is measured in kilobits per second. Changing the value after\u00a0-b:a<\/code>\u00a0will change the audio bitrate. This is measured in kilobits per second. Changing the value after\u00a0-s<\/code>\u00a0will change the resolution.<\/p><\/blockquote>\n

Save the file by pressing Control and X together. Restart Nginx.<\/strong><\/p>\n

sudo service nginx restart\r\n<\/code><\/pre>\n

Note: For best performance, each stream being converted should have its own CPU core.\u00a0For example two qualities, 360P and 480P are being created from a 720P stream.<\/strong>\u00a0A AKLWEB HOST instance with at least\u00a0two CPU<\/strong>\u00a0cores should be used.<\/p><\/blockquote>\n

Security Note<\/strong><\/h3>\n

If you’re using a firewall, you’ll need to make sure\u00a0TCP 1935<\/strong>\u00a0is allowed.<\/p>\n

The\u00a0current configuartion<\/strong>\u00a0allows anyone to stream to your server. We can fix this by only allowing certain IP addresses the publish permission.\u00a0Open the Nginx configuration.<\/strong><\/p>\n

sudo nano \/usr\/local\/nginx\/conf\/nginx.conf\r\n<\/code><\/pre>\n

Look for the following lines.<\/strong><\/p>\n

                live on;\r\n                record off;\r\n<\/code><\/pre>\n

Add the following to each set of the above lines.<\/strong>\u00a0Change 0.0.0.0 to your\u00a0IP address<\/strong>.<\/p>\n

                allow publish 127.0.0.1;\r\n                allow publish 0.0.0.0;\r\n                deny publish all;\r\n<\/code><\/pre>\n

The configuration should now look something like this.<\/strong><\/p>\n

rtmp {\r\n    server {\r\n            listen 1935;\r\n            chunk_size 4096;\r\n\r\n            application live {\r\n                    live on;\r\n                    record off;\r\n                    allow publish 127.0.0.1;\r\n                    allow publish 0.0.0.0;\r\n                    deny publish all;\r\n                    exec ffmpeg -i rtmp:\/\/localhost\/live\/$name -threads 1 -c:v libx264 -profile:v baseline -b:v 350K -s 640x360 -f flv -c:a aac -ac 1 -strict -2 -b:a 56k rtmp:\/\/localhost\/live360p\/$name;\r\n            }\r\n            application live360p {\r\n                    live on;\r\n                    record off;\r\n                    allow publish 127.0.0.1;\r\n                    allow publish 0.0.0.0;\r\n                    deny publish all;\r\n        }\r\n    }\r\n}\r\n<\/code><\/pre>\n

Save the file by pressing Control and X together. Restart Nginx.<\/p>\n

sudo service nginx restart\r\n<\/code><\/pre>\n

Configuring Software to Work with Nginx-RTMP<\/strong><\/h3>\n

Streaming applications typically have two fields for connection information. The first field is usually for the server information and the second field is usually for the stream name or key. The information that you should place into each field is listed. The stream name or key can be set to anything.<\/p>\n

Field 1: rtmp:\/\/your.akl-web-host.ip\/live\/\r\nField 2: stream-key-you-set\r\n<\/code><\/pre>\n

To view streams open the following links in a player supporting RTMP.<\/strong><\/p>\n

rtmp:\/\/your.akl-web-host.ip\/live\/stream-key-you-set\r\nrtmp:\/\/your.akl-web-host.ip\/live360p\/stream-key-you-set\r\n<\/code><\/pre>\n

Setting up a player<\/strong>\u00a0to display live video on a website is beyond the scope of this guide. Searching for the term\u00a0‘RTMP web player’<\/strong>\u00a0might assist you.<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"open","ping_status":"closed","template":"","format":"standard","manualknowledgebasecat":[107,109,242,247],"manual_kb_tag":[134],"_links":{"self":[{"href":"https:\/\/support.aklwebhost.com\/wp-json\/wp\/v2\/manual_kb\/2148"}],"collection":[{"href":"https:\/\/support.aklwebhost.com\/wp-json\/wp\/v2\/manual_kb"}],"about":[{"href":"https:\/\/support.aklwebhost.com\/wp-json\/wp\/v2\/types\/manual_kb"}],"author":[{"embeddable":true,"href":"https:\/\/support.aklwebhost.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/support.aklwebhost.com\/wp-json\/wp\/v2\/comments?post=2148"}],"version-history":[{"count":1,"href":"https:\/\/support.aklwebhost.com\/wp-json\/wp\/v2\/manual_kb\/2148\/revisions"}],"predecessor-version":[{"id":2149,"href":"https:\/\/support.aklwebhost.com\/wp-json\/wp\/v2\/manual_kb\/2148\/revisions\/2149"}],"wp:attachment":[{"href":"https:\/\/support.aklwebhost.com\/wp-json\/wp\/v2\/media?parent=2148"}],"wp:term":[{"taxonomy":"manualknowledgebasecat","embeddable":true,"href":"https:\/\/support.aklwebhost.com\/wp-json\/wp\/v2\/manualknowledgebasecat?post=2148"},{"taxonomy":"manual_kb_tag","embeddable":true,"href":"https:\/\/support.aklwebhost.com\/wp-json\/wp\/v2\/manual_kb_tag?post=2148"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}