How to record video in MPEG-2 TS format and ACC audio coding format

When I set the MPEG-2 video format (constant value 8) TS and the audio format ACC (constant value 3), it only records video without sound in ACC format. But that makes no mistake. I tried this on a Samsung Galaxy Tab (Honeycomb). Since MPEG-2TS supports Android version 3.0+. If I use the default video and audio format, it works great. 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(); 
+6
source share
3 answers

It looks like your problem is with audio encoders. Before Android 2.3.3 (GingerBread) you must install the encoder in AMR_NB. Starting with version 2.3.3, you can also use AMR_WB and AAC as audio codecs.

0
source

mMediaRecorder.setAudioEncodingBitRate (44100): 44100 is not a good audio bitrate. Most likely, the sample rate. 128,000 is most often the bit rate of sound.

Having said that, I also had the problem of recording in m2ts format on the Samsung Galaxy S3 in general.

  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 parameter is actually hidden in the Android 4.2.2 SDK. Therefore, "8" is used. This may be the key to the fact that this format is not supported.

0
source

The solution uses the patch in M2ts Writer . Build libstagefright.so and click on the device. Also below in the app

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

otherwise it will not fully record the clip. I did not explain the reason for setting the above parameters.

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)) { 
0
source

Source: https://habr.com/ru/post/911569/


All Articles