android - how to save images as jpeg and convert it into a single video file in java -
am having java application in pc , android application in phone. phone sends video frames in jpeg format using bytearrayoutputstream pc,the pc recieve using bytearrayinputstream(imagedata) .now need save jpeg frames pc , convert these jpeg single video file.
following code used in pc need code saving jpeg pc , convert video please help..:_) cam thread.java package carl.pc.udp;
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] & 0xff) << 8 | (data[4] & 0xff)); if((packet_nb==0) && (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 complete display */ if (slicesstored == nb_packets) { bytearrayinputstream bis = new bytearrayinputstream(imagedata); car_state.set_image(bis); } } } catch (ioexception e) { e.printstacktrace(); socket.close(); } } }
car_gui.java
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; /** font write message */ unicodefont ufont, ufont2; /** image 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); } }
Comments
Post a Comment