Example usage for android.media CamcorderProfile QUALITY_720P

List of usage examples for android.media CamcorderProfile QUALITY_720P

Introduction

In this page you can find the example usage for android.media CamcorderProfile QUALITY_720P.

Prototype

int QUALITY_720P

To view the source code for android.media CamcorderProfile QUALITY_720P.

Click Source Link

Document

Quality level corresponding to the 720p (1280 x 720) resolution.

Usage

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  ww  .  j  a  v  a2  s  . c  o  m

    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 createModeSwitcher() {
    LayoutInflater inflator = ApplicationScreen.instance.getLayoutInflater();
    modeSwitcher = (com.almalence.ui.Switch.Switch) inflator
            .inflate(R.layout.plugin_capture_standard_modeswitcher, null, false);

    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(ApplicationScreen.getMainContext());
    ModePreference = prefs.getString("modeVideoDROPref", "1");
    modeSwitcher.setTextOn(ApplicationScreen.instance.getString(R.string.Pref_Video_DRO_ON));
    modeSwitcher.setTextOff(ApplicationScreen.instance.getString(R.string.Pref_Video_DRO_OFF));
    modeSwitcher.setChecked(ModePreference.compareTo("0") == 0 ? true : false);
    modeSwitcher.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
        @Override/*  w  w w  .  j  a v  a2 s  .  c o m*/
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            SharedPreferences prefs = PreferenceManager
                    .getDefaultSharedPreferences(ApplicationScreen.getMainContext());

            if (isChecked) {
                ModePreference = "0";
                if (CameraController.isNexus6) {
                    Toast.makeText(ApplicationScreen.getMainContext(),
                            "Not suported currently on your device. Will be available later.",
                            Toast.LENGTH_LONG).show();
                    ModePreference = "1";
                    modeSwitcher.setChecked(false);
                    return;
                }
            } else {
                ModePreference = "1";
            }

            SharedPreferences.Editor editor = prefs.edit();
            editor.putString("modeVideoDROPref", ModePreference);
            editor.commit();

            if (modeDRO()) {
                int quality = Integer.parseInt(prefs.getString(
                        CameraController.getCameraIndex() == 0 ? ApplicationScreen.sImageSizeVideoBackPref
                                : ApplicationScreen.sImageSizeVideoFrontPref,
                        DEFAULT_VIDEO_QUALITY));
                if (quality > CamcorderProfile.QUALITY_720P || maxQuality()) {
                    quality = CamcorderProfile.QUALITY_720P;
                    quickControlIconID = R.drawable.gui_almalence_video_720;
                    editor.putString(
                            CameraController.getCameraIndex() == 0 ? ApplicationScreen.sImageSizeVideoBackPref
                                    : ApplicationScreen.sImageSizeVideoFrontPref,
                            String.valueOf(quality));
                    editor.commit();
                    VideoCapturePlugin.this.refreshQuickControl();
                }
            }

            try {
                CameraController.stopCameraPreview();
                setCameraPreviewSize();
                if (VideoCapturePlugin.this.modeDRO()) {
                    takePictureButton.setVisibility(View.GONE);
                    timeLapseButton.setVisibility(View.GONE);
                    ApplicationScreen.instance.showOpenGLLayer(2);
                    ApplicationScreen.instance.glSetRenderingMode(GLSurfaceView.RENDERMODE_WHEN_DIRTY);
                } else {
                    if (!CameraController.isRemoteCamera()) {
                        if (displayTakePicture)
                            takePictureButton.setVisibility(View.VISIBLE);
                        timeLapseButton.setVisibility(View.VISIBLE);
                    }

                    droEngine.onPause();
                    ApplicationScreen.instance.hideOpenGLLayer();
                    if (!CameraController.isUseCamera2()) {
                        CameraController.setupCamera(ApplicationScreen.getPreviewSurfaceHolder(), true);
                    }
                    CameraController.startCameraPreview();
                }
            } catch (final Exception e) {
                Log.e(TAG, Util.toString(e.getStackTrace(), '\n'));
                e.printStackTrace();
            }
        }
    });

}

From source file:com.almalence.plugins.capture.video.VideoCapturePlugin.java

private void setupVideoSize(SharedPreferences prefs) {
    quickControlIconID = -1;//from  ww w  .j ava 2 s  .  com
    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.czh.testmpeg.videorecord.CameraActivity.java

private void updateButtonText(int quality) {
    if (quality == CamcorderProfile.QUALITY_480P)
        mBinding.buttonQuality.setText("480p");
    if (quality == CamcorderProfile.QUALITY_720P)
        mBinding.buttonQuality.setText("720p");
    if (quality == CamcorderProfile.QUALITY_1080P)
        mBinding.buttonQuality.setText("1080p");
    if (quality == CamcorderProfile.QUALITY_2160P)
        mBinding.buttonQuality.setText("2160p");
}

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();//ww w .j  a v a 2s. c om

    // 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;
    }
}

From source file:com.almalence.plugins.capture.video.VideoCapturePlugin.java

@Override
public void onCameraParametersSetup() {
    supportedVideoSizesOrderedList.clear();

    List<CameraController.Size> vsz = CameraController.getSupportedVideoSizes();
    if (Util.listContainsSize(vsz, new CameraController.Size(176, 144))) {
        supportedVideoSizesOrderedList.add(CamcorderProfile.QUALITY_QCIF);
    }/* w w  w  .java2s  .c  o  m*/
    if (Util.listContainsSize(vsz, new CameraController.Size(352, 288))) {
        supportedVideoSizesOrderedList.add(CamcorderProfile.QUALITY_CIF);
    }
    if (Util.listContainsSize(vsz, new CameraController.Size(640, 480))) {
        supportedVideoSizesOrderedList.add(CamcorderProfile.QUALITY_480P);
    }
    if (Util.listContainsSize(vsz, new CameraController.Size(1280, 720))) {
        supportedVideoSizesOrderedList.add(CamcorderProfile.QUALITY_720P);
    }
    if (Util.listContainsSize(vsz, new CameraController.Size(1920, 1080))
            || Util.listContainsSize(vsz, new CameraController.Size(1920, 1088))) {
        supportedVideoSizesOrderedList.add(CamcorderProfile.QUALITY_1080P);
    }
    if (Util.listContainsSize(vsz, new CameraController.Size(3840, 2160))) {
        supportedVideoSizesOrderedList.add(CamcorderProfile.QUALITY_2160P);
    }
    if (Util.listContainsSize(vsz, new CameraController.Size(4096, 2160))) {
        supportedVideoSizesOrderedList.add(QUALITY_4K);
    }

    // Order list asc.
    Collections.sort(supportedVideoSizesOrderedList, new Comparator<Integer>() {
        @Override
        public int compare(Integer a, Integer b) {
            return a - b;
        }
    });

    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(ApplicationScreen.getMainContext());

    setupVideoSize(prefs);

    if (!CameraController.isGalaxyS4 && !CameraController.isGalaxyNote3) {
        CameraController.setPreviewFrameRate(30);
        CameraController.setRecordingHint(true);
    }
}

From source file:com.almalence.plugins.capture.video.VideoCapturePlugin.java

private CameraController.Size getBestPreviewSizeDRO(final int quality) {
    int width;// w  ww.jav a 2  s  . c  o  m
    int height;

    switch (quality) {
    case CamcorderProfile.QUALITY_QCIF:
        width = 176;
        height = 144;
        break;
    case CamcorderProfile.QUALITY_CIF:
        width = 352;
        height = 288;
        break;
    case CamcorderProfile.QUALITY_480P:
        width = 720;
        height = 480;
        break;
    case CamcorderProfile.QUALITY_720P:
        width = 1280;
        height = 720;
        break;
    case CamcorderProfile.QUALITY_1080P:
        width = 1920;
        height = 1080;
        break;
    case CamcorderProfile.QUALITY_2160P:
        width = 3840;
        height = 2160;
        break;
    case QUALITY_4K:
        width = 4096;
        height = 2160;
        break;
    default:
        return getBestPreviewSizeNormal(false);
    }

    if (maxQuality() && modeDRO()) {
        width = 720;
        height = 480;
    } else if (maxQuality()) {
        width = 1920;
        height = 1080;
    }

    final List<CameraController.Size> sizes = CameraController.getSupportedPreviewSizes();

    CameraController.Size size_best = sizes.get(0);
    for (final CameraController.Size size : sizes) {
        if (Math.sqrt(sqr(size.getWidth() - width) + sqr(size.getHeight() - height)) < Math
                .sqrt(sqr(size_best.getWidth() - width) + sqr(size_best.getHeight() - height))) {
            size_best = size;
        }
    }

    return size_best;
}