这篇文章主要介绍了java Red5服务器实现流媒体视频播放,对视频播放感兴趣的同学,可以参考下


引言

流媒体文件是目前最流行的在线媒体格式之一,它允许用户同时下载和播放,从而大大减少了用户的等待时间。另外,流媒体文件通过网络播放时,文件本身不会存储在本地磁盘中,从而节省了大量的磁盘空开销。正是这些优点使得流媒体文件在网络广播中得到了广泛的应用。

流媒体服务器通过建立发布点来发布流媒体内容和管理用户连接。流媒体服务器可以发布从视频采集卡或摄像机传输过来的直播流,或者预存的流媒体文件,发布直播流和流媒体文件的组合。媒体流可以由一个媒体文件、多个媒体记录组或一个媒体文件目录组成。

Flash Media Server,简称FMS,是Flash家族中的一员,被称为开发Web音视频应用(例如,视频聊天室、视频会议系统、播客系统、音视频消息等)最方便快捷的解决方案。).它也广泛应用于web应用程序开发。当然,FMS的这种优秀功能并不是免费提供给用户的,每点几千块钱的价格让很多开发者望而却步。于是大家开始尝试寻找更合适的解决方案,开源的Red5成为了人们的新宠。

Red5是Java开发的开源Flash流媒体服务器,功能上类似于FMS。它支持:转换音频(MP3)和视频(FLV)到播放流;记录客户端播放流(仅限FLV);是支持的);共享对象;直播流发布;远程呼叫。Red5采用RSTP作为流媒体传输协议,包括在线录制、Flash流媒体播放、在线聊天、视频会议等一些基本功能。国内外基于Red5的流媒体应用也在推广,如在线视频会议Openmeeting、大型Flash网游《功夫之王2》等。


Red5 概述

Red5是Java开发的开源Flash流媒体服务器。免费开源让软件更容易扩展,下载后可以修改源代码;更经济,相对于FMS的高成本,Red5对于一般应用来说可以省下不少钱;同时,服务器端的Java面向对象语言比FMS服务器端的ActionScript2语言更加成熟。鉴于Red5的优点,很快被用户接受。

红色5支持:

把音频(MP3)和视频(FLV, F4V, MP4, 3GP)转换成播放流; 录制客户端播放流, 把摄像头,麦克风等传入的音频视频录制保存到服务器; 共享对象; 现场直播流发布; 远程调用; 协议:RTMP, RTMPT, RTMPS, and RTMPE。


Red5 服务器搭建

JDK自己安装下载Red5

https://github.com/Red5/red5-server/releases

将它解压到一个你能记住的文件夹中,例如:F:Red5


配置Red5相关参数

修改red5.properties配置文件.. conf  red5.properties。

您只需要配置HTTP和RMTP节点的主机和端口,默认情况下可以使用。如果主机配置为0.0.0,输入局域网IP或127.0.0.1,可以正常访问。

# Socket policypolicy.host=0.0.0.0policy.port=843 # HTTPhttp.host=0.0.0.0http.port=8855https.port=5443http.URIEncoding=UTF-8http.max_keep_alive_requests=-1http.max_threads=20http.acceptor_thread_count=10http.processor_cache=20 # RTMPrtmp.host=0.0.0.0rtmp.port=1935rtmp.io_threads=16rtmp.send_buffer_size=65536rtmp.receive_buffer_size=65536rtmp.ping_interval=1000rtmp.max_inactivity=60000rtmp.max_handshake_time=5000rtmp.tcp_nodelay=truertmp.tcp_keepalive=falsertmp.default_server_bandwidth=10000000rtmp.default_client_bandwidth=10000000rtmp.client_bandwidth_limit_type=2rtmp.bandwidth_detection=falsertmp.encoder_base_tolerance=5000rtmp.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 connectionsrtmp.backlog=32# the interval (seconds) between each throughput calculationrtmp.thoughput_calc_interval=15# enable use of the default mina acceptorrtmp.default_acceptor=true# socket i/o pool sizes used when default acceptor is disabledrtmp.initial_pool_size=0rtmp.max_pool_size=2rtmp.max_processor_pool_size=16rtmp.executor_keepalive_time=60000mina.logfilter.enable=false# scheduler configs (per application)rtmp.scheduler.pool_size=16rtmp.deadlockguard.sheduler.pool_size=16# message executor configs (per application) - adjust these as needed if you get tasks rejectedrtmp.executor.core_pool_size=4rtmp.executor.max_pool_size=32rtmp.executor.queue_capacity=64# drop audio packets when queue is almost full, to disable this, set to 0rtmp.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 timeoutrtmp.max_handling_time=2000# connection tweaks - dont modify unless you know what you're doingrtmp.channel.initial.capacity=3rtmp.channel.concurrency.level=1rtmp.stream.initial.capacity=1rtmp.stream.concurrency.level=1rtmp.pending.calls.initial.capacity=3rtmp.pending.calls.concurrency.level=1rtmp.reserved.streams.initial.capacity=1rtmp.reserved.streams.concurrency.level=1 # RTMPSrtmps.host=0.0.0.0rtmps.port=8443rtmps.ping_interval=5000rtmps.max_inactivity=60000rtmps.max_keep_alive_requests=-1rtmps.max_threads=20rtmps.acceptor_thread_count=2rtmps.processor_cache=20# RTMPS Key and Trust store parametersrtmps.keystorepass=passwordrtmps.keystorefile=conf/keystore.jksrtmps.truststorepass=passwordrtmps.truststorefile=conf/truststore.jks # RTMPTrtmpt.host=0.0.0.0rtmpt.port=8088rtmpt.ping_interval=5000rtmpt.max_inactivity=60000rtmpt.max_handshake_time=5000rtmpt.max_keep_alive_requests=-1rtmpt.max_threads=20rtmpt.acceptor_thread_count=2rtmpt.processor_cache=20rtmpt.encoder_base_tolerance=5000rtmpt.encoder_drop_live_future=true# better setting for streaming mediartmpt.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 166rtmpt.max_in_msg_process=166# max time in millis that we will wait when offering data to the in or out queuertmpt.max_queue_offer_time=125# max offer attemptsrtmpt.max_queue_offer_attempts=4 # WebSocketws.host=0.0.0.0ws.port=8081 # Debug proxy (needs to be activated in red5-core.xml)proxy.source_host=127.0.0.1proxy.source_port=1936proxy.destination_host=127.0.0.1proxy.destination_port=1935 # JMXjmx.rmi.host=localhostjmx.rmi.port=9999jmx.rmi.sport=9998jmx.rmi.port.remoteobjects=jmx.keystorepass=passwordjmx.mina.monitor.enable=falsejmx.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 onejmx.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 threadsjmx.daemon=true# Whether the JMXConnectorServer should be started in a separate threadjmx.threaded=true # Server properties# max events to send in a single updateso.max.events.per.update=64so.scheduler.pool_size=4keyframe.cache.entry.max=500war.deploy.server.check.interval=600000fileconsumer.delayed.write=truefileconsumer.queue.size=120subscriberstream.buffer.check.interval=5000subscriberstream.underrun.trigger=100broadcaststream.auto.record=false


启动Red5

双击red.bat启动Red5服务器的浏览器访问,查看是否构建成功。http://localhost: port(配置文件中设置了localhost和port)是正确的,如下图所示。



视频直播开始准备

下载演示

你可以在上图中看到安装的红线。点击进入。选择OLFA安装


如果下载不成功,请看这里。

确保webapps下没有oflaDemo文件夹。下载压缩包,解压后放进去。

下载地址链接:https://pan.baidu.com/s/1Qd0UggtEhBv5nbVxQGPSzQ密码:4xqf


设置信息发布直播

进入发布设置界面:http://localhost:port/demos/publisher . html。


检查设置区域。选择视频后,在设备中选择摄像头,点击开始,会出现一个视频画面(可能会提示您是否允许。仅选择)



Server设置

返回到服务器屏幕,在Location中输入rtmp://localhost:1935/oflaDemo。该地址必须与red5.properties
中的rtmp协议设置相同,请单击“连接”。


右边是网络连接。Connect.Success出现,表示与服务器的连接成功。



推送视频流

切换到视频,点击发布页面的发布按钮,发布直播。


查看视频流

切换到服务器,点击播放,观看推送的视频流。



用自己的页面观看直播

Jwplayer是必需的。为了您的方便,它已被放在oflaDemo中。从上面的百度云链接下载。

修改的相关内容文件的值是活动页面的名称的值。Streamer是位置中的URL

lt;htmlgt;lt;headgt;lt;titlegt;Red5 - OFLADemolt;/titlegt;lt;script type='text/JavaScript' src='jwplayer.js'gt;lt;/scriptgt;lt;/headgt;lt;bodygt;lt;div id="player"gt;lt;script type='text/javascript'gt; jwplayer('player').setup({ 'flashplayer': 'player.swf', 'file': '直播页面的Name', 'streamer': 'rtmp://自己服务的IP:1935/oflaDemo', 'controlbar': 'bottom', 'width': '848', 'height': '360' });lt;/scriptgt;lt;/divgt;lt;/bodygt;lt;/htmlgt;


使用浏览器观看

输入地址http://localhost:port/of lademo/jw player . html即可查看。


以上是Java Red5服务器播放流媒体视频的详细内容。更多关于Java Red5播放流媒体视频的信息