how to save images as jpeg and convert it into a single video file in java
<p>am having a java application in my pc and an android application in my phone. phone sends video frames in jpeg format using ByteArrayOutputStream to pc,the pc recieve this using  ByteArrayInputStream(imageData) .now i need to save this jpeg frames to my pc and finally convert all these jpeg to a single video file.</p>

<p>following is the code i used in pc i need the code for saving jpeg to pc and convert it into video please help..:_)
cam thread.java
    package carl.pc.udp;</p>

<pre><code>import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.lang.Runnable;
import java.lang.Thread;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;

public class cam_thread_UDP implements Runnable
{
    int nb = 0;
    CAR_GUI car_state;
    Thread t;

    public static int HEADER_SIZE = 5;
    public static int DATAGRAM_MAX_SIZE = 1450;
    public static int DATA_MAX_SIZE = DATAGRAM_MAX_SIZE - HEADER_SIZE;

    public cam_thread_UDP(CAR_GUI gui) 
    {
        car_state = gui;
        try 
        {
            t = new Thread(this);
            t.start();
        } 
        catch (Exception e){e.printStackTrace();}
    }

    public void run() 
    {
        System.out.println("Cam thread waiting...");

        handleConnection_UDP();
    }

    public void handleConnection_UDP() 
    {
        int current_frame = -1;
        int slicesStored = 0;
        byte[] imageData = null;
        DatagramSocket socket=null;

        try 
        {                   
            InetAddress serverAddr = InetAddress.getLocalHost();
            System.out.println("PC IP address: " + serverAddr.getHostAddress());
            socket = new DatagramSocket(9000, serverAddr);
            byte[] buffer = new byte[DATAGRAM_MAX_SIZE];
            DatagramPacket packet = new DatagramPacket(buffer, buffer.length);

            while (true) 
            {               
                socket.receive(packet);             
                byte[] data = packet.getData();         
                int frame_nb = (int)data[0];
                int nb_packets = (int)data[1];
                int packet_nb = (int)data[2];
                int size_packet = (int) ((data[3] &amp; 0xff) &lt;&lt; 8 | (data[4] &amp; 0xff)); 

                if((packet_nb==0) &amp;&amp; (current_frame != frame_nb))
                {
                    current_frame = frame_nb;
                    slicesStored = 0;               
                    imageData = new byte[nb_packets * DATA_MAX_SIZE];
                }

                if(frame_nb == current_frame)
                {
                        System.arraycopy(data, HEADER_SIZE, imageData, packet_nb * DATA_MAX_SIZE, size_packet);
                        slicesStored++;             
                }

                /* If image is complete display it */
                if (slicesStored == nb_packets) 
                {                   
                    ByteArrayInputStream bis = new ByteArrayInputStream(imageData);
                    car_state.set_image(bis);
                }
            }
        } catch (IOException e) 
        {
            e.printStackTrace();
            socket.close();
        } 
    }
}
</code></pre>

<p>CAR_GUI.java</p>

<pre><code>package carl.pc.udp;

import java.io.ByteArrayInputStream;
import java.io.IOException;
import org.newdawn.slick.GameContainer;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.Image;
import org.newdawn.slick.Input;
import org.newdawn.slick.SlickException;
import org.newdawn.slick.UnicodeFont;
import org.newdawn.slick.font.effects.ColorEffect;
import org.newdawn.slick.opengl.Texture;
import org.newdawn.slick.opengl.TextureLoader;
import org.newdawn.slick.state.BasicGameState;
import org.newdawn.slick.state.StateBasedGame;
public class CAR_GUI extends BasicGameState 
{
    public static final int ID = 2;
    /** The font to write the message with */
    UnicodeFont uFont, uFont2;
    /** The image to be display */
    private Image bgc,logo;
    ByteArrayInputStream bis;
    Texture the_texture;

    GameContainer the_container;

    float x_O,y_O,z_O,x_A,y_A,z_A;
    float gas;
    int servo_val = 1500;

    cam_thread_UDP cam_thread;
    sensors_thread_UDP sensors_thread;

    public int getID() {
        return ID;
    }

    @SuppressWarnings("unchecked")
    public void init(GameContainer container, StateBasedGame game) throws SlickException 
    {

        String fontPath = "data-latin.ttf";
        uFont = new UnicodeFont(fontPath , 30, false, false); 
        uFont.addAsciiGlyphs();   
        uFont.addGlyphs(fontPath);
        uFont.getEffects().add(new ColorEffect(java.awt.Color.black)); 
        uFont.loadGlyphs(); 

        uFont2 = new UnicodeFont(fontPath , 25, false, false);
        uFont2.addAsciiGlyphs();   
        uFont2.addGlyphs(fontPath); 
        uFont2.getEffects().add(new ColorEffect(java.awt.Color.red)); 
        uFont2.loadGlyphs();  

        bgc = new Image("bac.png");
        logo = new Image("CARL_Logo.jpg"); 

        cam_thread = new cam_thread_UDP(this);
        sensors_thread = new sensors_thread_UDP(this);
    }

    public void render(GameContainer container, StateBasedGame game, Graphics g) 
    {
        try 
        {
            if(bis != null)
            {
                the_texture = TextureLoader.getTexture("jpeg", bis);
                logo.setRotation(90);                                   
                logo.setTexture(the_texture);
            }
        } catch (IOException e) {e.printStackTrace();}
        g.drawImage(bgc,0,0);
        uFont.drawString(200,110, "Camera");        
        g.drawImage(logo,300-(logo.getWidth()/2),300-(logo.getHeight()/2));
        uFont.drawString(200,550, "Sensors");       
        uFont2.drawString(50,650, "Acceleration" + "\n x: " + x_A + "\n y: " +  y_A + "\n z: " +   z_A);
        uFont2.drawString(300,650, "Orientation" + "\n x: " +  x_O + "\n y: " +  y_O + "\n z: " +  z_O);


    }

    public void set_image(ByteArrayInputStream b)
    {
        bis =b;     
    }

    public void set_sensors_values(float x_O2, float y_O2, float z_O2, float x_A2, float y_A2, float z_A2)
    {
        x_O = x_O2;
        y_O = y_O2;
        z_O = z_O2;
        x_A = x_A2;
        y_A = y_A2;
        z_A = z_A2;
    }


    public void update(GameContainer container, StateBasedGame game, int delta) 
    {   

    }
    public void keyPressed(int key, char c) 
    {
        if (key == Input.KEY_ESCAPE)System.exit(0);
    }
}
</code></pre>
