title: Streaming video from MediaRecorder through LocalSocket
body: <p>I'm trying to send h264/AAC video from Android's MediaRecorder through a local Socket. The goal is to to send video to a WOWZA server throught RTMP or RTSP, but it's giving me a lot of trouble and for now I'm just trying to write the data to a file from the LocalServerSocket. </p>
  
  <p>Here is some code. Sorry it's not really clean, but I spent hours testing many things and my project is a mess right now. </p>
  
  <p>In the Camera activity, the output file setup:</p>
  
  <pre><code>LocalSocket outSocket = new LocalSocket();
  
  try {
      outSocket.connect(new LocalSocketAddress(LOCAL_SOCKET));
  } catch (Exception e) {
      Log.i(LOG_TAG, "Error connecting socket: "+e);
  }
  mMediaRecorder.setOutputFile(outSocket.getFileDescriptor());
  </code></pre>
  
  <p>The LocalServerSocket implementation:</p>
  
  <pre><code>try {
      mLocalServerSocket = new LocalServerSocket(mName);
  } catch (Exception e) {
      Log.e(LOG_TAG, "Error creating server socket: "+e);
      return;
  }
  
  while (true) {
  
      File out = null;
      FileOutputStream fop = null;
      try {
          mLocalClientSocket = mLocalServerSocket.accept();
  
          InputStream in = mLocalClientSocket.getInputStream();
  
          out = new File(mContext.getExternalFilesDir(null), "testfile.mp4");
          fop = new FileOutputStream(out);
  
          int len = 0;
          byte[] buffer = new byte[1024];
          while ((len = in.read(buffer)) &gt;= 0) {
  
              Log.i(LOG_TAG, "Writing "+len+" bytes");
              fop.write(buffer, 0, len);
          }
      } catch (Exception e) {
          e.printStackTrace();
      }
      finally{
          try {
              fop.close();
              mLocalClientSocket.close();
          } catch (Exception e2) {}
      }
  }
  </code></pre>
  
  <p>The problem is that the file resulting from this is not readable by any media player. Do you think this is because of an encoding issue? This code should generate a binary file if I understand well?!</p>
  
  <p>Thanks in advance, cheers.</p>