[英]Java send Live Video InputStream to Red5 Media Server
I have an InputStream
from a Socket in Java. 我有一个来自Java套接字的InputStream
。 The InputStream
is a H.264 video live stream. InputStream
是H.264视频直播流。 I would like to send this Video InputStream
to a red5 Media Server, so that other clients can watch it. 我想将此视频InputStream
发送到red5媒体服务器,以便其他客户端可以观看它。
I found this example 我找到了这个例子
package com.ryong21.example.publisher;import java.io.File;
import java.io.IOException;
import java.util.Date;
import org.red5.server.messaging.IMessage;
import org.red5.server.stream.message.RTMPMessage;
import org.red5.server.stream.provider.FileProvider;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class Publisher {
public static void main(String[] args) throws IOException, InterruptedException {
Logger log = LoggerFactory.getLogger(Publisher.class);
String publishName = "test";
String localFile = "2.mp3";
String host = "rtmpxn.91kge.com";
int port = 1935;
String app = "live";
IMessage msg = null;
int timestamp = 0;
int lastTS = 0;
PublishClient client = new PublishClient();
client.setHost(host);
client.setPort(port);
client.setApp(app);
client.start(publishName, "live", null);
while(client.getState() != PublishClient.PUBLISHED){
Thread.sleep(500);
}
FileProvider fp = new FileProvider(new File(localFile));
Date begin = new Date();
log.debug(begin.toString());
while(true){
msg = fp.pullMessage(null);
if(msg == null){
log.debug("done!");
break;
}
timestamp = ((RTMPMessage)msg).getBody().getTimestamp();
Thread.sleep(timestamp - lastTS);
lastTS = timestamp;
client.pushMessage( msg);
}
Date end = new Date();
log.debug(end.toString());
client.stop();
}
}` }`
My problem is how to use this with a Sockets InputStream, instead of the File used in FileProvider. 我的问题是如何通过Sockets InputStream而不是FileProvider中使用的File来使用它。 The InputStream is already in H.264 encoded. InputStream已经使用H.264编码。
Ok, after digging a little deeper into video streaming, i found out that i ll first have to convert the InputStream to a container format file. 好的,在更深入地研究了视频流之后,我发现我首先必须将InputStream转换为容器格式文件。 Possible container formats are .mp4 or .flv 可能的容器格式为.mp4或.flv
Having created the container file, i can now publish it to the red5 media server. 创建了容器文件后,我现在可以将其发布到red5媒体服务器。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.