title: Android - MediaRecorder output to stream for ffmpeg
body: <p>I'm trying to stream the content of my screen to an rtmp server, and I believe the easiest/best way to do that is using ffmpeg.</p>
  
  <p>So, here's what I have so far:</p>
  
  <pre><code>try {
      Socket socket = new Socket(url, port);
      ParcelFileDescriptor fileDescriptor = ParcelFileDescriptor.fromSocket(socket);
  
      mMediaRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
      mMediaRecorder.setVideoSource(MediaRecorder.VideoSource.SURFACE);
      mMediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
      mMediaRecorder.setOutputFile(fileDescriptor.getFileDescriptor());
      mMediaRecorder.setVideoSize(DISPLAY_WIDTH, DISPLAY_HEIGHT);
      mMediaRecorder.setVideoEncoder(MediaRecorder.VideoEncoder.H264);
      mMediaRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
      mMediaRecorder.setVideoEncodingBitRate(512 * 1000);
      mMediaRecorder.setVideoFrameRate(30);
      int rotation = getWindowManager().getDefaultDisplay().getRotation();
      int orientation = ORIENTATIONS.get(rotation + 90);
      mMediaRecorder.setOrientationHint(orientation);
      mMediaRecorder.prepare();
  } catch (IOException e) {
      e.printStackTrace();
  }
  </code></pre>
  
  <p>In here, the important portion is</p>
  
  <pre><code>Socket socket = new Socket(url, port);
  ParcelFileDescriptor fileDescriptor = ParcelFileDescriptor.fromSocket(socket);
  
  mMediaRecorder.setOutputFile(fileDescriptor.getFileDescriptor());
  </code></pre>
  
  <p>So, when I place this inside an Asynctask I can make it attempt to send something, but I get a <code>UnknownHostException</code></p>
  
  <pre><code>java.net.UnknownHostException: Unable to resolve host "rtmps://rtmp-api....": No address associated with hostname
  </code></pre>
  
  <p>So, I've been told that I should use ffmpeg for this instead, but I don't know how to get the original stream from MediaRecorder to pass it to ffmpeg.</p>
  
  <p>If I understand correctly, ffmpeg be used as:</p>
  
  <pre><code>-i original_stream rtmps://rtmp-api...
  </code></pre>
  
  <p>So, how can I get output content of MediaRecorder in a format that I could use in ffmpeg for streaming (not with a saved file).</p>
  
  <p>Thanks!</p>