I have an InputStream
from a Socket in Java. The InputStream
is a H.264 video live stream. I would like to send this Video InputStream
to a red5 Media Server, so that other clients can watch it.
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. The InputStream is already in H.264 encoded.
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. Possible container formats are .mp4 or .flv
Having created the container file, i can now publish it to the red5 media server.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.