2

Hey I'm trying to develop screencast app which would record the contents of the screen as well as microphone input. I was able to implement the video recording but I can't find anything about adding microphone input to mediaMuxer. I know I could use mediarecorder class but how then could i add the mediarecorder to muxer? I've found this bits of code so far.

 MediaFormat audioFormat = new MediaFormat(...);
 int audioTrackIndex = muxer.addTrack(audioFormat);

While I could add an audioFormat to the muxer I'm not sure how could I add the microphone input to the muxer. Could someone point me in the right direction or provide some sort of sample code?

John Smith
  • 844
  • 8
  • 26
  • One possible approach: just use MediaRecorder. As of API 21 you can get an input Surface from a MediaRecorder and send the video to that -- you're not limited to Camera input anymore. – fadden Oct 17 '15 at 15:56
  • I could do just that but I want to stick with mediaMuxer as it's a bit more flexible than mediaRecorder. – John Smith Oct 17 '15 at 16:07

1 Answers1

0

Media recorder is much better alternate than media muxer for taking input from MIC while recording the screen

mMediaRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
        mMediaRecorder.setVideoSource(MediaRecorder.VideoSource.SURFACE);
        mMediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
        mMediaRecorder.setVideoEncoder(MediaRecorder.VideoEncoder.H264);
        mMediaRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
        mMediaRecorder.setVideoEncodingBitRate(512 * 1000);
        mMediaRecorder.setVideoFrameRate(30);
        mMediaRecorder.setVideoSize(DISPLAY_WIDTH, DISPLAY_HEIGHT);
        mMediaRecorder.setOutputFile("/sdcard/capture.mp4");

here is the full code.

Mohammed Atif
  • 4,383
  • 7
  • 28
  • 57
  • I wouldn't say "much better". `MediaRecorder` gives you less control compared to `MediaMuxer`, although it is simpler to use, and is enough for most use cases – Louis CAD Jan 22 '18 at 13:57