Re: [android-developers] Please help me!!! how to create video file on server side by send onPreviewFrames byte array

2011-11-27 Thread Raghav Sood
Use any one of the numerous methods to send the files to your server (HTTP,
FTP etc). You can use something on the server to combine them into a video.
What you do on the server is not part of the Android SDK, and hence doesn't
belong on the list.

Thansk

On Sun, Nov 27, 2011 at 6:29 PM, muhammad.ume...@hotmail.com 
muhammad.ume...@hotmail.com wrote:

 Hi,
i am able to create images on sd card with onPreviewFrame by
 converting the raw byte array to Yuvimage and then compressing it to
 jpeg format and then write in a file. this work perfectly. but i want
 to send these preview frames to server and recored in a video file.
 please help me, I m stuck here

 thanks and Regards

 umer

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

RE: [android-developers] Please help me!!! how to create video file on server side by send onPreviewFrames byte array

2011-11-27 Thread Muhammad UMER

Hi Raghav,
   Thanks for your reply, I am using the TCP socket to send data to 
my server.i am writing  image files continuously to sd card is perfet. but send 
this to server is not working.
/// 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[280];  
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:36:34 +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

Use any one of the numerous methods to send the files to your server (HTTP, FTP 
etc). You can use something on the server to combine them into a video. What 

Re: [android-developers] Please help me!!! how to create video file on server side by send onPreviewFrames byte array

2011-11-27 Thread Raghav Sood
What do you mean by not working? Are you getting a specific error? What
does the LogCat say? Try adding breakpoints to your code.

Also, in my personal opinion, it would be easier to send the images via
HTTP or FTP.

See this for FTP upload:
http://stackoverflow.com/questions/6464456/how-do-you-upload-images-to-an-ftp-server-within-an-android-app
.

On Sun, Nov 27, 2011 at 10:23 PM, Muhammad UMER muhammad.ume...@hotmail.com
 wrote:

  Hi Raghav,
Thanks for your reply, I am using the TCP socket to send
 data to my server.i am writing  image files continuously to sd card is
 perfet. but send this to server is not working.
 /// 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[280];
  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:36:34 +0530
 Subject: Re: [android-developers] Please help me!!! how to create video
 file on server side by 

RE: [android-developers] Please help me!!! how to create video file on server side by send onPreviewFrames byte array

2011-11-27 Thread Muhammad UMER

working means, server create an image file but when i open it, it will not show 
me an image as I write on sd card and FTP is to send file I don't want to send 
a file, I am sending an onpreviewfram byte array that is in jpeg format to 
server and then save it to image file.

basically my project is to capture video from the android camera and send it to 
TCP socket and server will receive this video in a a file.

thanks

Date: Sun, 27 Nov 2011 22:30:13 +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

What do you mean by not working? Are you getting a specific error? What does 
the LogCat say? Try adding breakpoints to your code.
Also, in my personal opinion, it would be easier to send the images via HTTP or 
FTP.

See this for FTP upload: 
http://stackoverflow.com/questions/6464456/how-do-you-upload-images-to-an-ftp-server-within-an-android-app.


On Sun, Nov 27, 2011 at 10:23 PM, Muhammad UMER muhammad.ume...@hotmail.com 
wrote:






Hi Raghav,
   Thanks for your reply, I am using the TCP socket to send data to 
my server.i am writing  image files continuously to sd card is perfet. but send 
this to server is not working.
/// 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[280];  
how to specify the length in run time 
if (len  0) 

{
dataInputStream.readFully(data);
//dataInputStream.read(data);
System.out.println(message:  + data);

 

Re: [android-developers] Please help me!!! how to create video file on server side by send onPreviewFrames byte array

2011-11-27 Thread Raghav Sood
I didn't quite understand your explanation. From what I get, you are saving
images to the SD Card, and then send those images in a byte array to your
server and want to save it as a video file? From what I have learnt so far
in this world, image files don't arbitrarily convert themselves to video
files. It would be easier for you to record the entire video and then send
it after the recording has finished to the server.

Thanks

On Sun, Nov 27, 2011 at 11:11 PM, Muhammad UMER muhammad.ume...@hotmail.com
 wrote:

  working means, server create an image file but when i open it, it will
 not show me an image as I write on sd card and FTP is to send file I don't
 want to send a file, I am sending an onpreviewfram byte array that is in
 jpeg format to server and then save it to image file.

 basically my project is to capture video from the android camera and send
 it to TCP socket and server will receive this video in a a file.

 thanks

 --
 Date: Sun, 27 Nov 2011 22:30:13 +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

 What do you mean by not working? Are you getting a specific error? What
 does the LogCat say? Try adding breakpoints to your code.

 Also, in my personal opinion, it would be easier to send the images via
 HTTP or FTP.

 See this for FTP upload:
 http://stackoverflow.com/questions/6464456/how-do-you-upload-images-to-an-ftp-server-within-an-android-app
 .

 On Sun, Nov 27, 2011 at 10:23 PM, Muhammad UMER 
 muhammad.ume...@hotmail.com wrote:

  Hi Raghav,
Thanks for your reply, I am using the TCP socket to send
 data to my server.i am writing  image files continuously to sd card is
 perfet. but send this to server is not working.
 /// 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 = 

RE: [android-developers] Please help me!!! how to create video file on server side by send onPreviewFrames byte array

2011-11-27 Thread Muhammad UMER

No, my purpose is not to save to SD Card, My purpose is to capture video from 
android camera and as i captured the video(not complete video, like frames) 
send live to server and server will save it to file.
Is Mediarecorder will help me to do this?

thanks 

Date: Sun, 27 Nov 2011 23:18:10 +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

I didn't quite understand your explanation. From what I get, you are saving 
images to the SD Card, and then send those images in a byte array to your 
server and want to save it as a video file? From what I have learnt so far in 
this world, image files don't arbitrarily convert themselves to video files. It 
would be easier for you to record the entire video and then send it after the 
recording has finished to the server.

Thanks

On Sun, Nov 27, 2011 at 11:11 PM, Muhammad UMER muhammad.ume...@hotmail.com 
wrote:






working means, server create an image file but when i open it, it will not show 
me an image as I write on sd card and FTP is to send file I don't want to send 
a file, I am sending an onpreviewfram byte array that is in jpeg format to 
server and then save it to image file.


basically my project is to capture video from the android camera and send it to 
TCP socket and server will receive this video in a a file.

thanks

Date: Sun, 27 Nov 2011 22:30:13 +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

What do you mean by not working? Are you getting a specific error? What does 
the LogCat say? Try adding breakpoints to your code.

Also, in my personal opinion, it would be easier to send the images via HTTP or 
FTP.

See this for FTP upload: 
http://stackoverflow.com/questions/6464456/how-do-you-upload-images-to-an-ftp-server-within-an-android-app.



On Sun, Nov 27, 2011 at 10:23 PM, Muhammad UMER muhammad.ume...@hotmail.com 
wrote:







Hi Raghav,
   Thanks for your reply, I am using the TCP socket to send data to 
my server.i am writing  image files continuously to sd card is perfet. but send 
this to server is not working.
/// 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 

RE: [android-developers] Please help me!!! how to create video file on server side by send onPreviewFrames byte array

2011-11-27 Thread lbendlin
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


RE: [android-developers] Please help me!!! how to create video file on server side by send onPreviewFrames byte array

2011-11-27 Thread Muhammad UMER

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[280];  
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 

Re: [android-developers] Please help me!!! how to create video file on server side by send onPreviewFrames byte array

2011-11-27 Thread Raghav Sood
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[280];
  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: 

RE: [android-developers] Please help me!!! how to create video file on server side by send onPreviewFrames byte array

2011-11-27 Thread Muhammad UMER

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[28]; // 
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());