简体   繁体   中英

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

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

Poc,

The way MediaRecorder writes files is as follows: Leave space for empty header Write file contents while recording When recording finishes, seek to the beginning of file Write the header at the beginning of the file Then (I believe) there is another seek to the end of the file where metadata is written.

Because there is no concept of "seeking" on a socket, you will have to figure out when the header comes, seek to the beginning of your file, and then write the header in the appropriate location.

The best place to start here is to use a hexeditor to determine the format of a valid 3gpp file, then analyze this hex against your receiver program's hex output. Also you will want to look into 3gpp file formats.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM