Thanks for your reply.First,is it good way to create a video(Mjpeg) from jpeg 
images? Secondly, In my code i compress camera onpreviewframe byte array to 
jpeg format and its perfect but when i send this compressed byte array to 
server through TCP socket and server save it in a file, but not in correct 
format.
 
 
/////// Here is  my client side code
 public void onPreviewFrame(byte[] data, Camera camera) {  // <11>
            
            Camera.Parameters parameters = camera.getParameters();
            int format = parameters.getPreviewFormat();

             //YUV formats require more conversion
            if (format == ImageFormat.NV21 /*|| format == ImageFormat.YUY2 || 
format == ImageFormat.NV16*/)
            {
                int w = parameters.getPreviewSize().width;
                int h = parameters.getPreviewSize().height;
                // Get the YuV image
                YuvImage yuv_image = new YuvImage(data, format, w, h, null);
                // Convert YuV to Jpeg
                Rect rect = new Rect(0, 0, w, h);
                ByteArrayOutputStream output_stream = new 
ByteArrayOutputStream();
                yuv_image.compressToJpeg(rect, 100, output_stream);
                byte[] byt=output_stream.toByteArray();
                
                FileOutputStream outStream = null;
                try {
                     /////// this work perfect for sd card
                    //outStream = new FileOutputStream(String.format(
                    //        "/sdcard/%d.jpg", System.currentTimeMillis()));
                    //outStream.write(byt);
                    //outStream.close();

                    // this method write byte array to socket
                    sendBytes(byt, 0, byt.length);
                    Log.d(TAG, "onPreviewFrame - wrote bytes: "
                            + data.length);
                } catch (FileNotFoundException e) {
                    e.printStackTrace();
                } catch (IOException e) {
                    e.printStackTrace();
                } finally {
                }
                Preview.this.invalidate();
                // Convert from Jpeg to Bitmap
                //bmap = 
BitmapFactory.decodeByteArray(output_stream.toByteArray(), 0, 
output_stream.size());
            }
//////////            sending byte array to server
    public void sendBytes(byte[] myByteArray, int start, int len) throws 
IOException {
        if (len < 0)
            throw new IllegalArgumentException("Negative length not allowed");
        if (start < 0 || start >= myByteArray.length)
            throw new IndexOutOfBoundsException("Out of bounds: " + start);
        // Other checks if needed.

        // May be better to save the streams in the support class;
        // just like the socket variable.
        
        DataOutputStream dos = new DataOutputStream(socket.getOutputStream());
        //BufferedOutputStream imagebos = new BufferedOutputStream(dos);  
         
       dos.writeInt(len);
        if (len > 0) {
               /// this will write to socket
            imagebos.write(myByteArray, start, len);
            
            
        }
    }
    


//////    here is server side code  /////////


 while(dataInputStream.readInt() > 0 )
        {
           //// reading from client
                                       
                                       
                                   ////read from client in byte array 
           
                                    int len = dataInputStream.readInt();
                                    byte[] data = new byte[2800000];     //// 
how to specify the length in run time 
                                    if (len > 0) 
                                    {
                                        dataInputStream.readFully(data);
                                        //dataInputStream.read(data);    
                                        System.out.println("message: " + data);
                                    }
                                    
                //// write this data array on a file

                FileOutputStream fos = new FileOutputStream("image.jpg", true);
                ObjectOutputStream out = new ObjectOutputStream(fos);
                                                    
                out.write(data);
                out.flush();
                out.close();
                fos.close();          
                 
        }

the server side code is correct or not but the file is not in correct formate, 
please tell me if i am doing wrong. Also tell me is it correct method to 
combine the images file to create a video?
Please correct me if i m doing wrong


Thanks 
umer

 

> Date: Sun, 27 Nov 2011 18:46:03 -0800
> From: l...@bendlin.us
> To: android-developers@googlegroups.com
> Subject: RE: [android-developers] Please help me!!! how to create video file 
> on server side by send onPreviewFrames byte array
> 
> It might be overly ambitious to send uncompressed frames to the server. You 
> can compress them to Jpeg in memory and send these to the server via whatever 
> method. On the server concatenate the files to a MJpeg stream.
> 
> -- 
> You received this message because you are subscribed to the Google
> Groups "Android Developers" group.
> To post to this group, send email to android-developers@googlegroups.com
> To unsubscribe from this group, send email to
> android-developers+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/android-developers?hl=en
                                          

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to