Linux---nginx+ffmpeg build streaming media server

Source: Internet
Author: User
Tags openssl git clone

Original address: 50907828

This allows the simple nginx+ffmpeg to push local MP4 video files, and will continue to update

Environment

System environment: CentOS Release 6.7 (Final)

Demand

Using Nginx and ffmpeg to build a streaming media server

Step Installation FFmpeg
    • Installation process can be referred to: CentOS compiler installation ffmpeg:http://blog.csdn.net/loyachen/article/details/50909854

    • After the installation is complete, check that the installation is successful. For example, I use the way to push a stream to Pili, a local MP4 video is pushed to seven kn pili.

      -re -i /tmp/ffmpeg_test.mp4 -vcodec copy -acodec copy -f flv "rtmp://pili-publish.qingkang.echohu.top/qingkang/stream1?key=***"
      • 1
    • Seven Bull Pili Live cloud service: https://pili.qiniu.com/

Installing Nginx
    • Here is the method of compiling and installing, the specific installation method can refer to:
      CENTOS6 Compiling and installing nginx1.8.1:http://blog.csdn.net/loyachen/article/details/50904593

    • Note: Be sure to add the Nginx-rtmp-module module

git clone https://github.com/arut/nginx-rtmp-module.git#编译的时候添加nginx-rtmp-module模块--add-module=path_of_/nginx-rtmp-module
    • 1
    • 2
    • 3
    • 4
    • My Nginx compilation parameters
./configure--prefix=/opt/nginx--user=nginx--Group=nginx--With-http_ssl_module--With-http_gzip_static_module--With-http_stub_status_module--With-pcre=/opt/software/pcre-8.35 -- With-zlib=/opt/software/zlib-< Span class= "Hljs-number" >1.2.8 -- With-openssl=/opt/software/openssl -1.0.1i - -add-module=/opt/software/nginx -1.8.1/modules/nginx-rtmp< Span class= "Hljs-attribute" >-module           
    • 1
Modify nginx config file nginx.conf join rtmp configuration
#切换自动推送 (multi-worker live stream) mode. Default is Offrtmp_auto_pushOnSet the automatic push connection timeout when #当 worker is killed. The default is 100 milliseconds Rtmp_auto_push_reconnect1s;rtmp {server {listen 1935;  #直播流配置 application MyApp {Live on;} application HLS {Live on; HLS on; Hls_path/tmp/hls;} application qiniu {Live on; Push push stream address; } application pull {Live on; Pull stream address; }  #rtmp日志设置 access_log logs/rtmp_access. log;} }  
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21st
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
Add a location configuration in HTTP to support HLS
location /hls {              types {                  application/vnd.apple.mpegurl m3u8;                  video/mp2t ts;              }              root /tmp;              add_header Cache-Control no-cache; } 
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
The complete nginx.conf is as follows
#user nobody;worker_processes2;#error_log Logs/error.log;#error_log Logs/error.log Notice;#error_log Logs/error.log Info;#pid logs/nginx.pid;events {use epoll; worker_connections1024;}#切换自动推送 (multi-worker live stream) mode. Default is Offrtmp_auto_pushOnSet the automatic push connection timeout when #当 worker is killed. The default is 100 milliseconds Rtmp_auto_push_reconnect1s;rtmp {server {Listen1935;#直播流配置Application MyApp {LiveOn }Application HLS {LiveOn HLsOn Hls_path/tmp/hls; }Application Qiniu {LiveOn Push push stream address; }Application Pull {LiveOn Pull stream address; }#rtmp日志设置 Access_log logs/rtmp_access.Log; }} HTTP {include mime.types; default_typeApplication/octet-stream; Log_format Main ' $remote _addr-$remote _user [$time _local]"$request" $status $body _bytes_sent"$http _referer""$http _user_agent""$http _x_forwarded_for"; Access_log logs/access.Log main; SendfileOn#tcp_nopush on;#keepalive_timeout 0; Keepalive_timeout65; GzipOn server {Listen80; server_name localhost; CharSet utf-8;  #access_log logs/host.access.log main; location/{root/opt/www/html; index index.html index.htm; }  #rtmp状态页面 location/stat {rtmp_stat all; Rtmp_stat_stylesheet stat.xsl;} location/stat.xs l {root/opt/software/nginx-rtmp-module/;} Location/hls {types {application/ Vnd.apple.mpegurl m3u8; VIDEO/MP2T ts; } root/tmp; Add_header Cache-control No-cache; }  #error_page 404/404.html; # redirect Server error pages to the static page/50x.html # error_ Page 500 502 503 504/50x.html; location =/50x.html { root HTML; }}include vhosts/*.conf;             
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21st
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
  • 83
  • 84
  • 85
  • 86
  • 87
  • 88
  • 89
  • 90
  • 91
  • 92
  • 93
  • 94
  • 95
  • 96
  • 97
  • 98
  • 99
  • 100
  • 101
  • 102
  • 103
  • 104
  • 105
  • 106
  • 107
  • 108
  • 109
  • 110
  • 111
  • 112
  • 113
  • 114
  • 115
  • 116
    • This is the simplest, most basic configuration, rtmp Monitor 1935 port, if it is HLS, use HLS on to open HLS, and set up a temporary file directory for HLS Hls_path/tmp/hls; Other more advanced configurations can be found in Nginx-rtmp-module's readme, which provides a more detailed introduction to other configurations, and it also offers an example of how to play through Jwplayer on a Web page .
Re-start Nginx
-tnginx -s reload
    • 1
    • 2
    • View Nginx already listening on port 1935
Use FFmpeg to push the flow to Nginx
    • Pushes a local MP4 onto the MyApp configured above:

       FFmpeg -re -i/tmp/ffmpeg_test .mp4 -vcodec copy -acodec Copy -f flv  "Rtmp://127.0.0.1:1935/myapp/test1"         
      • 1
       stream play address (10.0 .0.6 is my local IP): Rtmp:// 10.0.0.6:1935/myapp/test1      
      • 1
    • Push a local MP4 to HLS.

      -re -i /tmp/ffmpeg_test.mp4 -vcodec copy -acodec copy -f flv "rtmp://127.0.0.1:1935/hls/test2"
      • 1
      流播放地址为: http://10.0.0.6/hls/test2.m3u8
      • 1
    • Streaming Media Player Address: http://www.cutv.com/demo/live_test.swf

    • VLC Play HLS stream:

Linux---nginx+ffmpeg build streaming media server

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.