I have a problem with streaming my video to the server in real time from my phone. that is, let my phone be an IP camera, and the server can watch live video from my phone.
I have many solutions, but no one can solve my problem. I am using MediaRecorder for recording. It can save the video file on the SD card correctly. then I referenced on this page and used some method as the following
skt = new Socket(InetAddress.getByName(hostname),port);
pfd =ParcelFileDescriptor.fromSocket(skt);
mediaRecorder.setOutputFile(pfd.getFileDescriptor());
Now it seems that I can send the video stream while recording
however, I wrote a program on the receiver side to receive the video stream from Android, but this will not work. is there any mistake I can get the file, but I can not open the video file. I think the problem could be caused by the file format?
there is an outline of my code.
aside android
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();
on the receiver side (my ACER laptop)
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 was embarrassed for a long time ... thanks in advance
source
share