Android camera2 mediarecorder.setvideoencodingbitrate galaxy s6 - android

I have found that setvideoencodingbitrate(800000) works for most of the devices I am using but on the Samsung Galaxy S6 it seems to record at 1.3 MBs rather than 800 kbs as set.
I am assuming this is because the device doesnt support that bit rate (I could be wrong)
Is there a way of getting an android devices supported videoencoding bitrates? or at least seeing what the MediaRecorder has been set to after calling on prepare? I cant seem to find any kind of mediaRecorder.getvideoencodingbitrate call?
Code below.
mediaRecorder.setVideoEncodingBitRate(500000); //500000 works with galaxy s6
mediaRecorder.setVideoEncoder(MediaRecorder.VideoEncoder.H264);
mediaRecorder.setVideoFrameRate(mCaptureProfile.framesPerSecond);
// Audio Settings
mediaRecorder.setAudioChannels(mCaptureProfile.audioNumChannels);
mediaRecorder.setAudioSamplingRate(mCaptureProfile.audioSampleRate);
mediaRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AAC);
mediaRecorder.setAudioEncodingBitRate(mCaptureProfile.audioBitRate);
mediaRecorder.prepare();

In general, it's recommended you use CamcorderProfile to select the encoding settings, including bitrate, when recording video with a MediaRecorder. Select the profile with the resolution you want (for the camera you want), and then set it on the media recorder with MediaRecorder.setProfile.
This allows the device vendor to set the recommended bitrate, which may vary greatly between devices, due to different hardware encoders, supported parts of the video recording specs, and so on.
To look at the actual supported bitrates, that may be available somewhere in MediaCodecInfo.

Related

Find the MediaCodec supported video encoding resolutions under Jelly Bean MR2

Is there any way to get the MediaCodec video encoding supported resolutions under Jelly Bean MR2?
For lollipop we can use the new getVideoCapabilities() method to find out all the supported video resolutions. But for lower API levels couldn't find a way in the MediaCodec API.
I'm aware of the CamcorderProfile class available since API 8 which can give some hints of what the hardware might support, but to use the camcorder profiles to resolve the encoder video resolutions seems to be a guess game without consistency which could fail easily on many devices.
If it's listed in the CDD then you can assume it. If not, you have to try and see if it works.
The screenrecord tool uses a retry-on-error scheme to deal with cases where the video encoder can't record at the display resolution, because there was no way to query for it back then.

Experiencing Android Audio Stuttering during Screen Lock/Wake

I'm working on an Android app centered around audio playback and I'm experiencing some erratic behavior (audio stuttering and hiccups) that I suspect might be inherent to certain devices, OS versions or perhaps the native buffer size of the device.
About my implementation - I'm in need of low latency so I'm processing my audio in OpenSL ES callbacks and using a fairly small buffer size of 128 samples to enqueue the buffers. I am doing mp3 decoding during the callback, but with my ring buffer size, I do not need to decode during every callback cycle.
I'm using a remote testing service to gauge audio playback quality on a variety of devices and OS versions and here's a few examples of the inconsistencies I'm finding.
Samsung Galaxy S4 w/ Android 4.4 - no audio playback issues
Samsung Galaxy S4 w/ Android 4.3 - user experiences audio drop-outs/stuttering when locking/un-locking the device
Samsung Galaxy Note 2 w/ Android 4.1.2 - no issues
Samsung Galaxy Note 2 w/ Android 4.3 - audio drop-outs during playback and stuttering when locking/unlocking screen.
Personally, I have a Galaxy S3 w/ 4.1.2 and a Nexus 5 with 4.4 and don't ever experience these issues. I also have a few older 2.3.7 devices where these issues do not occur (2010 Droid Incredible, LG Optimus Elite).
I am fairly confident that I'm not over-working the processor since I can get this running on older, Gingerbread devices just fine.
My questions:
If I raise my base SDK to 4.2, I can detect native buffer size from the hardware and use some multiple of this during my buffer queue callbacks. Would this make much of a difference in cases where stuttering and drop-outs are problematic especially during screen lock?
Is there a known bug with Android 4.3 where audio playback suffers,
especially during screen lock actions? Is this possibly just a Samsung issue?
Are there other ways of improving performance to avoid this problem? I absolutely need OpenSL ES for my app.
Thanks.
Increasing buffer size solves some problems regarding distortion and noise. Yes, you can detect native buffer size from the hardware when your SDK is above 4.2 with this:
String size = audioManager.getProperty(AudioManager.PROPERTY_OUTPUT_FRAMES_PER_BUFFER);
But yet another approach to get the minimum buffer size for Audio Record is:
int minForAudioRecord = AudioRecord.getMinBufferSize(8000,
AudioFormat.CHANNEL_IN_MONO,
AudioFormat.ENCODING_PCM_16BIT);
And for Audio Playback:
int minForAudioTrack = AudioTrack.getMinBufferSize(8000,
AudioFormat.CHANNEL_OUT_MONO,
AudioFormat.ENCODING_PCM_16BIT);
If your SDK version is greater than or equal to 4.2, then you can have preferred sample rate for your audio.
String rate = audioManager.getProperty(AudioManager.PROPERTY_OUTPUT_SAMPLE_RATE);
I've found samsung devices are the worst while dealing with these things because each device has different approach to deal with audio drivers.

Android recorded video play on samsung device but blur on Htc device

I created video on android that properties is :
mRecorder.setAudioSource(MediaRecorder.AudioSource.DEFAULT);
mRecorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);
mRecorder.setOutputFormat(MediaRecorder.OutputFormat.DEFAULT);
mRecorder.setVideoSize(640, 480);
mRecorder.setVideoFrameRate(24);
mRecorder.setVideoEncodingBitRate(3000000);
mRecorder.setAudioEncodingBitRate(8000);
mRecorder.setVideoEncoder(MediaRecorder.VideoEncoder.DEFAULT);
mRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
mRecorder.setMaxDuration((int) (maxDuration));
mRecorder.setPreviewDisplay(mHolder.getSurface());
mRecorder.setOutputFile(mOutputFileName);
mRecorder.setOrientationHint(90);
but this video create and play both on samsung device properly but htc device shows blur video.
You have set MediaRecorder.VideoEncoder.DEFAULT so every smartphone will choose its default video codec to record it (and you don't know which one it will be. It's likely HTCs and Samsungs default codecs are different). Try to set MediaRecorder.VideoEncoder.H264 instead.

Android recording video using Camcorder on HTC one X

I implemented a video recorder in my code and it runs perfectly on almost all the devices
except to HTC One X. There the video record getting stuck(the first image doesn't change) and when I'm trying to open the file I'm receiving a pop-up "Cannot play video, sorry this video cannot be played"
Here are my settings
mMediaRecorder.setPreviewDisplay(mSurfaceHolder.getSurface());
// Use the same frame rate for both, since internally
// if the frame rate is too large, it can cause camera to become
// unstable. We need to fix the MediaRecorder to disable the support
// of setting frame rate for now.
mMediaRecorder.setVideoFrameRate(mProfile.videoFrameRate);
//mMediaRecorder.setVideoSize(mVideoWidth, mVideoHeight);
mMediaRecorder.setVideoSize(640,480); // Works On Note(not on HTC One X)
mMediaRecorder.setVideoEncodingBitRate(MAXIMAL_PERMITTED_VIDEO_ENCODING_BITRATE);
// mMediaRecorder.setVideoEncoder(mProfile.videoCodec);
mMediaRecorder.setVideoEncoder(MediaRecorder.VideoEncoder.DEFAULT);
// mMediaRecorder.setAudioEncoder(mProfile.audioCodec);
mMediaRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.DEFAULT);
Thanks
I adapted some code from this question How can I capture a video recording on Android? for recording video, set it to 640x480, and it ran fine on my AT&T One X:
https://raw.github.com/lnanek/Misc/master/HtcOneXVideoRecord/src/com/htc/sample/videorecord/RecordVideo.java
So it isn't the 640x480 that isn't working in and of itself. What's the value for the bitrate you are setting? Have you considered using profiles instead, which are build in supported combinations? For example, you would set:
mRecorder.setProfile(CamcorderProfile.get(CamcorderProfile.QUALITY_HIGH)
And that would set the resolution, bit rate, etc. to values that work. There are various constants for high quality recording, low, etc..

How to determine if an Android phone can capture video?

Android 1.6 supports video capture, however, not all phones will support video capture. Is there a way I can tell if the phone I am running on supports video capture or not?
Well, I couldn't find an official way to do this. The only way I know is to assume that all Android phones will support video capture, so if the phone is running 1.5 (3) or greater, it will support video capture.
android.os.Build.VERSION.SDK_INT

Categories

Resources