Skip to Main Content

Java User Groups

Order: h.264 streaming on socket.

gramo82Oct 30 2017 — edited Oct 30 2017

We need class both on receiver and sender side that are going to be used for video streaming (only images) in h.264 protocol or if you know better one – than in another.

On sender side we need a class that, lets’ say, is called „Sender” with a constructor in which we will put height and width of sending images, time interval in ms with which we will send next frame and outputstream for streaming. This class should have also the putCapture(BufferedImage) method. In this method we send next images from the film and we are obliged to realize it with the frequency exactly the same like in the constructor. It means that after creating an object delivered class we will

call putCapure metod as often as we have declared in the constructor and your class (Sender) will send  h.264 data via given OutputStream.

“Receiver” class should be initiated similar to the senders’ one (width, height, targeted frames and expected time in long between the frames) with one difference – despite of OutputStream it should be given in InputStream constructor to streams receiver. In constructor there should be listener object given that has receiveCapture(BufferedImage capture) method that will be called always after receiving next frame. That way you will inform us about next frames. In other words, Recievier class reads data from given InputStream and call receivCapture(BufferedImage) when next frame of video streaming will be received.

Of course on described above InputStream and OutputStream we perform neither before starting streaming nor after any operations. Intentionally I am not showing who in this communication will be server and who the client, I am only showing InputStream and OutputStream streams. Eventually we want to bring two different architectures in which in one of them the Sender connects with server and promptly send the data to it, on the other it is the Receiver who connects with server and the server instantly after connection sends images using stream (as you can guess – it is resend from another client).

As I read the solution for the problem above could be h.264 compression but till now either using JMF or Xuggle I could not implement such solution. All examples are on the files downloaded from the disc and at all was not connected with rtp whatsoever.

For example lets’ use such naming of classes and methods:

public class Sender {

       public Sender(int width,int height,long time_interval,OutputStream os) {




       public void putCapture(BufferedImage capture) {





public class Receiver {


       public Receiver(int width,int height,long time_interval,InputStream os,ReveiverInterface listener) {




       public static interface ReveiverInterface {

             public void receiveCapture(BufferedImage capture);



Salary: 0,2 BTC

Post Details
Added on Oct 30 2017