I am trying to record camcorder recordings to a network stream, see the following snippet:
ParcelFileDescriptor fd = ParcelFileDescriptor.fromSocket(socket); this.camera.lock(); // this.camera refers to an android.hardware.Camera instance. this.camera.unlock(); this.mediaRecorder = new MediaRecorder(); this.mediaRecorder.setCamera(this.camera); this.mediaRecorder.setAudioSource(MediaRecorder.AudioSource.MIC); this.mediaRecorder.setVideoSource(MediaRecorder.VideoSource.CAMERA); this.mediaRecorder.setProfile(CamcorderProfile.get(0, CamcorderProfile.QUALITY_HIGH)); this.mediaRecorder.setOutputFile(fd.getFileDescriptor()); this.mediaRecorder.prepare(); this.mediaRecorder.start();
Then I try to capture it on the other side of the connection: with Socket.getInputStream() I read the bytes, and yes, the bytes come in. The byte is actually written over the network.
But when you try to save it to a file using the FileOutputStream class and open the file using VLC, it is simply impossible to read.
How can I end up making the file “playable”, which means it's a valid video file?
Edit:
When I use this.mediaRecorder.setOutputFile("/sdcard/out.mp4"); , I can open the video file from Android, and it will play successfully. However, when I use this.mediaRecorder.setOutputFile(fd.getFileDescriptor()); , he will not.
source share