天天看點

Red5伺服器搭建,流媒體rtmp推流實作H5線上直播以及遇到的坑

1.先安裝JDK,red5運作需要運作在java環境裡,(java環境配置自行百度)

2.1下載下傳red5連結,選擇适合的版本

https://github.com/Red5/red5-server/releases
Red5伺服器搭建,流媒體rtmp推流實作H5線上直播以及遇到的坑

我(第一次下載下傳的是1.2.3最新版本的)第二次下載下傳的是上圖的版本,建議用一個比較穩定的版本,解壓到你找的到檔案夾裡,然後修改Red5相關參數

2.2修改red5.properties配置檔案..\conf\red5.properties

隻需要配置HTTP 和RMTP節點的host和port即可 預設也行host配置成0.0.0.0 輸入區域網路IP或者127.0.0.1都可以正常通路

# Socket policy
policy.host=0.0.0.0
policy.port=843

# HTTP
http.host=192.168.xxx.xxx
http.port=5080
https.port=5443
http.URIEncoding=UTF-8
http.max_headers_size=8192
http.max_keep_alive_requests=-1
http.max_threads=20
http.acceptor_thread_count=10
http.processor_cache=20

# RTMP
rtmp.host=192.168.xxx.xxx
rtmp.port=1935
rtmp.io_threads=8
rtmp.send_buffer_size=65536
rtmp.receive_buffer_size=65536
rtmp.ping_interval=1000
rtmp.max_inactivity=60000
rtmp.max_handshake_time=5000
rtmp.tcp_nodelay=true
rtmp.tcp_keepalive=false
rtmp.default_server_bandwidth=10000000
rtmp.default_client_bandwidth=10000000
rtmp.client_bandwidth_limit_type=2
rtmp.bandwidth_detection=false
rtmp.encoder_base_tolerance=5000
rtmp.encoder_drop_live_future=false
# traffic optimization hinting. to disable set traffic class set to -1
# low delay + high throughput == 24 (0x18)
rtmp.traffic_class=-1
# requested maximum length of the queue of incoming connections
rtmp.backlog=32
# the interval (seconds) between each throughput calculation
rtmp.thoughput_calc_interval=15
# enable use of the default mina acceptor
rtmp.default_acceptor=true
# socket i/o pool sizes used when default acceptor is disabled
rtmp.initial_pool_size=0
rtmp.max_pool_size=2
rtmp.max_processor_pool_size=8
rtmp.executor_keepalive_time=60000
mina.logfilter.enable=false
# scheduler configs (per application)
rtmp.scheduler.pool_size=8
rtmp.deadlockguard.sheduler.pool_size=8
# message executor configs (per application) - adjust these as needed if you get tasks rejected
rtmp.executor.core_pool_size=4
rtmp.executor.max_pool_size=32
rtmp.executor.queue_capacity=64
# drop audio packets when queue is almost full, to disable this, set to 0
rtmp.executor.queue_size_to_drop_audio_packets=60
# maximum amount of time allotted to process a single rtmp message / packet in milliseconds, set it as 0 to disable timeout
rtmp.max_handling_time=2000
# connection tweaks - dont modify unless you know what you're doing
rtmp.channel.initial.capacity=3
rtmp.channel.concurrency.level=1
rtmp.stream.initial.capacity=1
rtmp.stream.concurrency.level=1
rtmp.pending.calls.initial.capacity=3
rtmp.pending.calls.concurrency.level=1
rtmp.reserved.streams.initial.capacity=1
rtmp.reserved.streams.concurrency.level=1
# maximum packet size allowed in bytes
rtmp.max_packet_size=3145728
           

2.3啟動Red5

輕按兩下red.bat即可啟動Red5伺服器(遇到的坑,就是輕按兩下red.bat時候會出現閃退情況,建議在windows的dos視窗下啟動red5.bat試試,cmd的指令行可以查到報錯内容)我的情況如下錯誤

Error: JNI error occurred, please check the installation and try again

Exception in thread "main" java.lang.unsupportiedclassversionerror: org / red5 / server / bootstrap has been compiled by a newer version of Java runtime (class file version 55.0), which only recognizes class file versions up to 52.0

//下面是翻譯

錯誤:發生JNI錯誤,請檢查安裝并重試

線程“main”java.lang.UnsupportedClassVersionError中的異常:org/red5/server/Bootstrap已由較新版本的java運作時(類檔案版本55.0)編譯,此版本的java運作時僅識别高達52.0的類檔案版本

最新版本的red5,用的Java版本比我之前安裝的版本高,是以我會運作失敗。我重新選擇了合适的1.0.1版本red5進行了安裝,可以運作起來了。

2.4浏覽器通路檢視是否搭建成功

http://localhost:port(localhost、port為配置檔案..\conf\red5.properties中設定的,參考2.2的圖) ,如下圖就說明啟動成功了。

Red5伺服器搭建,流媒體rtmp推流實作H5線上直播以及遇到的坑

2.5設定資訊釋出直播

進入釋出設定界面:http://localhost:port/demos/publisher.html(localhost:port替換成自己的ip和端口)

Red5伺服器搭建,流媒體rtmp推流實作H5線上直播以及遇到的坑

檢視Settings區域。選擇Video後在Device中選擇攝像頭,并點選Start,出現視訊畫面(有可能會提示是否允許。選擇允許即可)

Red5伺服器搭建,流媒體rtmp推流實作H5線上直播以及遇到的坑

我用chrome浏覽器通路會存在的問題,video 選擇時候會出現下圖情況No video

Red5伺服器搭建,流媒體rtmp推流實作H5線上直播以及遇到的坑

我換成IE浏覽器通路就可以從video裡找到可選擇的播放裝置。按照下面的步驟可以進行推流。

Red5伺服器搭建,流媒體rtmp推流實作H5線上直播以及遇到的坑
Red5伺服器搭建,流媒體rtmp推流實作H5線上直播以及遇到的坑

修改一下red5-server/webapps/oflaDemo/index.html的配置

jwplayer('mediaspace').setup({
        'flashplayer': 'player.swf',
        'file': '你的streamid', //你的streamid 很重要哦
        'streamer': 'rtmp://你的ip/oflaDemo',
        'controlbar': 'bottom',
        'width': '720',
        'height': '480'
    });
           

測試可以通路http://localhost:port/oflaDemo/index.html(localhost:port替換成自己的ip和端口)

Red5伺服器搭建,流媒體rtmp推流實作H5線上直播以及遇到的坑

也可以下載下傳VCL播放器播放 rtmp://你的ip/oflaDemo/你的streamid。

以上内容我補充了我遇到的問題,參考連結https://blog.csdn.net/u010651369/article/details/80886676