由于原来项目中用到的是red5 0.8 只支持flv格式,最近要用到mp4格式,查看官网 red5 1.0.6 支持 FLV, F4V, MP4, 3GP格式。
网上找了半天最新的整合都是1.0.1及以下版本的,1.0 版本视频录制有个小bug,无奈只能自己整合了。
1.0.2之后作者将red5分成了几个子工程,仓库也从google迁移到了github. 地址:https://github.com/Red5
1.整合环境
red5 1.0.6 用Java 8编译,web容器这里用的是Tomat 8(支持Java8)。
2.配置文件
官网下载red5-server-1.0.6-RELEASE-server.zip,解压后查看conf文件夹,有20个配置文件。这里web整合我们用到的核心配置文件一共6个,如图。
找不到beanRefContext.xml的下载red5-server-1.0.6-RELEASE的源代码
在 \red5-server-1.0.6-RELEASE\src\main\server\war 即可找到,这里配置文件都是web需要的,但是作者没更新这面的配置文件,都是1.0及以下的配置文件。需要我们一一修改。
如red5-common.xml
<?xml version="1.0" encoding="UTF-8" ?>
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:lang="http://www.springframework.org/schema/lang" xmlns:context="http://www.springframework.org/schema/context" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/lang http://www.springframework.org/schema/lang/spring-lang.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
<!-- DO NOT FORMAT THIS FILE IN ECLIPSE -->
<bean id="placeholderConfig" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="location" value="classpath:/red5/red5.properties" />
</bean>
<!-- Server bean -->
<bean id="red5.server" class="org.red5.server.Server" />
<bean id="minaEncoder" class="org.red5.server.net.rtmp.codec.RTMPMinaProtocolEncoder" scope="prototype">
<property name="baseTolerance" value="${rtmp.encoder_base_tolerance}" />
<property name="dropLiveFuture" value="${rtmp.encoder_drop_live_future}" />
</bean>
<bean id="minaDecoder" class="org.red5.server.net.rtmp.codec.RTMPMinaProtocolDecoder" scope="prototype" />
<!-- Deals with StatusObjects representing statuses like NetConnection.Connect.Success status -->
<bean id="statusObjectService" class="org.red5.server.net.rtmp.status.StatusObjectService" autowire="byType"/>
<!-- RTMPT codec factory -->
<bean id="rtmptCodecFactory" class="org.red5.server.net.rtmpt.codec.RTMPTCodecFactory" autowire="byType" init-method="init">
<property name="baseTolerance" value="${rtmpt.encoder_base_tolerance}" />
<property name="dropLiveFuture" value="${rtmpt.encoder_drop_live_future}" />
</bean>
<!-- Remoting calls codec factory -->
<bean id="remotingCodecFactory" class="org.red5.server.net.remoting.codec.RemotingCodecFactory" autowire="byType" init-method="init"/>
<!-- Streamable file factory -->
<bean id="streamableFileFactory" class="org.red5.server.stream.StreamableFileFactory">
<property name="services">
<list>
<bean id="flvFileService" class="org.red5.server.service.flv.impl.FLVService">
<property name="generateMetadata" value="true"/>
</bean>
<bean id="mp3FileService" class="org.red5.server.service.mp3.impl.MP3Service"/>
<bean id="mp4FileService" class="org.red5.server.service.mp4.impl.MP4Service"/>
<bean id="m4aFileService" class="org.red5.server.service.m4a.impl.M4AService"/>
</list>
</property>
</bean>
<!-- Handles creation / lookup of shared objects -->
<bean id="sharedObjectService" class="org.red5.server.so.SharedObjectService">
<property name="maximumEventsPerUpdate" value="${so.max.events.per.update}"/>
<property name="persistenceClassName">
<value>org.red5.server.persistence.FilePersistence</value>
</property>
<property name="scheduler">
<bean class="org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler">
<property name="poolSize" value="${so.scheduler.pool_size}" />
<property name="waitForTasksToCompleteOnShutdown" value="false"/>
<property name="daemon" value="true"/>
<property name="threadNamePrefix" value="SharedObjectScheduler-"/>
</bean>
</property>
</bean>
<!-- High level access to streams -->
<bean id="streamService" class="org.red5.server.stream.StreamService"/>
<!-- High level access to broadcasted streams -->
<bean id="providerService" class="org.red5.server.stream.ProviderService"/>
<!-- Provides output to consumers -->
<bean id="consumerService" class="org.red5.server.stream.ConsumerService"/>
<!-- Scheduling service -->
<bean id="schedulingService" class="org.red5.server.scheduling.QuartzSchedulingService">
</bean>
<!-- Use injection to setup thread pool for remoting clients -->
<bean id="remotingClient" class="org.red5.server.net.remoting.RemotingClient">
<property name="poolSize" value="1"/>
</bean>
<!-- Now we can load the cache engine, only one may be enabled at a time. If no-caching is required select the NoCacheImpl. Three other implementations based on EhCache, and Red5Cache are also available. -->
<bean id="object.cache" class="org.red5.cache.impl.NoCacheImpl"/>
<!-- Cache to use for keyframe metadata. -->
<bean id="keyframe.cache" class="org.red5.io.CachingFileKeyFrameMetaCache">
<property name="maxCacheEntry" value="${keyframe.cache.entry.max}" />
</bean>
<!-- Represents FLV files Use injection to set the cache impl to be used with flvs -->
<bean id="flv.impl" class="org.red5.io.flv.impl.FLV">
<property name="cache">
<ref bean="object.cache"/>
</property>
</bean>
<!-- Use injection to set the keyframe cache for FLV files -->
<bean id="flvreader.impl" class="org.red5.io.flv.impl.FLVReader">
<property name="keyFrameCache">
<ref bean="keyframe.cache"/>
</property>
</bean>
<!-- Use injection to set the keyframe cache for MP4 files -->
<bean id="mp4reader.impl" class="org.red5.io.mp4.impl.MP4Reader"/>
<!-- Use injection to set the keyframe cache for MP3 files -->
<bean id="mp3reader.impl" class="org.red5.io.mp3.impl.MP3Reader">
<property name="frameCache">
<ref bean="keyframe.cache"/>
</property>
</bean>
<!-- Use injection to set the buffer type for reading FLV files -->
<bean class="org.springframework.beans.factory.config.MethodInvokingFactoryBean">
<property name="staticMethod">
<value>org.red5.io.flv.impl.FLVReader.setBufferType</value>
</property>
<!-- Three buffer types are available 'auto', 'heap', and 'direct' -->
<property name="arguments" value="auto"/>
</bean>
<!-- Use injection to set the buffer size for reading FLV files -->
<bean class="org.springframework.beans.factory.config.MethodInvokingFactoryBean">
<property name="staticMethod">
<value>org.red5.io.flv.impl.FLVReader.setBufferSize</value>
</property>
<!-- Three buffer types are available 'auto', 'heap', and 'direct' -->
<property name="arguments" value="4096"/>
</bean>
<!-- Low level access for recording to file -->
<bean id="fileConsumer" scope="prototype" lazy-init="true" class="org.red5.server.stream.consumer.FileConsumer">
<property name="delayWrite" value="${fileconsumer.delayed.write}"/>
<property name="queueThreshold" value="${fileconsumer.queue.size}"/>
</bean>
<!-- ClientBroadcastStream and PlaylistSubscriberStream that will be used by RTMPConnection and maybe other classes. These beans are lazy-init because most likely server will need to be up and running before we can get a smart implementation of these streams -->
<bean id="playlistSubscriberStream" scope="prototype" lazy-init="true" class="org.red5.server.stream.PlaylistSubscriberStream">
<!-- Check for buffer underruns every X ms and generate NetStream.Play.InsufficientBW accordingly. Set to 0 to disable. Be careful not to set this value too small to avoid network congestion. -->
<property name="bufferCheckInterval" value="${subscriberstream.buffer.check.interval}"/>
<!-- A NetStream.Play.InsufficientBW message is generated if more than X messages are queued for sending on the connection. This value will also control the maximum pending messages on the server. To use a smaller value on slow connections to get smaller delay for downstream server commands. -->
<property name="underrunTrigger" value="${subscriberstream.underrun.trigger}"/>
</bean>
<bean id="clientBroadcastStream" scope="prototype" lazy-init="true" class="org.red5.server.stream.ClientBroadcastStream">
<property name="automaticRecording" value="${broadcaststream.auto.record}"/>
</bean>
</beans>
xml配置文件不要用eclipse格式化,否则会造成莫名的错误。
整合过程不再zao复述,过程不复杂,但一定要细心。
运行效果图:
需要其他版本1.0.2-1.0.7的
替换以下jar包到对应版本即可。
red5-client-1.0.6-RELEASE.jar
red5-io-1.0.6-RELEASE.jar
red5-server.jar
red5-server-common-1.0.6-RELEASE.jar
red5-service.jar
源代码用MyEclipse 2015开发,下载链接
1.0.0源代码下载 Jdk1.6以上 tomcat 6.0
1.0.6源代码下载 jdk 1.7以上 tomcat 8.0