How could I send live video stream to remote server from my phone !!!

Posted by poc on Stack Overflow See other posts from Stack Overflow or by poc
Published on 2010-12-26T14:18:34Z Indexed on 2010/12/28 2:54 UTC
Read the original article Hit count: 298

Filed under:
|
|

Hello , I have a problem about streaming my video to server in real-time from my phone. that is , let my phone be a IP Camera , and server can watch the live video from my phone

I have googled many many solutions, but there is no one can solve my problem. I use MediaRecorder to record . it can save video file in the SD card correctly. then , I refered this page and used some method as followings

 skt = new Socket(InetAddress.getByName(hostname),port);
 pfd =ParcelFileDescriptor.fromSocket(skt);
 mediaRecorder.setOutputFile(pfd.getFileDescriptor());

now it seems I can send the video stream while recording

however, I wrote a receiver-side program to receive the video stream from Android , but it doesn't work . is there any error? I can receive file , but I can not open the video file . I guess the problem may caused by file format ?

there are outline of my code.

in android side

    Socket skt = new Socket(hostIP,port);
ParcelFileDescriptor pfd =ParcelFileDescriptor.fromSocket(skt);
....
....
mediaRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
mediaRecorder.setVideoSource(MediaRecorder.VideoSource.DEFAULT);
mediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
mediaRecorder.setOutputFile(pfd.getFileDescriptor());
.....
mediaRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.DEFAULT);
mediaRecorder.setVideoEncoder(MediaRecorder.VideoEncoder.MPEG_4_SP);
.....
mediaRecorder.start();

in receiver side (my ACER notebook)

// anyway , I don't think the file extentions will do any effect                
File video = new File (strDate+".3gpp");
FileOutputStream fos;
try {
fos = new FileOutputStream(video);

byte[] data = new byte[1024];

int count =-1;

while( (count = fin.read(data,0,1024) ) !=-1)
{
    fos.write(data,0,count);                                
    fos.flush();    
}                                       
fos.close();
fin.close();

I confused a long time.... thanks in advance

© Stack Overflow or respective owner

Related posts about java

Related posts about android