5

I am succeed to record video through Mediarecorder on SD card but i want to send this video to a server without writing to SD card. I search it and i found the parcelFileDescriptor is the way to send video to TCP socket but i don't know how to receive it on server side please explain it. here is my client side code

socket = new Socket("hostname", portnumber);
ParcelFileDescriptor  pfd =ParcelFileDescriptor.fromSocket(socket);
            recorder = new MediaRecorder();
            recorder.setVideoSource(MediaRecorder.VideoSource.DEFAULT);
            recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
            recorder.setOutputFile(pfd.getFileDescriptor());
            recorder.setVideoEncoder(MediaRecorder.VideoEncoder.MPEG_4_SP);
            mPreview = new Preview(VideoRecorder.this,recorder);

setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
            setContentView(mPreview);

I want to receive it on server side and play it to create areal time video transer.

knowing that "The MediaRecorder records either in 3GPP or in MP4 format. This file format consists of atoms, where each atom starts with its size. There are different kinds of atoms in a file, mdat atoms store the actual raw frames of the encoded video and audio. In the Cupcake version Android starts writing out an mdat atom with the encoded frames, but it has to leave the size of the atom empty for obvious reasons. When writing to a seekable file descriptor, it can simply fill in the blanks after the recording, but of course socket file descriptors are not seekable. So the received stream will have to be fixed up after the recording is finished, or the raw video / audio frames have to be processed by the server".

I want a server(may be Android handset or PC) side code. if there is another way please help me......

Thanks

1 Answers1

2

In order to stream from android or pc you need to implement protocol over which the stream is carried over and server. There are several of them like HSL, RTPS etc (more http://en.wikipedia.org/wiki/Streaming_media). It is not a trivial problem, and there are only very few successful streaming service from android.

You can check how to implement and steaming service on android here: https://github.com/fyhertz/libstreaming

The library is broken for Android 5, but works for 4.4.x

Califlower
  • 467
  • 4
  • 15
  • 1
    An author of this library wrote that he had found a trick to make it work in Android 5. – CoolMind Jun 24 '15 at 17:09
  • can you could you give a link to that? I looked at GitHub and there is only a comment about attempt for Lolipop support. Not clear if it is working properly or not. – Califlower Jul 01 '15 at 15:45
  • a link from that GitHub (http://stackoverflow.com/questions/26990816/mediarecorder-issue-on-android-lollipop). It's said: "as of Android Lollipop using a LocalSocket is not possible anymore for security reasons. But using a ParcelFileDescriptor does the trick. More details in the file MediaStream.java". – CoolMind Jul 01 '15 at 15:52