6

When I set video format MPEG-2(Constant value 8) TS and audio format ACC(Constant value 3) it records video only without audio in ACC format. But it doesn't give any error. I tried it on Samsung Galaxy Tab(Honeycomb). Because MPEG-2TS supports on android version 3.0+. If I use default video and audio format it works fine. How can I do this. Please help.

if(mCamera == null) {
    mCamera = Camera.open();
    mCamera.unlock();
}


if(mMediaRecorder == null) mMediaRecorder = new MediaRecorder();

mMediaRecorder.setPreviewDisplay(surface);
mMediaRecorder.setCamera(mCamera);
mMediaRecorder.setAudioSource(MediaRecorder.AudioSource.DEFAULT);
mMediaRecorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);   
mMediaRecorder.setOutputFormat(8);
mMediaRecorder.setOutputFile("/mnt/sdcard/temp.ts");
mMediaRecorder.setVideoEncoder(MediaRecorder.VideoEncoder.H264);
mMediaRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AAC);
mMediaRecorder.setVideoSize(640, 480);

mMediaRecorder.setVideoEncodingBitRate(500000);
mMediaRecorder.setAudioEncodingBitRate(44100);
mMediaRecorder.setVideoFrameRate(30);
mMediaRecorder.setMaxDuration(-1);   
mMediaRecorder.prepare();
Suvam Roy
  • 1,282
  • 2
  • 11
  • 21
  • How are you checking it has no audio? Are you demuxing the .TS file? – freeone3000 Apr 24 '12 at 23:57
  • When I'm using all default format, I'm getting audio. But when I set this format, I don't get any audio. – Suvam Roy Apr 25 '12 at 05:23
  • Hi @SuvamRoy. I tried your code but with mMediaRecorder.setOutputFormat(8); option i am not able to save the file. Nothing records not even video. I am using android 4.1.2. Have you got any success?? – sachy Jun 13 '13 at 10:08
  • I am facing same issue. I tried using modified audioloop commandline app. Using this app when AACWriter is used to encode audio, it produces output correctly, but when I try MPEG2TSWriter, there is no output. I believe that AAC encoder is not a problem but MPEG2TS muxer when used with AAC audio or AMR audio is a problem. – Nishit Jain Sep 02 '13 at 11:18

3 Answers3

0

Looks like your problem is associated with Audio encoders. Prior to Android 2.3.3(GingerBread) you must set the encoder to AMR_NB. As of 2.3.3 you can also use AMR_WB and AAC as audio codecs.

Gaurav Agarwal
  • 18,754
  • 29
  • 105
  • 166
  • 1
    you don't get my requirement. It is unable to mux audio and video in mpeg2ts and aac. – Suvam Roy Apr 21 '12 at 18:20
  • Actually I requirement is that I want to record video in MERG-2TS output format, and for this format only ACC audio encoder supports according android developer guide. So, that I'm able to record video in that format without audio. If I change my audio encoder, it gives exception. If I use all default video and audio encoder, it is able to record video and audio. – Suvam Roy Apr 22 '12 at 06:20
0

mMediaRecorder.setAudioEncodingBitRate(44100): 44100 is not a good audio bit rate. It is more likely a sample rate. 128000 is more commonly an audio bit rate.

Having said that, I am also having trouble recording to m2ts format on the Samsung Galaxy S3 at all.

    mediaRecorder = new MediaRecorder();
    mediaRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
    mediaRecorder.setOutputFormat(/*MediaRecorder.OutputFormat.OUTPUT_FORMAT_MPEG2TS*/8);
    mediaRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AAC);
    mediaRecorder.setAudioSamplingRate(48000);
    mediaRecorder.setAudioEncodingBitRate(128000);

The OutputFormat.OUTPUT_FORMAT_MPEG2TS option is actually hidden in the Android 4.2.2 SDK. Hence teh use of the '8'. This may be a clue that this format is not really supported.

Jerry F
  • 449
  • 6
  • 8
0

The solution is applying a patch in M2ts Writer. Build libstagefright.so and push to device. Also set below in application

recorder.setAudioSamplingRate(48000); 
recorder.setAudioEncodingBitRate(128000);

or else it will not record the clip completely. I did not dig into the reason for setting the above parameters though.

Patch for M2tsWriter in libstagefright:

diff --git a/media/libstagefright/MPEG2TSWriter.cpp b/media/libstagefright/MPEG2TSWriter.cpp

index c9ed5bb..a42371f 100644

--- a/media/libstagefright/MPEG2TSWriter.cpp

+++ b/media/libstagefright/MPEG2TSWriter.cpp

@@ -411,6 +411,7 @@ void MPEG2TSWriter::SourceInfo::onMessageReceived(const sp<AMessage> &msg) { 
                            (const uint8_t *)buffer->data() 
                             + buffer->range_offset(), 
                            buffer->range_length()); 
+                    readMore(); 
                 } else if (buffer->range_length() > 0) {
                     if (mStreamType == 0x0f) { 
                         if (!appendAACFrames(buffer)) { 
sdh
  • 53
  • 1
  • 8