I am trying to use xuggle and red5 to generate streaming video in a browser. As a first step I'm just trying to run a video through xuggle and have it show up on my red5 server. The problem is I don't know how to configure red5 to hook up to my java code. I have this code here:
private static String outputUrl = "rtmp://localhost:5080/oflaDemo/";
private static String inputFilename = "/home/usr/jworkspace1/GetContainerInfo/aaa.ogg";
public static void main(String[] args)
{
IMediaReader mediaReader = ToolFactory.makeReader(inputFilename);
// create a media writer
IMediaWriter mediaWriter = ToolFactory.makeWriter(outputUrl, mediaReader);
// add a writer to the reader, to create the output file
mediaReader.addListener(mediaWriter);
// create a media viewer with stats enabled
IMediaViewer mediaViewer = ToolFactory.makeViewer(true);
// add a viewer to the reader, to see the decoded media
mediaReader.addListener(mediaViewer);
// read and decode packets from the source file and
// and dispatch decoded audio and video to the writer
while (mediaReader.readPacket() == null)
{
;
}
}
That gives me an error that says:
java.lang.IllegalArgumentException: could not open: rtmp://localhost:5080/oflaDemo/
My question is how can I open up red5 to receive rtmp from my java program?
i think port 5080 is http port.
Ports
By default, Red5 open the following ports :
5080 (HTTP port - embedded Tomcat)
1935 (RTMP port)
8443 (RTMPS port)
9980 (JMX port - admin and shutdown)
you should use port 1935 for rtmp
Related
I am making a small project with Java sockets, it's like a port scanner and I am wondering if I can detect a port "version" like with Zenmap. In case you're not familiar with what I'm talking about, if you scan a target with zenmap then go to "Ports / Hosts" and you get something like this.
I was wondering if I could get the port "version" information in Java.
When you get a connection, try reading the first line the server sends. Many applications identify themselves when the connection is established. This is especially true for ftp servers like your example.
For example, this connects to a port on a server and reads up to 1000 bytes from what the server sent, which should be enough:
Socket s = new Socket(hostname, port)
InputStream in = s.getInputStream();
byte[] bs = new byte[1000];
int len = in.read(bs);
s.close();
You can then convert those bytes into a string:
String serverInfo = new String(bs, 0, len);
// I got "SSH-2.0-OpenSSH_5.3\r\n" in a test
Not all protocols start with the server sending something so you should also set a timeout for reading from the socket.
I am trying to communicate with Edito (Seiko) KSM347 printer through Serial Port. I have successfully printed data through echo "test" > /dev/usb/lp1 or Java's code:
FileOutputStream fs = new FileOutputStream("/dev/usb/lp1");
PrintStream ps = new PrintStream(fs);
ps.write(cmd); // cmd is bytes with corresponding commands
ps.flush();
It works properly too. But I need to send data and get response. In other projects I have been using RXTX library which was working good with for example Huawei MU609 modems. Now this library does not see these /dev/usb/ ports.
CommPortIdentifier portId = null;
Enumeration portEnum = CommPortIdentifier.getPortIdentifiers();
// this list contains only /dev/ttyS0 and /dev/ttyUSB0 devices.
How to force RXTX to use these ports? Even setting -Dgnu.io.rxtx.SerialPorts does not work. Please help :)
To overcome Chromecast's restriction on streaming from self-certificated https servers (in my case the Subsonic music server) I'm utilizing an instance of the NanoHTTPD server already running as part of my Android app. The idea is to stream from the Subsonic server (SSL) and connect that stream to a new stream (non SSL) for the NanoHTTP.Response back to Chromecast. I have the InputStream working from the Subsonic server (which plays through the MediaPlayer) but don't know how to re-stream unencrypted for the following call: new NanoHTTPD.Response(NanoHTTPD.Response.Status.OK, "audio/mpeg", newStream); So in a nutshell, how do I convert an https encrypted audio stream to a decrypted audio stream on the fly?
Ok, managed to get all of this working. Subsonic server using https, accessible from Android and Chromecast using the server's self-signed certificate. If https is on then both Android and Chromecast use a nanohttpd proxy server running on the Android client to stream to the Android MediaPlayer and the html5 audio element respectively. The serve function override of the nanohttpd server running on Android contains the following code:-
int filesize = .... obtained from Subsonic server for the track to be played
// establish the https connection using the self-signed certificate
// placed in the Android assets folder (code not shown here)
HttpURLConnection con = _getConnection(subsonic_url,"subsonic.cer")
// Establish the InputStream from the Subsonic server and
// the Piped Streams for re-serving the unencrypted data
// back to the requestor
final InputStream is = con.getInputStream();
PipedInputStream sink = new PipedInputStream();
final PipedOutputStream source = new PipedOutputStream(sink);
// On a separate thread, read from Subsonic and write to the pipe
Thread t = new Thread(new Runnable() {
public void run () {
try {
byte[] b = new byte[1024];
int len;
while ((len = is.read(b,0,1024)) != -1)
source.write(b, 0, len);
source.flush();
}
catch (IOException e) {
}
}});
t.start();
sleep(200); // just to let the PipedOutputStream start up
// Return the PipedInputStream to the requestor.
// Important to have the filesize argument
return new NanoHTTPD.Response(NanoHTTPD.Response.Status.OK,
"audio/mpeg", sink, filesize);
I found that streaming flac files with mp3 transcoding on gave me the flac filesize but of course the mp3 stream. This proved difficult to handle for the html5 audio element so I reverted to adding &format=raw to the Subsonic api call for the stream. So regardless of user's configuration over https I stream raw format and it all seems to be working well so far in testing.
I'm writing a Java code which have to send some data to an elecronic system and to receive some data from it through wireless. The electronic system is made of PIC32 and RN-171 module. I'm now trying to connect to the RN-171 network and to send and receive some data. Although I can in my java code set up an OutputStream and send some data to the RN-171 properly, I can't set up an InputStream and my app launches the following exception:
java.io.StreamCorruptedException: invalid stream header: 2A48454C
at java.io.ObjectInputStream.readStreamHeader(ObjectInputStream.java:804)
at java.io.ObjectInputStream.<init>(ObjectInputStream.java:299)
at TestController.sendParametersToWirelessModule(TestController.java:44)
at TestController.main(TestController.java:30)
The code in my java app, which generates the exception is:
try{
//1. creating a socket to connect to the server
requestSocket = new Socket("1.2.3.4", 2000);
System.out.println("Connected to localhost in port 2004");
//2. get Input and Output streams
out = new ObjectOutputStream(requestSocket.getOutputStream());
out.flush();
--> in = new ObjectInputStream(requestSocket.getInputStream());
//3: Communicating with the server
sendMessage(message); }
(The arrow indicates the code line which generates exception)
Is there a solution? Could anyone help me please?
Thanks
Use the following code instead:
out = requestSocket.getOutputStream();
in = requestSocket.getInputStream();
ObjectOutputStream/ObjectInputStream are used to serialize/deserialize Java objects. There is also no point in flushing the output stream before writing to it.
I use my Android application for streaming video from phone camera to my PC Server and need to save them into file on HDD. So, file created and stream successfully saved, but the resulting file can not play with any video player (GOM, KMP, Windows Media Player, VLC etc.) - no picture, no sound, only playback errors.
I tested my Android application into phone and may say that in this instance captured video successfully stored on phone SD card and after transfer it to PC played witout errors, so, my code is correct.
In the end, I realized that the problem in the video container: data streamed from phone in MP4 format and stored in *.mp4 files on PC, and in this case, file may be incorrect for playback with video players. Can anyone suggest how to correctly save streaming video to a file?
There is my code that process and store stream data (without errors handling to simplify):
// getOutputMediaFile() returns a new File object
DataInputStream in = new DataInputStream (server.getInputStream());
FileOutputStream videoFile = new FileOutputStream(getOutputMediaFile());
int len;
byte buffer[] = new byte[8192];
while((len = in.read(buffer)) != -1) {
videoFile.write(buffer, 0, len);
}
videoFile.close();
server.close();
Also, I would appreciate if someone will talk about the possible "pitfalls" in dealing with the conservation of media streams.
Thank you, I hope for your help!
Alex.
UPD:
For record video locally to phone storage I use:
//targetFile - new File object, represents a file on phone SD card
myMediaRecorder.setOutputFile(targetFile);
And for streaming it to PC (without errors handling to simplify)
ParcelFileDescriptor pfd = null;
Socket socket = null;
String hostname = "my IP";
int port = 8081;
socket = new Socket(InetAddress.getByName(hostname), port);
pfd = ParcelFileDescriptor.fromSocket(socket);
myMediaRecorder.setOutputFile(pfd.getFileDescriptor());
Make this comment to flag question as answered: RTMP should be properly encoded and streamed, my simple socket solution is invalid and question is not correct in this sense. Related to How to encode h.264 live stream to RTP packet with Java