Search code examples
androidaudioaudio-recording

Parallel using of MediaRecorder.AudioSource.CAMCORDER


I have some strange problem, and can't find answer. I using wowza to make live streaming. It use inside AudioRecord recorder = new AudioRecord(this.mAudioSource, ... ), and mAudioSource by default = 5 (like MediaRecorder.AudioSource.CAMCORDER) it works good, but in same time i need to record this video with audio inside device memory with more video quality.

For inner record I use the MediaRecorder.

        mWZCameraView.getCamera().getPlatformDevice().unlock();

        mMediaRecorder = new MediaRecorder();
        mMediaRecorder.setCamera(mWZCameraView.getCamera().getPlatformDevice());

        //mMediaRecorder.setAudioSource(MediaRecorder.AudioSource.CAMCORDER);
        mMediaRecorder.setVideoSource(MediaRecorder.VideoSource.DEFAULT);

        mMediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);

        //mMediaRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
        mMediaRecorder.setVideoEncoder(MediaRecorder.VideoEncoder.H264);

        mMediaRecorder.setVideoEncodingBitRate(15000000);
        mMediaRecorder.setVideoFrameRate(30);
        mMediaRecorder.setVideoSize(1920, 1080);

        try {
            mMediaRecorder.prepare();
        } catch (Exception e) {
            // This is thrown if the previous calls are not called with the
            // proper order
            e.printStackTrace();
        } finally {
            mMediaRecorder.start();
        }

As you can see setAudioSource in comment, in this case live video get the audio and video on device wont get audio. If open setAudioSource & setAudioEncoder my live video will be without audio record and on device with audio.

I tried different combinations of AudioSource and AudioEncoder but it always make audio record in one of the video.

I can't find the answer, if it possible to use CAMCORDER in parallel.

PS. I know about the option to record audio via bytes in another file and merge it after, but it not so easy and i will try it in case last option.


Solution

  • It seems that I found the answer, maybe it will helps to somebody. The write answer here: https://stackoverflow.com/a/12935309/7917629, "Android devices are based on limit the number of open audio input streams to 1".

    Wowza used inside the audioRecorder to get audio, an it looks like when i add to mediaRecorder setAudioSource it try to use audioRecorder too. So the option set callback to wowza like mWZAudioDevice.registerAudioSampleListener(new WZAudioDevice.AudioSampleListener()) to get byte[] from audioRecord.