I am facing a problem recording a video with MediaRecorder. I need to register a video in H264 and save it in a 3gp container with extension mp4. I absolutely need this video format, because then I will open it with a native library that I can't directly modify for my own. I am using the following code, that normally works well. But with another tablet, the video is taken, but the format isn't the same (and the native library stops to work).
Inspecting the video proprieties I saw that the second video has a container "Quicktime" instead of "3gp":
And analysing the video's bytes, I found that the header isn't the 3gp's one.
What's wrong in the code?
recorder = new MediaRecorder();
recorder.setCamera(camera);
recorder.setAudioSource(MediaRecorder.AudioSource.CAMCORDER);
recorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);
recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
recorder.setVideoSize(320, 240);
recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
recorder.setVideoEncoder(MediaRecorder.VideoEncoder.H264);
recordingPath = getApplicationContext().getFilesDir().getAbsolutePath()
+ "/" + System.currentMillis();
recorder.setOutputFile(recordingPath + ".mp4");
recorder.setMaxDuration(50000); // 50 seconds
recorder.setMaxFileSize(5000000); // Approximately 5 megabytes
recorder.setPreviewDisplay(recPreview.getHolder().getSurface());
try {
recorder.prepare();
} catch (IllegalStateException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
recorder.start();
it seems like the recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP); doesn't take effect
Thanks, Nico
Related
so from my understanding is that the mediarecorder saves audio samples and binds them with a timeStamp to be able to seek through the audio file later (by the help of a prgressbar):
recorder = new MediaRecorder();
recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
recorder.setOutputFile(fileName);
recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
try {
recorder.prepare();
} catch (IOException e) {
Log.e(LOG_TAG, "prepare() failed");
}
recorder.start();
My question
Is there any way to get these timestamps of audio samples real time while recording a voice?
please I need your help.
I am going to create a program that recording voice call but MediaRecorder.AudioSource.VOICE_CALL does not work. I think its not support on many phones.
I'm trying with MediaRecorder.AudioSource.MIC but it just records and upload voice. In another word record my voice on microphone!!!
And I'm trying with MediaRecorder.AudioSource.VOICE_COMMUNICATION but it has a bad sound.
Here is my sample code:
recorder = new MediaRecorder();
recorder.reset();
recorder.setAudioSource(MediaRecorder.AudioSource.VOICE_CALL);
recorder.setOutputFormat(MediaRecorder.OutputFormat.AMR_NB);
recorder.setOutputFile(mFileName);
recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
try {
recorder.prepare();
} catch (IOException e) {
Log.e("LOG", "prepare() failed");
}
recorder.start();
Please help me. Thank you.
Iam trying to develop an android based camera application which requires recording videos on live camera preview with overlay images. Is there any way on android using which we can record videos with overlay images without using any third party library .
Currently iam using an additional Surfaceview as an overlay on live camera screen and MediaRecorder class for recording videos.Here is my code :
recorder = new MediaRecorder();
recorder.setCamera(mCam);
String filename="";
String path="";
path= Environment.getExternalStorageDirectory().getAbsolutePath().toString();
Date date=new Date();
filename="/rec"+date.toString().replace(" ", "_").replace(":", "_")+".mp4";
File file=new File(path,filename);
recorder.setAudioSource(MediaRecorder.AudioSource.CAMCORDER);
recorder.setVideoSource(MediaRecorder.VideoSource.SURFACE);
recorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
recorder.setVideoSize(mPreviewSize.width, mPreviewSize.height);
recorder.setVideoEncodingBitRate(10000000);
recorder.setVideoFrameRate(30);
try {
recorder.prepare();
} catch (IllegalStateException e) {
releaseMediaRecorder();
return false;
} catch (IOException e) {
releaseMediaRecorder();
return false;
}
The above code crashes the application during the start of recording process.
Is there any other way in OpenGL ES 2.0 apart from MediaRecorder for recording videos with overlay.
Please advice.
I am trying to add effect in audio, I have recorded audio using MediaRecorder and added effects using SoundPool class now I am trying to save the effected sound but I found that sound i can't store a sound using SoundPool. Can any one please give a way to move on I am posting my code that records the sound and play it ...
Thanks in advance
mediaRecorder = new MediaRecorder();
mediaRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
mediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
mediaRecorder.setAudioEncoder(MediaRecorder.OutputFormat.AMR_NB);
mediaRecorder.setOutputFile(getFilePath() + getFilename());
try {
mediaRecorder.prepare();
mediaRecorder.start();
setFlagRecording(true);
} catch (IllegalStateException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
and to play sound
soundPool.play(getStreamID(), 1, 1, 0, 0, getFrequency());
I have an app that encodes in amr_nb format and output the file in amr. I want the recorded file to be broken into a series of amr files of 2 KB each. Got no clue on how to achieve this.
Here is the function called upon clicking Record Button
private void startRecording() {
recorder = new MediaRecorder();
recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
recorder.setOutputFormat(MediaRecorder.OutputFormat.AMR_NB);
recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
recorder.setOutputFile(getFilename());
recorder.setOnErrorListener(errorListener);
recorder.setOnInfoListener(infoListener);
try {
recorder.prepare();
recorder.start();
} catch (IllegalStateException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
Here is the method called upon clicking Stop Button,
private void stopRecording() {
if (null != recorder) {
recorder.stop();
recorder.reset();
recorder.release();
recorder = null;
}
}
http://developer.android.com/reference/android/media/MediaRecorder.html#setMaxFileSize(long)
Then register your listener to MediaRecorder that gets a callback when the max file size is reached, then set up MediaRecorder to record the next file. Be aware there's a (good?) chance this will not produce a series of gapless files.