Android Media Recorder: getting 3GP instead of MPEG4

I want to record video only in android with MPEG4 format. I want the container and codec to be MPEG4. So here is what I did for this.

Thread video = new Thread(new Runnable() { public void run() { videoRecorder = new MediaRecorder(); videoRecorder.setPreviewDisplay(surfaceView.getHolder().getSurface()); videoRecorder.setVideoSource(MediaRecorder.VideoSource.DEFAULT); videoRecorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4); videoRecorder.setVideoEncodingBitRate(56 * 8 * 1024); videoRecorder.setVideoSize(176, 144); videoRecorder.setVideoFrameRate(12); videoRecorder.setVideoEncoder(MediaRecorder.VideoEncoder.MPEG_4_SP); videoRecorder.setOutputFile("/sdcard/video.m4e"); try { videoRecorder.prepare(); } catch (IllegalStateException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } videoRecorder.start(); } }); video.start(); 

Now, after recording, I got the video recorded in the video.m4e file. But when I check his information, I got the following:

enter image description here

At the same time, I used the following to record sound:

 Thread audio = new Thread(new Runnable() { public void run() { audioRecorder = new MediaRecorder(); audioRecorder.setAudioSource(MediaRecorder.AudioSource.MIC); audioRecorder.setOutputFormat(MediaRecorder.OutputFormat.RAW_AMR); audioRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB); audioRecorder.setOutputFile("/sdcard/audio.amr"); try { audioRecorder.prepare(); } catch (IllegalStateException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } audioRecorder.start(); } }); audio.start(); 

and I got the container format and codec as AMR, as I assumed:

enter image description here

So what makes MediaRecorder record video in 3GP format? I did not specify 3GP anywhere in my program. I am testing this code on a Samsung Galaxy tab running Android 2.2

+1
source share
3 answers

MPEG-4 is a method for determining the compression of audio and visual (AV) digital data.

File format for storing media content based on time. This is a common format that forms the basis for a number of other more specific file formats (for example, 3GP, Motion JPEG 2000, MPEG-4 Part 14).

Thus, there is no conspiracy as a result of what you got, the compression method (OR "Codec") that you used was MPEG4, and the video format generated by your phone is 3gp, which is actually part of the video formats of the MPEG4 compression scheme set for carrier.

+6
source

This is determined by wireframes. In particular, it has a set of parameters that are in the MediaRecorder class that determine that everything is supported.

0
source

I do not understand the explanation of akkilis.

In the official Android tutorial "MediaRecorder.OutputFormat" , MPEG_4 is one of the options for "media formats," in parallel with THREE_GPP. int AAC_ADTS File format AAC ADTS int AMR_NB File format AMR NB int AMR_WB File format AMR WB int DEFAULT
int MPEG_4 MPEG4 media file format int RAW_AMR This constant was deprecated at API level 16. Deprecated in favor of MediaRecorder.OutputFormat.AMR_NB int THREE_GPP 3GPP media file format

There is another parameter for specifying the encoding format: "MediaRecorder.VideoEncoder"

int DEFAULT
int H263
int H264
int MPEG_4_SP

In the OP code, he specified both the file format and the encoding format.

videoRecorder.setOutputFormat (MediaRecorder.OutputFormat.MPEG_4); videoRecorder.setVideoEncoder (MediaRecorder.VideoEncoder.MPEG_4_SP);

So, it seems that the explanation of akkilis is not suitable for this example.

0
source

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


All Articles