How can I send a direct video stream to a remote server from my phone!

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)

// 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 was embarrassed for a long time ... thanks in advance

+3
source share
1 answer

ROS

The way to write MediaRecorder files is as follows: Leave space for an empty header Record the contents of the file while recording When you finish recording, find the beginning of the file Write a title at the beginning of the file Then (I guess) there is another search for the end of the file where the metadata is written.

"" , , , , .

- hexeditor 3gpp, . 3gpp.

+4

Source: https://habr.com/ru/post/1782173/


All Articles