Java – Video streaming in android via parcelFileDescriptor

Video streaming in android via parcelFileDescriptor… here is a solution to the problem.

Video streaming in android via parcelFileDescriptor

I successfully recorded video to SD card via Mediarecorder
But I want to send this video to the server without writing to the SD card.
I searched and found parcelFileDescriptor to be the way to send it
Video to TCP sockets
But I don’t know how to receive it on the server side, please explain.
Here is my client 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 the server side and play it to create a live video transmitter.

Know
“MediaRecorder records in 3GPP or MP4 format. This file format consists of atoms, each of which starts with its size. There are different kinds of atoms in the file and MDAT atoms store the actual raw frames that encode video and audio. In the Cupcake version, Android started writing out an mdat atom in an encoded frame, but for obvious reasons, it had to leave the size of the atom blank. When writing a searchable file descriptor, it can simply fill in the blanks after recording, but of course the socket file descriptor is not searchable. Therefore, the received stream must be repaired after the recording is complete, or the original video/audio frame must be processed by the server. ”

I want a server (maybe Android phone or PC) side code.
Please help me if there is another way…

Thank you

Best Solution

In order to stream from Android or PC, you need to implement a protocol and server for the transport stream. There are several of them, such as HSL, RTPS, etc. (more http://en.wikipedia.org/wiki/Streaming_media). This is not a small issue, there are very few successful streaming services on Android.

You can see how to implement and stream services on Android here: https://github.com/fyhertz/libstreaming

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

Related Problems and Solutions