流媒體視頻服務:快速搭建一個簡單的流媒體視頻服務(一)

快速搭建一個簡單的流媒體視頻服務

前言

最近自己在研究有關於流媒體播放的技術,網上資料甚少。出於開源精神以及在查閱資料得到各位大佬的幫助,故將自己的心得寫下記錄,便於分享以及日後維護。
在此極力感謝並推薦雷神(雷霄驊)
個人博客:https://blog.csdn.net/leixiaohua1020

系統組成

一個完整的流媒體系統大致需要三個部分組成:編碼器、流服務器和播放器。

編碼器通過對內容來源(如MP3文件或者麥克風輸入)進行編碼,並將編碼過的內容發送到流服務器;流服務器再將它們發佈到Internet,這樣客戶端的播放器只要連接到流服務器就可以進行在線播放了。

而本次搭建過程是基於RTMP協議完成。

RTMP協議簡介

RTMP播放過程
播放一個RTMP協議的流媒體需要經過以下幾個步驟:握手,建立連接,建立流,播放。
RTMP連接都是以握手作爲開始的。

1:建立連接階段用於建立客戶端與服務器之間的“網絡連接”;
2:建立流階段用於建立客戶端與服務器之間的“網絡流”;
3:播放階段用於傳輸視音頻數據。

Red5 概述

Red5 是一個採用 Java 開發開源的 Flash 流媒體服務器。免費開源使軟件更加容易擴展,下載後你可以對源代碼進行修改;更加經濟,比起 FMS 高昂的費用,Red5 能爲一般的應用節約大筆費用;同時服務器端的 Java 面嚮對象語言比起 FMS 服務器端的 ActionScript2 語言更加成熟。鑑於 Red5 的種種優勢,推出不久便被廣大用戶所接受。

Red 5 支持:

  1. 把音頻(MP3)和視頻(FLV, F4V, MP4, 3GP)轉換成播放流;

  2. 錄製客戶端播放流, 把攝像頭,麥克風等傳入的音頻視頻錄製保存到服務器;

  3. 共享對象;

  4. 現場直播流發佈;

  5. 遠程調用;

  6. 協議:RTMP, RTMPT, RTMPS, and RTMPE。

Red5 服務器搭建

JDK自行安裝_本文不做演示

可參考:https://jingyan.baidu.com/article/6dad5075d1dc40a123e36ea3.html

下載Red5:(本人使用版本:1.0.10)
官網:http://red5.org/
GitHub:https://github.com/Red5/red5-server/releases

下載後解壓到自己的固定文件夾,如圖:
在這裏插入圖片描述
可以選擇在conf/red5.properties文件下修改IP和端口號

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

# HTTP
http.host=192.168.1.115	//可在此修改HTTP  IP地址
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.1.115		//可在此修改IP地址
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

# RTMPS
rtmps.host=0.0.0.0
rtmps.port=8443
rtmps.ping_interval=5000
rtmps.max_inactivity=60000
rtmps.max_keep_alive_requests=-1
rtmps.max_threads=8
rtmps.acceptor_thread_count=2
rtmps.processor_cache=20
# RTMPS Key and Trust store parameters
rtmps.keystorepass=password
rtmps.keystorefile=conf/keystore.jks
rtmps.truststorepass=password
rtmps.truststorefile=conf/truststore.jks

# RTMPT
rtmpt.host=0.0.0.0
rtmpt.port=8088
rtmpt.ping_interval=5000
rtmpt.max_inactivity=60000
rtmpt.max_handshake_time=5000
rtmpt.max_keep_alive_requests=-1
rtmpt.max_threads=8
rtmpt.acceptor_thread_count=2
rtmpt.processor_cache=20
rtmpt.encoder_base_tolerance=5000
rtmpt.encoder_drop_live_future=true
# better setting for streaming media
rtmpt.target_reponse_size=32768
# best setting for small messages or shared objects
#rtmpt.target_reponse_size=8192
# max incoming messages to process at a time. the most that FP appears to send is 166
rtmpt.max_in_msg_process=166
# max time in millis that we will wait when offering data to the in or out queue
rtmpt.max_queue_offer_time=125
# max offer attempts
rtmpt.max_queue_offer_attempts=4

# Debug proxy (needs to be activated in red5-core.xml)
proxy.source_host=127.0.0.1
proxy.source_port=1936
proxy.destination_host=127.0.0.1
proxy.destination_port=1935

# JMX
jmx.rmi.host=localhost
jmx.rmi.port=9999
jmx.rmi.sport=9998
jmx.rmi.port.remoteobjects=
jmx.keystorepass=password
jmx.mina.monitor.enable=false
jmx.mina.poll.interval=1000
# Whether to always create the registry in-process, not attempting to 
# locate an existing registry at the specified port. Set to "true" in order
# to avoid the overhead of locating an existing registry when you always intend
# to create a new registry in any case.
jmx.registry.create=true
# Whether or not the MBeanServerFactoryBean should attempt to locate a running 
# MBeanServer before creating one
jmx.reuse.existing.server=true
# Whether to register the MBeanServer with the MBeanServerFactory, making it 
# available through MBeanServerFactory.findMBeanServer()
jmx.register.factory=true
# Whether any threads started for the JMXConnectorServer should be started as daemon threads
jmx.daemon=true
# Whether the JMXConnectorServer should be started in a separate thread
jmx.threaded=true

# Server properties
# max events to send in a single update
so.max.events.per.update=64
so.scheduler.pool_size=4
keyframe.cache.entry.max=500
war.deploy.server.check.interval=600000
fileconsumer.delayed.write=true
fileconsumer.queue.size=120
fileconsumer.wait.for.keyframe=true
subscriberstream.buffer.check.interval=5000
subscriberstream.underrun.trigger=100
subscriberstream.max.pending.frames=10
subscriberstream.max.sequential.frames=10
broadcaststream.auto.record=false

啓動red5.bat
在這裏插入圖片描述

出現上圖後在瀏覽器輸入:http://IP:port/
如:http://192.168.1.115:5080/
在這裏插入圖片描述
即代表啓動成功!

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章