I have an application that uses MediaRecorder for recording video and I have a problem with low resolution recording on the Samsung Galaxy S5 SM-G900F (only this device - recording at the lowest supported video resolution works fine on everything else I have tested with).
I firstly interrogate the camera parameters (with a Camera Parameters object, so mParameters.getSupportedVideoSizes();
and mParameters.getSupportedPreviewSizes();
) to check for the available recording and preview resolutions and the S5 returns the following supported video and preview sizes, respectively:
Video Size List: Preview Size List:
W = 1920, H = 1080
W = 1920, H = 1080 W = 1440, H = 1080
W = 1440, H = 1080 W = 1280, H = 720
W = 1280, H = 720 W = 1056, H = 864
W = 800, H = 450 W = 960, H = 720
W = 800, H = 480 W = 800, H = 480
W = 720, H = 480 W = 720, H = 480
W = 640, H = 480 W = 640, H = 480
W = 352, H = 288 W = 352, H = 288
W = 320, H = 240 W = 320, H = 240
W = 176, H = 144 W = 176, H = 144
The range of supported frame rates returned is 10,000-30,000, so I select 10,000 for the lowest recording resolution (10FPS).
I select the lowest resolution offered by the S5, which is 176(w) x 144(h) (to keep the video file size low) and then make the following MediaRecorder settings...
mMediaRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
mMediaRecorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);
mMediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
mMediaRecorder.setVideoFrameRate(10);
mMediaRecorder.setVideoSize(176, 144);
mMediaRecorder.setVideoEncodingBitRate(256000);
mMediaRecorder.setVideoEncoder(MediaRecorder.VideoEncoder.H264);
mMediaRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
mMediaRecorder.setPreviewDisplay(mSurfaceHolder.getSurface()); // Preview size is also set to 176 x 144
mMediaRecorder.setOutputFile(mVideoFilename);
...before then calling mMediaRecorder.prepare();
, followed by mMediaRecorder.start();
.
This code works fine on the "Sony XPeria", the "HTC One", the "HTC One V", the "Samsung Galaxy S3" an "HTC Explorer" and a number of other devices, running various Android versions from Gingerbread up to KitKat (I can't get a separate Video Size list on Gingerbread).
Only the Samsung Galaxy S5 has a problem recording at 176 x 144. When calling mMediaRecorder.start();
, the recording fails to start with a "java.lang.RuntimeException: start failed." exception.
I cannot work out what the problem is. All other recording resolutions (with increased EncodingBitRate settings) work just fine - it is only 176 x 144 that doesn't work on the S5.
Has anybody else seen this problem? Does anybody know if there's a problem with the S5 that stops recording from working properly at the lowest supported video resolution? Or is there some Samsung 'trick' that I'm missing?
Any help or insights would be much appreciated - I'm tearing my hair out over this one!