correct format means, a jpeg file is created but it will not show the image 
what's the reason? i think the problem is in the creation of byte array?
 
///here is my server side code
 
 while(dataInputStream.readInt() > 0 )
        {
           //// reading from client
                                       
                                       
                                   ////read from client in byte array 
           
                                    int len = dataInputStream.readInt();
                                    byte[] data = new byte[280000];     ////// 
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();          
                 
        }

 
thanks
 



Date: Mon, 28 Nov 2011 12:49:36 +0530
Subject: Re: [android-developers] Please help me!!! how to create video file on 
server side by send onPreviewFrames byte array
From: raghavs...@androidactivist.org
To: android-developers@googlegroups.com

If you are sure that what you are sending from the device is fine, then I'd 
imagine that whatever server side system you are using to save the files isn't 
doing it the correct way. What do you mean by correct format? Does it get saved 
only partially? Or is it just a mixed up bunch of data?


Thanks


On Mon, Nov 28, 2011 at 12:44 PM, Muhammad UMER <muhammad.ume...@hotmail.com> 
wrote:



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


-- 
Raghav Sood
http://www.androidactivist.org/ - Author
http://www.appaholics.in/ - Founder

-- 
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