Nginx + rtmp + ffmpeg
nginx 로 rtmp + hls 스트리밍 Test
시나리오 작성 문서
Test 시나리오
nginx config
# /usr/local/nginx/conf/nginx.conf
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 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 | worker_processes 1; events { worker_connections 1024; } # HTTP can be used for accessing RTMP stats http { access_log /var/log/nginx/access-streaming.log; error_log /var/log/nginx/error-streaming.log; server { # in case we have another web server on port 80 listen 80; # This URL provides RTMP statistics in XML location /stat { rtmp_stat all; rtmp_stat_stylesheet stat.xsl; } location /stat.xsl { # XML stylesheet to view RTMP stats. # Copy stat.xsl wherever you want # and put the full directory path here root /usr/local/nginx/html/; } #rtmp control location /control { rtmp_control all; } error_page 500 502 503 504 /50x.html; location =/50x.html { root html; } #hls location /hls { types { application/vnd.apple.mpegurl m3u8; video/mp2t ts; } root /tmp; add_header Cache-Control no-cache; } } } rtmp { server { listen 1935; ping 30s; notify_method get; chunk_size 4000; interleave on; exec_static /usr/local/bin/ffmpeg -i rtmp://Your IP/live-test/aaa -vcodec libx264 -vprofile baseline -level 3 -b:v 2000000 -g 10 -s 640x400 -ac 1 -r 15 -f flv rtmp://Your IP/live-test/high -vcodec libx264 -vprofile baseline -level 3 -b:v 800000 -g 10 -s 640x400 -ac 1 -r 15 -f flv rtmp://Your IP/live-test/medium -vcodec libx264 -vprofile baseline -level 3 -b:v 100000 -g 10 -s 640x400 -ac 1 -r 15 -f flv rtmp://Your IP/live-test/low 2>>/var/log/ffmpeg/all.log; application live-test { live on; hls on; hls_path /tmp/hls; hls_sync 100ms; hls_fragment 10s; hls_fragment_slicing aligned; wait_video on; wait_key on; } } } | cs |
smil config
#/usr/loca/nginx/html/live.smil
1 2 3 4 5 6 7 8 9 10 11 12 13 | <smil> <head> <meta base='rtmp://Your IP/live-test/' /> </head> <body> <switch> <video src='high' system-bitrate='2000000' height='2000' /> <video src='medium' system-bitrate='800000' height='800' /> <video src='low' system-bitrate='100000' height='600' /> </switch> </body> </smil> | cs |
Player Config
#/usr/local/ginx/html/index.html
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 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 | <html> <head> <b>Play</b> | <a href="record.html">Record</a> <br/> <script type="text/javascript" src="/jwplayer/jwplayer.js"></script> <script type="text/javascript">jwplayer.key="Your Key";</script> </head> <table> <tr> <td> <div id="container">Loading the player ...</div> <script type="text/javascript"> jwplayer("container").setup({ sources: [ { file: "rtmp://Your IP/live-test/aaa" } ], ga: {}, skin: "roundster", autostart: false, width: 640, height: 480, primary: "flash" }); </script> </td> <td> <div id="container1">Loading the player ...</div> <script type="text/javascript"> jwplayer("container1").setup({ sources: [ { file: "/live.smil" } ], bufferlength: 0.1, ga: {}, skin: "roundster", autostart: false, width: 640, height: 480, primary: "flash" }); </script> </td> </tr> </table> </html> | cs |
ffmpeg bash_profile 수정
#/root/.bash_profile
RTMP Test 결과
hls test 결과