List of usage examples for android.media CamcorderProfile hasProfile
public static boolean hasProfile(int cameraId, int quality)
From source file:Main.java
public static List<CamcorderProfile> getAvailableProfiles(int cameraID) { List<CamcorderProfile> profiles = new ArrayList<>(specificProfileQualities.length); for (int quality : specificProfileQualities) { if (CamcorderProfile.hasProfile(cameraID, quality)) { CamcorderProfile p = CamcorderProfile.get(cameraID, quality); profiles.add(p);//from www . j a va 2 s . c om Log.d("PROFILE", p.videoFrameWidth + "x" + p.videoFrameHeight + " " + p.videoFrameRate + " fps " + p.videoBitRate + " bps "); } } return profiles; }
From source file:com.czh.testmpeg.videorecord.CameraActivity.java
private void reloadQualities(int idCamera) { SharedPreferences prefs = getSharedPreferences("RECORDING", Context.MODE_PRIVATE); quality = prefs.getInt("QUALITY", CamcorderProfile.QUALITY_480P); changeVideoQuality(quality);//from w w w .ja va 2 s. c om final ArrayList<String> list = new ArrayList<String>(); int maxQualitySupported = CamcorderProfile.QUALITY_480P; if (CamcorderProfile.hasProfile(idCamera, CamcorderProfile.QUALITY_480P)) { list.add("480p"); maxQualitySupported = CamcorderProfile.QUALITY_480P; } if (CamcorderProfile.hasProfile(idCamera, CamcorderProfile.QUALITY_720P)) { list.add("720p"); maxQualitySupported = CamcorderProfile.QUALITY_720P; } if (CamcorderProfile.hasProfile(idCamera, CamcorderProfile.QUALITY_1080P)) { list.add("1080p"); maxQualitySupported = CamcorderProfile.QUALITY_1080P; } if (CamcorderProfile.hasProfile(idCamera, CamcorderProfile.QUALITY_2160P)) { list.add("2160p"); maxQualitySupported = CamcorderProfile.QUALITY_2160P; } if (!CamcorderProfile.hasProfile(idCamera, quality)) { quality = maxQualitySupported; updateButtonText(maxQualitySupported); } final StableArrayAdapter adapter = new StableArrayAdapter(this, android.R.layout.simple_list_item_1, list); mBinding.listOfQualities.setAdapter(adapter); mBinding.listOfQualities.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, final View view, int position, long id) { final String item = (String) parent.getItemAtPosition(position); mBinding.buttonQuality.setText(item); if (item.equals("480p")) { changeVideoQuality(CamcorderProfile.QUALITY_480P); } else if (item.equals("720p")) { changeVideoQuality(CamcorderProfile.QUALITY_720P); } else if (item.equals("1080p")) { changeVideoQuality(CamcorderProfile.QUALITY_1080P); } else if (item.equals("2160p")) { changeVideoQuality(CamcorderProfile.QUALITY_2160P); } if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { mBinding.listOfQualities.animate().setDuration(200).alpha(0).withEndAction(new Runnable() { @Override public void run() { mBinding.listOfQualities.setVisibility(View.GONE); } }); } else { mBinding.listOfQualities.setVisibility(View.GONE); } } }); }
From source file:com.almalence.plugins.capture.video.VideoCapturePlugin.java
private void setupVideoSize(SharedPreferences prefs) { quickControlIconID = -1;/*from w w w.j ava2 s.c o m*/ int quality = Integer.parseInt( prefs.getString(CameraController.getCameraIndex() == 0 ? ApplicationScreen.sImageSizeVideoBackPref : ApplicationScreen.sImageSizeVideoFrontPref, DEFAULT_VIDEO_QUALITY)); if (this.modeDRO() && quality > CamcorderProfile.QUALITY_720P) { quality = CamcorderProfile.QUALITY_720P; } if (supportedVideoSizesOrderedList.isEmpty()) { if (videoSizeIcons.containsKey(quality)) { quickControlIconID = videoSizeIcons.get(quality); } return; } // If selected profile not supported or if we don't have icon for selected profile, then select max from available. while ((!CamcorderProfile.hasProfile(CameraController.getCameraIndex(), quality) && !supportedVideoSizesOrderedList.contains(quality)) || !videoSizeIcons.containsKey(quality)) { quality--; } if (quality == 0) { return; } if (videoSizeIcons.containsKey(quality)) { quickControlIconID = videoSizeIcons.get(quality); } if (maxQuality()) { quickControlIconID = -1; } Editor editor = prefs.edit(); editor.putString(CameraController.getCameraIndex() == 0 ? ApplicationScreen.sImageSizeVideoBackPref : ApplicationScreen.sImageSizeVideoFrontPref, String.valueOf(quality)); editor.commit(); }
From source file:com.almalence.plugins.capture.video.VideoCapturePlugin.java
private void prepareMediaRecorder() { mMediaRecorder = CameraController.getMediaRecorder(); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(ApplicationScreen.getMainContext()); if (Build.VERSION.SDK_INT > Build.VERSION_CODES.ICE_CREAM_SANDWICH && videoStabilization) CameraController.setVideoStabilization(true); CameraController.unlockCamera();/*from w w w . j a v a 2s. c o m*/ // Step 2: Set sources if (!CameraController.isUseCamera2()) { CameraController.configureMediaRecorder(mMediaRecorder); mMediaRecorder.setVideoSource(MediaRecorder.VideoSource.CAMERA); } else { mMediaRecorder.setVideoSource(MediaRecorder.VideoSource.SURFACE); } if (ApplicationScreen.isMicrophonePermissionGranted()) mMediaRecorder.setAudioSource(MediaRecorder.AudioSource.CAMCORDER); int quality = Integer.parseInt( prefs.getString(CameraController.getCameraIndex() == 0 ? ApplicationScreen.sImageSizeVideoBackPref : ApplicationScreen.sImageSizeVideoFrontPref, DEFAULT_VIDEO_QUALITY)); if (maxQuality()) { quality = CamcorderProfile.QUALITY_HIGH; } boolean useProfile = true; if (!CamcorderProfile.hasProfile(CameraController.getCameraIndex(), quality)) useProfile = false; // Step 3: Set a CamcorderProfile (requires API Level 8 or higher) try { try { if (swChecked) { int qualityTimeLapse = quality; // if time lapse activated switch (quality) { case CamcorderProfile.QUALITY_QCIF: quality = CamcorderProfile.QUALITY_TIME_LAPSE_QCIF; break; case CamcorderProfile.QUALITY_CIF: quality = CamcorderProfile.QUALITY_TIME_LAPSE_CIF; break; case CamcorderProfile.QUALITY_2160P: quality = CamcorderProfile.QUALITY_TIME_LAPSE_2160P; break; case CamcorderProfile.QUALITY_1080P: quality = CamcorderProfile.QUALITY_TIME_LAPSE_1080P; break; case CamcorderProfile.QUALITY_720P: quality = CamcorderProfile.QUALITY_TIME_LAPSE_720P; break; case CamcorderProfile.QUALITY_480P: quality = CamcorderProfile.QUALITY_TIME_LAPSE_480P; break; case QUALITY_4K: quality = QUALITY_4K; break; case CamcorderProfile.QUALITY_HIGH: quality = CamcorderProfile.QUALITY_TIME_LAPSE_HIGH; break; default: break; } if (!CamcorderProfile.hasProfile(CameraController.getCameraIndex(), quality)) { Toast.makeText(ApplicationScreen.instance, "Time lapse not supported", Toast.LENGTH_LONG) .show(); } else quality = qualityTimeLapse; } } catch (Exception e) { e.printStackTrace(); Log.e("Video", "Time lapse error catched" + e.getMessage()); swChecked = false; } lastUseProfile = useProfile; if (useProfile) { CamcorderProfile pr = CamcorderProfile.get(CameraController.getCameraIndex(), quality); if (ApplicationScreen.isMicrophonePermissionGranted()) { mMediaRecorder.setProfile(pr); } else { // If we don't have access to microphone, then configure only video settings of MediaREcorder. mMediaRecorder.setOutputFormat(pr.fileFormat); mMediaRecorder.setVideoEncoder(pr.videoCodec); mMediaRecorder.setVideoSize(pr.videoFrameWidth, pr.videoFrameHeight); mMediaRecorder.setVideoFrameRate(pr.videoFrameRate); mMediaRecorder.setVideoEncodingBitRate(pr.videoBitRate); } lastCamcorderProfile = pr; } else { boolean useProf = false; lastUseProf = useProf; CameraController.Size sz = null; switch (quality) { case CamcorderProfile.QUALITY_QCIF: sz = new CameraController.Size(176, 144); break; case CamcorderProfile.QUALITY_CIF: sz = new CameraController.Size(352, 288); break; case CamcorderProfile.QUALITY_480P: sz = new CameraController.Size(640, 480); break; case CamcorderProfile.QUALITY_720P: sz = new CameraController.Size(1280, 720); break; case CamcorderProfile.QUALITY_1080P: sz = new CameraController.Size(1920, 1080); break; case CamcorderProfile.QUALITY_2160P: { if (CamcorderProfile.hasProfile(CameraController.getCameraIndex(), CamcorderProfile.QUALITY_2160P)) sz = new CameraController.Size(3840, 2160); else { CamcorderProfile prof = CamcorderProfile.get(CameraController.getCameraIndex(), CamcorderProfile.QUALITY_HIGH); prof.videoFrameWidth = 3840; prof.videoFrameHeight = 2160; prof.videoBitRate = (int) (prof.videoBitRate * 2.8); // need a higher bitrate for the better quality - this is roughly based on the bitrate used by an S5's native camera app at 4K (47.6 Mbps, compared to 16.9 Mbps which is what's returned by the QUALITY_HIGH profile) if (ApplicationScreen.isMicrophonePermissionGranted()) { mMediaRecorder.setProfile(prof); } else { mMediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4); mMediaRecorder.setVideoEncoder(MediaRecorder.VideoEncoder.H264); mMediaRecorder.setVideoSize(prof.videoFrameWidth, prof.videoFrameHeight); mMediaRecorder.setVideoFrameRate(30); mMediaRecorder.setVideoEncodingBitRate((int) (prof.videoBitRate * 2.8)); // need a higher bitrate for the better quality } lastCamcorderProfile = prof; useProf = true; lastUseProf = useProf; } } break; case QUALITY_4K: { if (CamcorderProfile.hasProfile(CameraController.getCameraIndex(), CamcorderProfile.QUALITY_1080P)) { CamcorderProfile prof = CamcorderProfile.get(CamcorderProfile.QUALITY_1080P); prof.videoFrameHeight = 2160; prof.videoFrameWidth = 4096; if (ApplicationScreen.isMicrophonePermissionGranted()) { mMediaRecorder.setProfile(prof); } else { mMediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4); mMediaRecorder.setVideoEncoder(MediaRecorder.VideoEncoder.H264); mMediaRecorder.setVideoSize(prof.videoFrameWidth, prof.videoFrameHeight); mMediaRecorder.setVideoFrameRate(30); mMediaRecorder.setVideoEncodingBitRate(prof.videoBitRate * 4); // 2160p has 4x more pixels then 1080p. } lastCamcorderProfile = prof; useProf = true; lastUseProf = useProf; } else sz = new CameraController.Size(4096, 2160); } break; default: break; } if (!useProf) { mMediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4); mMediaRecorder.setVideoEncoder(MediaRecorder.VideoEncoder.H264); mMediaRecorder.setVideoSize(sz.getWidth(), sz.getHeight()); mMediaRecorder.setVideoFrameRate(30); // Other parameters just copy from CamcorderProfile.QUALITY_1080P CamcorderProfile prof = CamcorderProfile.get(CamcorderProfile.QUALITY_1080P); mMediaRecorder.setVideoEncodingBitRate(prof.videoBitRate * 4); // 2160p has 4x more pixels then 1080p. if (ApplicationScreen.isMicrophonePermissionGranted()) { mMediaRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AAC); mMediaRecorder.setAudioChannels(prof.audioChannels); mMediaRecorder.setAudioEncodingBitRate(prof.audioBitRate); mMediaRecorder.setAudioSamplingRate(prof.audioSampleRate); } lastSz = sz; } else lastUseProfile = true; } if (swChecked) { double val1 = Double.valueOf(stringInterval[interval]); int val2 = measurementVal; switch (val2) { case 0: val2 = 1; break; case 1: val2 = 60; break; case 2: val2 = 3600; break; default: break; } captureRate = 1 / (val1 * val2); mMediaRecorder.setCaptureRate(captureRate); } } catch (Exception e) { e.printStackTrace(); releaseMediaRecorder(); // release the MediaRecorder object return; } // Step 4: Set output file if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { DocumentFile file = getOutputMediaDocumentFile(); try { documentFileSavedFd = ApplicationScreen.instance.getContentResolver() .openFileDescriptor(file.getUri(), "w"); FileDescriptor fileDescriptor = documentFileSavedFd.getFileDescriptor(); mMediaRecorder.setOutputFile(fileDescriptor); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); mMediaRecorder.setOutputFile(getOutputMediaFile().toString()); } } else { mMediaRecorder.setOutputFile(getOutputMediaFile().toString()); } // Step 5: Set the preview output if (!CameraController.isUseCamera2()) { mMediaRecorder.setPreviewDisplay(ApplicationScreen.getPreviewSurfaceHolder().getSurface()); } mMediaRecorder.setOrientationHint(CameraController.isFrontCamera() ? (ApplicationScreen.getWantLandscapePhoto() ? ApplicationScreen.getGUIManager().getImageDataOrientation() : (ApplicationScreen.getGUIManager().getImageDataOrientation() + 180) % 360) : ApplicationScreen.getGUIManager().getImageDataOrientation()); // Step 6: Prepare configured MediaRecorder try { mMediaRecorder.prepare(); } catch (Exception e) { Log.d("Video", "Exception preparing MediaRecorder: " + e.getMessage()); releaseMediaRecorder(); CameraController.lockCamera(); // take camera access back from MediaRecorder return; } }