- 浏览: 85165 次
- 性别:
- 来自: 北京
最新评论
-
zhulongxia:
您好,请问您的服务端的配置和用flex写客户端的配置一样么?还 ...
Red5 Client 调用 Red5 Server -
zhaoleiJE:
public static String toMPTree(S ...
jave -
zouwu85:
你好,你这个能录制网络上的flv小游戏的数据吗?
使用Red5 录制视频 -
emilyHong:
不过有没有多条线的?
js曲线图 -
amssy_zhu:
很好,正准备开发这样的系统
使用Java实现Comet风格的Web应用
import java.io.File;
import org.apache.mina.common.ByteBuffer;
import org.red5.io.IStreamableFile;
import org.red5.io.ITag;
import org.red5.io.ITagWriter;
import org.red5.io.flv.impl.FLVService;
import org.red5.io.flv.impl.Tag;
import org.red5.io.utils.ObjectMap;
import org.red5.server.api.event.IEvent;
import org.red5.server.api.event.IEventDispatcher;
import org.red5.server.api.service.IPendingServiceCall;
import org.red5.server.api.service.IPendingServiceCallback;
import org.red5.server.net.rtmp.Channel;
import org.red5.server.net.rtmp.RTMPClient;
import org.red5.server.net.rtmp.RTMPConnection;
import org.red5.server.net.rtmp.codec.RTMP;
import org.red5.server.net.rtmp.event.AudioData;
import org.red5.server.net.rtmp.event.IRTMPEvent;
import org.red5.server.net.rtmp.event.Notify;
import org.red5.server.net.rtmp.event.VideoData;
import org.red5.server.net.rtmp.message.Header;
import org.red5.server.net.rtmp.status.StatusCodes;
import org.red5.server.stream.AbstractClientStream;
import org.red5.server.stream.IStreamData;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class MyRtmpClient extends RTMPClient {
private static final Logger logger = LoggerFactory.getLogger(MyRtmpClient.class);
private String saveAsFileName = "test.flv";
public static void main(String[] args) {
String host = "localhost";
String app = "oflaDemo";
final String name = "IronMan.flv";
int port = 1935;
final int duration = 10000; // milliseconds, -2 means until end of stream
final MyRtmpClient client = new MyRtmpClient();
logger.debug("connecting, host: " + host + ", app: " + app + ", port: " + port);
IPendingServiceCallback callback = new IPendingServiceCallback() {
public void resultReceived(IPendingServiceCall call) {
logger.debug("service call result: " + call);
if ("connect".equals(call.getServiceMethodName())) {
client.createStream(this);
} else if ("createStream".equals(call.getServiceMethodName())) {
Integer streamId = (Integer) call.getResult();
logger.debug("createStream result stream id: " + streamId);
logger.debug("playing video by name: " + name);
client.play(streamId, name, 0, duration);
}
}
};
client.connect(host, port, app, callback);
}
private RTMPConnection conn;
private ITagWriter writer;
private int videoTs;
private int audioTs;
@Override
public void connectionOpened(RTMPConnection conn, RTMP state) {
logger.debug("connection opened");
super.connectionOpened(conn, state);
this.conn = conn;
init();
}
@Override
public void connectionClosed(RTMPConnection conn, RTMP state) {
logger.debug("connection closed");
super.connectionClosed(conn, state);
if (writer != null) {
writer.close();
writer = null;
}
System.exit(0);
}
@Override
public void createStream(IPendingServiceCallback callback) {
logger.debug("create stream");
IPendingServiceCallback wrapper = new CreateStreamCallBack(callback);
invoke("createStream", null, wrapper);
}
@Override
protected void onInvoke(RTMPConnection conn, Channel channel, Header header, Notify notify, RTMP rtmp) {
super.onInvoke(conn, channel, header, notify, rtmp);
ObjectMap<String, String> map = (ObjectMap) notify.getCall().getArguments()[0];
String code = map.get("code");
if (StatusCodes.NS_PLAY_STOP.equals(code)) {
logger.debug("onInvoke, code == NetStream.Play.Stop, disconnecting");
disconnect();
}
}
private void init() {
File file = new File(saveAsFileName);
FLVService flvService = new FLVService();
flvService.setGenerateMetadata(true);
try {
IStreamableFile flv = flvService.getStreamableFile(file);
writer = flv.getWriter();
} catch (Exception e) {
throw new RuntimeException(e);
}
}
private class CreateStreamCallBack implements IPendingServiceCallback {
private IPendingServiceCallback wrapped;
public CreateStreamCallBack(IPendingServiceCallback wrapped) {
this.wrapped = wrapped;
}
public void resultReceived(IPendingServiceCall call) {
Integer streamIdInt = (Integer) call.getResult();
if (conn != null && streamIdInt != null) {
MyNetStream stream = new MyNetStream();
stream.setConnection(conn);
stream.setStreamId(streamIdInt.intValue());
conn.addClientStream(stream);
}
wrapped.resultReceived(call);
}
}
private class MyNetStream extends AbstractClientStream implements IEventDispatcher {
public void close() { }
public void start() { }
public void stop() { }
public void dispatchEvent(IEvent event) {
if (!(event instanceof IRTMPEvent)) {
logger.debug("skipping non rtmp event: " + event);
return;
}
IRTMPEvent rtmpEvent = (IRTMPEvent) event;
if (logger.isDebugEnabled()) {
logger.debug("rtmp event: " + rtmpEvent.getHeader() + ", "
+ rtmpEvent.getClass().getSimpleName());
}
if (!(rtmpEvent instanceof IStreamData)) {
logger.debug("skipping non stream data");
return;
}
if (rtmpEvent.getHeader().getSize() == 0) {
logger.debug("skipping event where size == 0");
return;
}
ITag tag = new Tag();
tag.setDataType(rtmpEvent.getDataType());
if (rtmpEvent instanceof VideoData) {
videoTs += rtmpEvent.getTimestamp();
tag.setTimestamp(videoTs);
} else if (rtmpEvent instanceof AudioData) {
audioTs += rtmpEvent.getTimestamp();
tag.setTimestamp(audioTs);
}
ByteBuffer data = ((IStreamData) rtmpEvent).getData().asReadOnlyBuffer();
tag.setBodySize(data.limit());
tag.setBody(data);
try {
writer.writeTag(tag);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
}
}
使用:
commons-collections-3.2.jar
jcl104-over-slf4j-1.4.3.jar
logback-classic-0.9.8.jar
logback-core-0.9.8.jar
mina-core-1.1.6.jar
red5.jar
slf4j-api-1.4.3.jar
spring-beans-2.0.8.jar
spring-context-2.0.8.jar
spring-core-2.0.8.jar
import org.apache.mina.common.ByteBuffer;
import org.red5.io.IStreamableFile;
import org.red5.io.ITag;
import org.red5.io.ITagWriter;
import org.red5.io.flv.impl.FLVService;
import org.red5.io.flv.impl.Tag;
import org.red5.io.utils.ObjectMap;
import org.red5.server.api.event.IEvent;
import org.red5.server.api.event.IEventDispatcher;
import org.red5.server.api.service.IPendingServiceCall;
import org.red5.server.api.service.IPendingServiceCallback;
import org.red5.server.net.rtmp.Channel;
import org.red5.server.net.rtmp.RTMPClient;
import org.red5.server.net.rtmp.RTMPConnection;
import org.red5.server.net.rtmp.codec.RTMP;
import org.red5.server.net.rtmp.event.AudioData;
import org.red5.server.net.rtmp.event.IRTMPEvent;
import org.red5.server.net.rtmp.event.Notify;
import org.red5.server.net.rtmp.event.VideoData;
import org.red5.server.net.rtmp.message.Header;
import org.red5.server.net.rtmp.status.StatusCodes;
import org.red5.server.stream.AbstractClientStream;
import org.red5.server.stream.IStreamData;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class MyRtmpClient extends RTMPClient {
private static final Logger logger = LoggerFactory.getLogger(MyRtmpClient.class);
private String saveAsFileName = "test.flv";
public static void main(String[] args) {
String host = "localhost";
String app = "oflaDemo";
final String name = "IronMan.flv";
int port = 1935;
final int duration = 10000; // milliseconds, -2 means until end of stream
final MyRtmpClient client = new MyRtmpClient();
logger.debug("connecting, host: " + host + ", app: " + app + ", port: " + port);
IPendingServiceCallback callback = new IPendingServiceCallback() {
public void resultReceived(IPendingServiceCall call) {
logger.debug("service call result: " + call);
if ("connect".equals(call.getServiceMethodName())) {
client.createStream(this);
} else if ("createStream".equals(call.getServiceMethodName())) {
Integer streamId = (Integer) call.getResult();
logger.debug("createStream result stream id: " + streamId);
logger.debug("playing video by name: " + name);
client.play(streamId, name, 0, duration);
}
}
};
client.connect(host, port, app, callback);
}
private RTMPConnection conn;
private ITagWriter writer;
private int videoTs;
private int audioTs;
@Override
public void connectionOpened(RTMPConnection conn, RTMP state) {
logger.debug("connection opened");
super.connectionOpened(conn, state);
this.conn = conn;
init();
}
@Override
public void connectionClosed(RTMPConnection conn, RTMP state) {
logger.debug("connection closed");
super.connectionClosed(conn, state);
if (writer != null) {
writer.close();
writer = null;
}
System.exit(0);
}
@Override
public void createStream(IPendingServiceCallback callback) {
logger.debug("create stream");
IPendingServiceCallback wrapper = new CreateStreamCallBack(callback);
invoke("createStream", null, wrapper);
}
@Override
protected void onInvoke(RTMPConnection conn, Channel channel, Header header, Notify notify, RTMP rtmp) {
super.onInvoke(conn, channel, header, notify, rtmp);
ObjectMap<String, String> map = (ObjectMap) notify.getCall().getArguments()[0];
String code = map.get("code");
if (StatusCodes.NS_PLAY_STOP.equals(code)) {
logger.debug("onInvoke, code == NetStream.Play.Stop, disconnecting");
disconnect();
}
}
private void init() {
File file = new File(saveAsFileName);
FLVService flvService = new FLVService();
flvService.setGenerateMetadata(true);
try {
IStreamableFile flv = flvService.getStreamableFile(file);
writer = flv.getWriter();
} catch (Exception e) {
throw new RuntimeException(e);
}
}
private class CreateStreamCallBack implements IPendingServiceCallback {
private IPendingServiceCallback wrapped;
public CreateStreamCallBack(IPendingServiceCallback wrapped) {
this.wrapped = wrapped;
}
public void resultReceived(IPendingServiceCall call) {
Integer streamIdInt = (Integer) call.getResult();
if (conn != null && streamIdInt != null) {
MyNetStream stream = new MyNetStream();
stream.setConnection(conn);
stream.setStreamId(streamIdInt.intValue());
conn.addClientStream(stream);
}
wrapped.resultReceived(call);
}
}
private class MyNetStream extends AbstractClientStream implements IEventDispatcher {
public void close() { }
public void start() { }
public void stop() { }
public void dispatchEvent(IEvent event) {
if (!(event instanceof IRTMPEvent)) {
logger.debug("skipping non rtmp event: " + event);
return;
}
IRTMPEvent rtmpEvent = (IRTMPEvent) event;
if (logger.isDebugEnabled()) {
logger.debug("rtmp event: " + rtmpEvent.getHeader() + ", "
+ rtmpEvent.getClass().getSimpleName());
}
if (!(rtmpEvent instanceof IStreamData)) {
logger.debug("skipping non stream data");
return;
}
if (rtmpEvent.getHeader().getSize() == 0) {
logger.debug("skipping event where size == 0");
return;
}
ITag tag = new Tag();
tag.setDataType(rtmpEvent.getDataType());
if (rtmpEvent instanceof VideoData) {
videoTs += rtmpEvent.getTimestamp();
tag.setTimestamp(videoTs);
} else if (rtmpEvent instanceof AudioData) {
audioTs += rtmpEvent.getTimestamp();
tag.setTimestamp(audioTs);
}
ByteBuffer data = ((IStreamData) rtmpEvent).getData().asReadOnlyBuffer();
tag.setBodySize(data.limit());
tag.setBody(data);
try {
writer.writeTag(tag);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
}
}
使用:
commons-collections-3.2.jar
jcl104-over-slf4j-1.4.3.jar
logback-classic-0.9.8.jar
logback-core-0.9.8.jar
mina-core-1.1.6.jar
red5.jar
slf4j-api-1.4.3.jar
spring-beans-2.0.8.jar
spring-context-2.0.8.jar
spring-core-2.0.8.jar
发表评论
-
red5检测流量
2010-07-16 17:27 1333@Override public void strea ... -
red5共享对象
2010-07-16 17:21 1799package ChatSystem; import java ... -
red5+hibernate
2010-07-16 17:18 1396Application 代码: package conjs.i ... -
Red5实现直播
2010-07-16 17:14 9869发布端(Publish): var nc:NetConnect ... -
Red5 Client 调用 Red5 Server
2010-07-16 17:02 2913package com.conjs; import org. ... -
jave
2010-07-14 10:56 1317JAVE (Java Audio Video Encoder) ... -
nutch+solr
2010-07-13 17:52 1592两年前集成Nutch 和Solr 这两个Apache Luc ... -
ActiveMQ
2010-07-13 17:44 46251. 背景 ... -
red5的一些概念
2010-07-09 10:52 1291IConnection 是连接的意思 并且有getClient ... -
red5的eclipse插件地址
2010-07-09 10:05 1171Name: Red5Plugin 0.2.x (Eclipse ... -
uuid
2010-07-06 17:55 1076java uuid生成方法 UUID(Universally ... -
Java集合排序及java集合类详解:集合框架中常用类比较
2010-07-01 14:06 1979用 “ 集合框架 ” 设计软件时,记住该框架四个 ... -
Java集合排序及java集合类详解:Set
2010-07-01 14:04 14821.5 Set 1.5.1 概述 ... -
Java集合排序及java集合类详解:Map
2010-07-01 14:02 21601.4 Map 1.4.1 概 ... -
Java集合排序及java集合类详解:Collection
2010-07-01 13:50 21431.2 Collection ... -
Java集合排序及java集合类详解:集合框架概述
2010-07-01 13:47 12911.1 集 ... -
关于 Java Collections API 您不知道的 5 件事,第 2 部分
2010-06-29 13:57 677java.util 中的 Collection ... -
关于 Java Collections API 您不知道的 5 件事,第 1 部分
2010-06-29 13:55 798对于很多 Java 开发人员 ... -
关于 Java 对象序列化您不知道的 5 件事
2010-06-29 11:59 863数年前,当和一个软件团队一起用 Java 语言编写一个应用程序 ... -
使用 Apache MINA 开发高性能网络应用程序
2010-06-29 11:41 900本文将通过一个简单的问候程序 HelloServer 来介绍 ...
相关推荐
/** Path that will store recorded videos. */ public String recordPath = "recordedStreams/"; /** Path that contains VOD streams.... public String playbackPath = "videoStreams/"; /** Set if the path ...
这个"red5视频插件"很可能是一个与Red5服务器配合使用的播放器组件,用于优化视频流的播放体验。 在流媒体开发中,Red5扮演着至关重要的角色。它允许开发者创建各种类型的多媒体应用程序,如直播、录制、播放、存储...
Red5是由Java开发的流媒体服务器,它允许开发者创建、录制、存储和分发音频、视频、数据以及屏幕共享流。Red5支持多种流媒体协议,包括RTMP、HLS(HTTP Live Streaming)和RTSP(Real-Time Streaming Protocol),...
使用Red5 RTSP视频服务器,你可以实现以下功能: 1. **视频直播**:通过Red5 Server,你可以将视频源(如摄像头)的实时数据推送到服务器,并分发给多个客户端,实现大规模的视频直播。 2. **录制与回放**:Red5 ...
RED5是一款用Java编写,支持实时流传输协议(RTMP)的服务器,它允许用户创建、录制以及播放音频、视频和其他交互式富媒体内容。 【描述】中提到的"red5chatv2.1 red5建的一个FLASH视频聊天会议例子"表明这是一个...
Red5是一个开源的流媒体服务器,它支持实时的音频、视频流传输,以及录制、播放等功能。本篇文章将详细阐述如何使用Red5插件搭建Java开发环境,帮助你创建并运行你的第一个Red5项目。 首先,了解Red5的基础概念是...
Red5是一个基于Java的流媒体服务器,它支持RTMP(Real Time Messaging Protocol)、HLS(HTTP Live Streaming)和RTSP(Real Time Streaming Protocol)等协议,可以提供实时流服务,例如在线视频播放、直播和录制。...
接下来,你还需要编写客户端代码,使用ActionScript或者Flex来与服务器通信,实现视频播放、录制、互动等功能。客户端通常会通过RTMP协议与Red5服务器建立连接,获取或发送视频流。 在客户端开发中,你需要创建一个...
在Red5的手册中,还介绍了Red5使用的默认端口,包括http.port=5080、rtmp.port=1935、rtmpt.port=8088、mrtmp.port=9035、proxy.source_port=1936等,可以在[RED5_HOME]\conf\red5.properties文件中更改。...
Red5是一款开源的媒体服务器,主要用于实时音视频流传输、录制、转码等操作。它支持多种协议,如RTMP、WebRTC等,并且可以方便地集成到Flash和其他客户端应用中。本文将详细介绍如何使用Red5进行录音录像的方法及其...
- 转换RTSP流为RTMP流:使用FFmpeg命令行工具将摄像机采集的RTSP协议视频流转换为RTMP格式,并推送到Red5服务器。具体命令格式为:ffmpeg -i "RTSP流地址" -f flv -r 25 -s 640x480 -an "RTMP流地址"。其中-i后面跟...
Red5是一款基于Java的开源Flash流媒体服务器,它支持RSTP协议,提供了一系列示例应用,如在线录制、播放、聊天和视频会议等。Red5作为Macromedia商业产品FMS的一个替代方案,具有开源、成本低和可扩展性强的优势。在...
Flex Red5 Tomcat 视频语音录制和播放 在网上找,总发现文章都一样,而且都是不完整的, 这里希望能够给跟我一样学习中的朋友一些帮助, 详细说明在压缩文件中有。 Flex+Red5+Tomcat视频播放器: ...
总结一下,实现Android实时录制视频流并上传到Red5服务器,涉及以下几个关键步骤: 1. 配置和使用Android MediaRecorder进行视频录制。 2. 使用Java的Socket类建立与Red5服务器的连接。 3. 实现RTMP推送,将视频流推...
访问Red5官方网站下载最新版本的Red5,解压后即可使用。对于生产环境,建议通过脚本或服务管理工具将其设置为系统服务。 ##### 3.3 配置Red5 Red5的配置文件通常位于`conf`目录下,主要包括`server.xml`、`context...
总结起来,AS3与RED5的结合使用涵盖了视频播放、视频录制等多个方面,它们为开发者提供了一个强大的工具集,可以在Web上实现丰富的多媒体交互体验。通过深入学习和实践,你可以创建出具有高度定制化和交互性的视频...
Red5是一款开源的流媒体服务器,它支持实时流传输协议(RTMP),并提供录制、播放、存储等功能,广泛应用于在线视频直播、VoIP、互动游戏等场景。本教程将介绍如何进行Red5的入门学习,并结合Tomcat和MyEclipse进行...
Red5是一款基于Java开发的开源流媒体服务器,它支持多种功能,包括将音频(MP3)和视频(FLV)转换为播放流,客户端播放流的录制(仅限FLV),共享对象,现场直播流发布,以及远程调用。Red5依赖RSTP作为流媒体传输...