Кажется, проблема в библиотеке. Позвольте мне объяснить ..
Посмотрев, как OpenCamera реализовал свою камеру, я заметил, что они сначала проверяют, имеет ли camCoderProfile
значение CamcorderProfile.QUALITY...
, затем устанавливают профиль и передают размер профиля, как показано ниже :
private void initialiseVideoQuality() {
int cameraId = camera_controller.getCameraId();
List<Integer> profiles = new ArrayList<>();
List<VideoQualityHandler.Dimension2D> dimensions = new ArrayList<>();
if( CamcorderProfile.hasProfile(cameraId, CamcorderProfile.QUALITY_HIGH) ) {
CamcorderProfile profile = CamcorderProfile.get(cameraId, CamcorderProfile.QUALITY_HIGH);
profiles.add(CamcorderProfile.QUALITY_HIGH);
dimensions.add(new VideoQualityHandler.Dimension2D(profile.videoFrameWidth, profile.videoFrameHeight));
}
if( Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP ) {
if( CamcorderProfile.hasProfile(cameraId, CamcorderProfile.QUALITY_2160P) ) {
CamcorderProfile profile = CamcorderProfile.get(cameraId, CamcorderProfile.QUALITY_2160P);
profiles.add(CamcorderProfile.QUALITY_2160P);
dimensions.add(new VideoQualityHandler.Dimension2D(profile.videoFrameWidth, profile.videoFrameHeight));
}
}
if( CamcorderProfile.hasProfile(cameraId, CamcorderProfile.QUALITY_1080P) ) {
CamcorderProfile profile = CamcorderProfile.get(cameraId, CamcorderProfile.QUALITY_1080P);
profiles.add(CamcorderProfile.QUALITY_1080P);
dimensions.add(new VideoQualityHandler.Dimension2D(profile.videoFrameWidth, profile.videoFrameHeight));
}
if( CamcorderProfile.hasProfile(cameraId, CamcorderProfile.QUALITY_720P) ) {
CamcorderProfile profile = CamcorderProfile.get(cameraId, CamcorderProfile.QUALITY_720P);
profiles.add(CamcorderProfile.QUALITY_720P);
dimensions.add(new VideoQualityHandler.Dimension2D(profile.videoFrameWidth, profile.videoFrameHeight));
}
if( CamcorderProfile.hasProfile(cameraId, CamcorderProfile.QUALITY_480P) ) {
CamcorderProfile profile = CamcorderProfile.get(cameraId, CamcorderProfile.QUALITY_480P);
profiles.add(CamcorderProfile.QUALITY_480P);
dimensions.add(new VideoQualityHandler.Dimension2D(profile.videoFrameWidth, profile.videoFrameHeight));
}
if( CamcorderProfile.hasProfile(cameraId, CamcorderProfile.QUALITY_CIF) ) {
CamcorderProfile profile = CamcorderProfile.get(cameraId, CamcorderProfile.QUALITY_CIF);
profiles.add(CamcorderProfile.QUALITY_CIF);
dimensions.add(new VideoQualityHandler.Dimension2D(profile.videoFrameWidth, profile.videoFrameHeight));
}
if( CamcorderProfile.hasProfile(cameraId, CamcorderProfile.QUALITY_QVGA) ) {
CamcorderProfile profile = CamcorderProfile.get(cameraId, CamcorderProfile.QUALITY_QVGA);
profiles.add(CamcorderProfile.QUALITY_QVGA);
dimensions.add(new VideoQualityHandler.Dimension2D(profile.videoFrameWidth, profile.videoFrameHeight));
}
if( CamcorderProfile.hasProfile(cameraId, CamcorderProfile.QUALITY_QCIF) ) {
CamcorderProfile profile = CamcorderProfile.get(cameraId, CamcorderProfile.QUALITY_QCIF);
profiles.add(CamcorderProfile.QUALITY_QCIF);
dimensions.add(new VideoQualityHandler.Dimension2D(profile.videoFrameWidth, profile.videoFrameHeight));
}
if( CamcorderProfile.hasProfile(cameraId, CamcorderProfile.QUALITY_LOW) ) {
CamcorderProfile profile = CamcorderProfile.get(cameraId, CamcorderProfile.QUALITY_LOW);
profiles.add(CamcorderProfile.QUALITY_LOW);
dimensions.add(new VideoQualityHandler.Dimension2D(profile.videoFrameWidth, profile.videoFrameHeight));
}
this.video_quality_handler.initialiseVideoQualityFromProfiles(profiles, dimensions);
}
Похоже, что OpenCamera изменяет только качество видео с default
/ 0, если поддерживаемая ширина профиля составляет 1920, а высота равна 1080 - я думаю, это потому, что активность камеры всегда в альбомной ориентации:
if( video_quality_handler.getCurrentVideoQualityIndex() == -1 && video_quality_handler.getSupportedVideoQuality().size() > 0 ) {
video_quality_handler.setCurrentVideoQualityIndex(0); // start with highest quality
//If I log video_quality_handler.getSupportedVideoQuality() here, I get:
//[1, 5_r1440x1080, 5, 4_r960x720, 4_r800x450, 4, 7_r640x480, 7_r480x320, 7_r352x288, 7, 2]
//With 1 being QUALITY_HIGH
//https://developer.android.com/reference/android/media/CamcorderProfile.html#constants_2
for(int i=0;i<video_quality_handler.getSupportedVideoQuality().size();i++) {
CamcorderProfile profile = getCamcorderProfile(video_quality_handler.getSupportedVideoQuality().get(i));
if( profile.videoFrameWidth == 1920 && profile.videoFrameHeight == 1080 ) {
video_quality_handler.setCurrentVideoQualityIndex(i);
break;
}
}
}
private CamcorderProfile getCamcorderProfile(String quality) {
if( camera_controller == null ) {
//Camera is not opened
return CamcorderProfile.get(0, CamcorderProfile.QUALITY_HIGH);
}
int cameraId = camera_controller.getCameraId();
CamcorderProfile camcorder_profile = CamcorderProfile.get(cameraId, CamcorderProfile.QUALITY_HIGH); // default
try {
String profile_string = quality;
int index = profile_string.indexOf('_');
if( index != -1 ) {
profile_string = quality.substring(0, index);
}
int profile = Integer.parseInt(profile_string);
camcorder_profile = CamcorderProfile.get(cameraId, profile);
if( index != -1 && index+1 < quality.length() ) {
String override_string = quality.substring(index+1);
if( override_string.charAt(0) == 'r' && override_string.length() >= 4 ) {
index = override_string.indexOf('x');
if( index == -1 ) {
Log.d(TAG, "override_string invalid format, can't find x");
}
else {
String resolution_w_s = override_string.substring(1, index); // skip first 'r'
String resolution_h_s = override_string.substring(index+1);
// copy to local variable first, so that if we fail to parse height, we don't set the width either
int resolution_w = Integer.parseInt(resolution_w_s);
int resolution_h = Integer.parseInt(resolution_h_s);
camcorder_profile.videoFrameWidth = resolution_w;
camcorder_profile.videoFrameHeight = resolution_h;
}
}
else {
Log.d(TAG, "unknown override_string initial code, or otherwise invalid format");
}
}
}
catch(NumberFormatException e) {
e.printStackTrace();
}
return camcorder_profile;
}
}
Пока я буду использовать ту же реализацию, что и OpenCamera. Поскольку он лицензирован по GPLv3 , я изменил проект, чтобы реализовать только запись видео, и сделал доступным исходный код здесь .