Java Code Examples for android.media.CamcorderProfile#hasProfile()

The following examples show how to use android.media.CamcorderProfile#hasProfile() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CameraSession.java    From KrGallery with GNU General Public License v2.0 7 votes vote down vote up
protected void configureRecorder(int quality, MediaRecorder recorder) {
    Camera.CameraInfo info = new Camera.CameraInfo();
    Camera.getCameraInfo(cameraInfo.cameraId, info);
    int displayOrientation = getDisplayOrientation(info, false);
    recorder.setOrientationHint(displayOrientation);

    int highProfile = getHigh();
    boolean canGoHigh = CamcorderProfile.hasProfile(cameraInfo.cameraId, highProfile);
    boolean canGoLow = CamcorderProfile.hasProfile(cameraInfo.cameraId, CamcorderProfile.QUALITY_LOW);
    if (canGoHigh && (quality == 1 || !canGoLow)) {
        recorder.setProfile(CamcorderProfile.get(cameraInfo.cameraId, highProfile));
    } else if (canGoLow) {
        recorder.setProfile(CamcorderProfile.get(cameraInfo.cameraId, CamcorderProfile.QUALITY_LOW));
    } else {
        throw new IllegalStateException("cannot find valid CamcorderProfile");
    }
    isVideo = true;
}
 
Example 2
Source File: Camera1ApiManager.java    From rtmp-rtsp-stream-client-java with Apache License 2.0 7 votes vote down vote up
/**
 * @return max size that device can record.
 */
private Camera.Size getMaxEncoderSizeSupported() {
  if (CamcorderProfile.hasProfile(CamcorderProfile.QUALITY_2160P)) {
    return camera.new Size(3840, 2160);
  } else if (CamcorderProfile.hasProfile(CamcorderProfile.QUALITY_1080P)) {
    return camera.new Size(1920, 1080);
  } else if (CamcorderProfile.hasProfile(CamcorderProfile.QUALITY_720P)) {
    return camera.new Size(1280, 720);
  } else {
    return camera.new Size(640, 480);
  }
}
 
Example 3
Source File: CamcorderProfiles.java    From Lassi-Android with MIT License 6 votes vote down vote up
/**
 * Returns a CamcorderProfile that's somewhat coherent with the target size,
 * to ensure we get acceptable video/audio parameters for MediaRecorders (most notably the bitrate).
 *
 * @param cameraId   the camera id
 * @param targetSize the target video size
 * @return a profile
 */
@NonNull
static CamcorderProfile get(int cameraId, @NonNull Size targetSize) {
    final int targetArea = targetSize.getWidth() * targetSize.getHeight();
    List<Size> sizes = new ArrayList<>(sizeToProfileMap.keySet());
    Collections.sort(sizes, new Comparator<Size>() {
        @Override
        public int compare(Size s1, Size s2) {
            int a1 = Math.abs(s1.getWidth() * s1.getHeight() - targetArea);
            int a2 = Math.abs(s2.getWidth() * s2.getHeight() - targetArea);
            //noinspection UseCompareMethod
            return (a1 < a2) ? -1 : ((a1 == a2) ? 0 : 1);
        }
    });
    while (sizes.size() > 0) {
        Size candidate = sizes.remove(0);
        //noinspection ConstantConditions
        int quality = sizeToProfileMap.get(candidate);
        if (CamcorderProfile.hasProfile(cameraId, quality)) {
            return CamcorderProfile.get(cameraId, quality);
        }
    }
    // Should never happen, but fallback to low.
    return CamcorderProfile.get(cameraId, CamcorderProfile.QUALITY_LOW);
}
 
Example 4
Source File: SettingsUtil.java    From Camera2 with Apache License 2.0 6 votes vote down vote up
/**
 * Starting from 'start' this method returns the next supported video
 * quality.
 */
private static int getNextSupportedVideoQualityIndex(int cameraId, int start)
{
    for (int i = start + 1; i < sVideoQualities.length; ++i)
    {
        if (isVideoQualitySupported(sVideoQualities[i])
                && CamcorderProfile.hasProfile(cameraId, sVideoQualities[i]))
        {
            // We found a new supported quality.
            return i;
        }
    }

    // Failed to find another supported quality.
    if (start < 0 || start >= sVideoQualities.length)
    {
        // This means we couldn't find any supported quality.
        throw new IllegalArgumentException("Could not find supported video qualities.");
    }

    // We previously found a larger supported size. In this edge case, just
    // return the same index as the previous size.
    return start;
}
 
Example 5
Source File: TakeVideoActivity.java    From MultiMediaSample with Apache License 2.0 6 votes vote down vote up
private void initSupportProfile() {

        if (CamcorderProfile.hasProfile(CamcorderProfile.QUALITY_TIME_LAPSE_480P)) {//无声音的480p
            mQuality = CamcorderProfile.QUALITY_TIME_LAPSE_480P;
        } else if (CamcorderProfile.hasProfile(CamcorderProfile.QUALITY_TIME_LAPSE_QVGA)) {
            mQuality = CamcorderProfile.QUALITY_TIME_LAPSE_QVGA;
        } else if (CamcorderProfile.hasProfile(CamcorderProfile.QUALITY_TIME_LAPSE_CIF)) {
            mQuality = CamcorderProfile.QUALITY_TIME_LAPSE_CIF;
        } else if (CamcorderProfile.hasProfile(CamcorderProfile.QUALITY_TIME_LAPSE_720P)) {
            mQuality = CamcorderProfile.QUALITY_TIME_LAPSE_720P;
        }
        Log.d(TAG, "finally mQuality resolution:" + mQuality);
        CamcorderProfile profile = CamcorderProfile.get(mQuality);
        //因为竖屏被旋转了90度
        mVideoHeiht = profile.videoFrameWidth;
        mVideoWidth = profile.videoFrameHeight;
        Log.d(TAG, "video screen from CamcorderProfile resolution:" + mVideoWidth + "*" + mVideoHeiht);
    }
 
Example 6
Source File: CameraSession.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
protected void configureRecorder(int quality, MediaRecorder recorder) {
    Camera.CameraInfo info = new Camera.CameraInfo();
    Camera.getCameraInfo(cameraInfo.cameraId, info);
    int displayOrientation = getDisplayOrientation(info, false);


    int outputOrientation = 0;
    if (jpegOrientation != OrientationEventListener.ORIENTATION_UNKNOWN) {
        if (info.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) {
            outputOrientation = (info.orientation - jpegOrientation + 360) % 360;
        } else {
            outputOrientation = (info.orientation + jpegOrientation) % 360;
        }
    }
    recorder.setOrientationHint(outputOrientation);

    int highProfile = getHigh();
    boolean canGoHigh = CamcorderProfile.hasProfile(cameraInfo.cameraId, highProfile);
    boolean canGoLow = CamcorderProfile.hasProfile(cameraInfo.cameraId, CamcorderProfile.QUALITY_LOW);
    if (canGoHigh && (quality == 1 || !canGoLow)) {
        recorder.setProfile(CamcorderProfile.get(cameraInfo.cameraId, highProfile));
    } else if (canGoLow) {
        recorder.setProfile(CamcorderProfile.get(cameraInfo.cameraId, CamcorderProfile.QUALITY_LOW));
    } else {
        throw new IllegalStateException("cannot find valid CamcorderProfile");
    }
    isVideo = true;
}
 
Example 7
Source File: VideoCapture.java    From mollyim-android with GNU General Public License v3.0 5 votes vote down vote up
/** Set audio record parameters by CamcorderProfile */
private void setAudioParametersByCamcorderProfile(Size currentResolution, String cameraId) {
    CamcorderProfile profile;
    boolean isCamcorderProfileFound = false;

    for (int quality : CamcorderQuality) {
        if (CamcorderProfile.hasProfile(Integer.parseInt(cameraId), quality)) {
            profile = CamcorderProfile.get(Integer.parseInt(cameraId), quality);
            if (currentResolution.getWidth() == profile.videoFrameWidth
                && currentResolution.getHeight() == profile.videoFrameHeight) {
                mAudioChannelCount = profile.audioChannels;
                mAudioSampleRate = profile.audioSampleRate;
                mAudioBitRate = profile.audioBitRate;
                isCamcorderProfileFound = true;
                break;
            }
        }
    }

    // In case no corresponding camcorder profile can be founded, * get default value from
    // VideoCaptureConfig.
    if (!isCamcorderProfileFound) {
        VideoCaptureConfig config = (VideoCaptureConfig) getUseCaseConfig();
        mAudioChannelCount = config.getAudioChannelCount();
        mAudioSampleRate = config.getAudioSampleRate();
        mAudioBitRate = config.getAudioBitRate();
    }
}
 
Example 8
Source File: CameraSession.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
protected void configureRecorder(int quality, MediaRecorder recorder) {
    Camera.CameraInfo info = new Camera.CameraInfo();
    Camera.getCameraInfo(cameraInfo.cameraId, info);
    int displayOrientation = getDisplayOrientation(info, false);


    int outputOrientation = 0;
    if (jpegOrientation != OrientationEventListener.ORIENTATION_UNKNOWN) {
        if (info.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) {
            outputOrientation = (info.orientation - jpegOrientation + 360) % 360;
        } else {
            outputOrientation = (info.orientation + jpegOrientation) % 360;
        }
    }
    recorder.setOrientationHint(outputOrientation);

    int highProfile = getHigh();
    boolean canGoHigh = CamcorderProfile.hasProfile(cameraInfo.cameraId, highProfile);
    boolean canGoLow = CamcorderProfile.hasProfile(cameraInfo.cameraId, CamcorderProfile.QUALITY_LOW);
    if (canGoHigh && (quality == 1 || !canGoLow)) {
        recorder.setProfile(CamcorderProfile.get(cameraInfo.cameraId, highProfile));
    } else if (canGoLow) {
        recorder.setProfile(CamcorderProfile.get(cameraInfo.cameraId, CamcorderProfile.QUALITY_LOW));
    } else {
        throw new IllegalStateException("cannot find valid CamcorderProfile");
    }
    isVideo = true;
}
 
Example 9
Source File: CameraWrapper.java    From LandscapeVideoCamera with Apache License 2.0 5 votes vote down vote up
public CamcorderProfile getBaseRecordingProfile() {
    CamcorderProfile returnProfile;
    if (VERSION.SDK_INT < VERSION_CODES.HONEYCOMB) {
        returnProfile = getDefaultRecordingProfile();
    } else if (CamcorderProfile.hasProfile(CamcorderProfile.QUALITY_720P)) {
        returnProfile = CamcorderProfile.get(CamcorderProfile.QUALITY_720P);
    } else if (CamcorderProfile.hasProfile(CamcorderProfile.QUALITY_480P)) {
        returnProfile = CamcorderProfile.get(CamcorderProfile.QUALITY_480P);
    } else {
        returnProfile = getDefaultRecordingProfile();
    }
    return returnProfile;
}
 
Example 10
Source File: CameraWrapper.java    From VideoCamera with Apache License 2.0 5 votes vote down vote up
public CamcorderProfile getBaseRecordingProfile() {
    CamcorderProfile returnProfile;
    if (VERSION.SDK_INT < VERSION_CODES.HONEYCOMB) {
        returnProfile = getDefaultRecordingProfile();
    } else if (CamcorderProfile.hasProfile(CamcorderProfile.QUALITY_720P)) {
        returnProfile = CamcorderProfile.get(CamcorderProfile.QUALITY_720P);
    } else if (CamcorderProfile.hasProfile(CamcorderProfile.QUALITY_480P)) {
        returnProfile = CamcorderProfile.get(CamcorderProfile.QUALITY_480P);
    } else {
        returnProfile = getDefaultRecordingProfile();
    }
    return returnProfile;
}
 
Example 11
Source File: CameraSession.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
protected void configureRecorder(int quality, MediaRecorder recorder) {
    Camera.CameraInfo info = new Camera.CameraInfo();
    Camera.getCameraInfo(cameraInfo.cameraId, info);
    int displayOrientation = getDisplayOrientation(info, false);


    int outputOrientation = 0;
    if (jpegOrientation != OrientationEventListener.ORIENTATION_UNKNOWN) {
        if (info.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) {
            outputOrientation = (info.orientation - jpegOrientation + 360) % 360;
        } else {
            outputOrientation = (info.orientation + jpegOrientation) % 360;
        }
    }
    recorder.setOrientationHint(outputOrientation);

    int highProfile = getHigh();
    boolean canGoHigh = CamcorderProfile.hasProfile(cameraInfo.cameraId, highProfile);
    boolean canGoLow = CamcorderProfile.hasProfile(cameraInfo.cameraId, CamcorderProfile.QUALITY_LOW);
    if (canGoHigh && (quality == 1 || !canGoLow)) {
        recorder.setProfile(CamcorderProfile.get(cameraInfo.cameraId, highProfile));
    } else if (canGoLow) {
        recorder.setProfile(CamcorderProfile.get(cameraInfo.cameraId, CamcorderProfile.QUALITY_LOW));
    } else {
        throw new IllegalStateException("cannot find valid CamcorderProfile");
    }
    isVideo = true;
}
 
Example 12
Source File: CameraSession.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
protected void configureRecorder(int quality, MediaRecorder recorder) {
    Camera.CameraInfo info = new Camera.CameraInfo();
    Camera.getCameraInfo(cameraInfo.cameraId, info);
    int displayOrientation = getDisplayOrientation(info, false);


    int outputOrientation = 0;
    if (jpegOrientation != OrientationEventListener.ORIENTATION_UNKNOWN) {
        if (info.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) {
            outputOrientation = (info.orientation - jpegOrientation + 360) % 360;
        } else {
            outputOrientation = (info.orientation + jpegOrientation) % 360;
        }
    }
    recorder.setOrientationHint(outputOrientation);

    int highProfile = getHigh();
    boolean canGoHigh = CamcorderProfile.hasProfile(cameraInfo.cameraId, highProfile);
    boolean canGoLow = CamcorderProfile.hasProfile(cameraInfo.cameraId, CamcorderProfile.QUALITY_LOW);
    if (canGoHigh && (quality == 1 || !canGoLow)) {
        recorder.setProfile(CamcorderProfile.get(cameraInfo.cameraId, highProfile));
    } else if (canGoLow) {
        recorder.setProfile(CamcorderProfile.get(cameraInfo.cameraId, CamcorderProfile.QUALITY_LOW));
    } else {
        throw new IllegalStateException("cannot find valid CamcorderProfile");
    }
    isVideo = true;
}
 
Example 13
Source File: Camera1.java    From camerakit-android with MIT License 4 votes vote down vote up
private CamcorderProfile getCamcorderProfile(@VideoQuality int videoQuality) {
    CamcorderProfile camcorderProfile = null;
    switch (videoQuality) {
        case CameraKit.Constants.VIDEO_QUALITY_QVGA:
            if (CamcorderProfile.hasProfile(mCameraId, CamcorderProfile.QUALITY_QVGA)) {
                camcorderProfile = CamcorderProfile.get(mCameraId, CamcorderProfile.QUALITY_QVGA);
            } else {
                camcorderProfile = getCamcorderProfile(CameraKit.Constants.VIDEO_QUALITY_LOWEST);
            }
            break;

        case CameraKit.Constants.VIDEO_QUALITY_480P:
            if (CamcorderProfile.hasProfile(mCameraId, CamcorderProfile.QUALITY_480P)) {
                camcorderProfile = CamcorderProfile.get(mCameraId, CamcorderProfile.QUALITY_480P);
            } else {
                camcorderProfile = getCamcorderProfile(CameraKit.Constants.VIDEO_QUALITY_QVGA);
            }
            break;

        case CameraKit.Constants.VIDEO_QUALITY_720P:
            if (CamcorderProfile.hasProfile(mCameraId, CamcorderProfile.QUALITY_720P)) {
                camcorderProfile = CamcorderProfile.get(mCameraId, CamcorderProfile.QUALITY_720P);
            } else {
                camcorderProfile = getCamcorderProfile(CameraKit.Constants.VIDEO_QUALITY_480P);
            }
            break;

        case CameraKit.Constants.VIDEO_QUALITY_1080P:
            if (CamcorderProfile.hasProfile(mCameraId, CamcorderProfile.QUALITY_1080P)) {
                camcorderProfile = CamcorderProfile.get(mCameraId, CamcorderProfile.QUALITY_1080P);
            } else {
                camcorderProfile = getCamcorderProfile(CameraKit.Constants.VIDEO_QUALITY_720P);
            }
            break;

        case CameraKit.Constants.VIDEO_QUALITY_2160P:
            try {
                camcorderProfile = CamcorderProfile.get(mCameraId, CamcorderProfile.QUALITY_2160P);
            } catch (Exception e) {
                camcorderProfile = getCamcorderProfile(CameraKit.Constants.VIDEO_QUALITY_HIGHEST);
            }
            break;

        case CameraKit.Constants.VIDEO_QUALITY_HIGHEST:
            camcorderProfile = CamcorderProfile.get(mCameraId, CamcorderProfile.QUALITY_HIGH);
            break;

        case CameraKit.Constants.VIDEO_QUALITY_LOWEST:
            camcorderProfile = CamcorderProfile.get(mCameraId, CamcorderProfile.QUALITY_LOW);
            break;
    }

    if (camcorderProfile != null && mVideoBitRate != 0) {
        camcorderProfile.videoBitRate = mVideoBitRate;
    }

    return camcorderProfile;
}
 
Example 14
Source File: CameraHelper.java    From sandriosCamera with MIT License 4 votes vote down vote up
public static CamcorderProfile getCamcorderProfile(@CameraConfiguration.MediaQuality int mediaQuality, int cameraId) {
    if (Build.VERSION.SDK_INT > 10) {
        if (mediaQuality == CameraConfiguration.MEDIA_QUALITY_HIGHEST) {
            return CamcorderProfile.get(cameraId, CamcorderProfile.QUALITY_HIGH);
        } else if (mediaQuality == CameraConfiguration.MEDIA_QUALITY_HIGH) {
            if (CamcorderProfile.hasProfile(cameraId, CamcorderProfile.QUALITY_1080P)) {
                return CamcorderProfile.get(cameraId, CamcorderProfile.QUALITY_1080P);
            } else if (CamcorderProfile.hasProfile(cameraId, CamcorderProfile.QUALITY_720P)) {
                return CamcorderProfile.get(cameraId, CamcorderProfile.QUALITY_720P);
            } else {
                return CamcorderProfile.get(cameraId, CamcorderProfile.QUALITY_HIGH);
            }
        } else if (mediaQuality == CameraConfiguration.MEDIA_QUALITY_MEDIUM) {
            if (CamcorderProfile.hasProfile(cameraId, CamcorderProfile.QUALITY_720P)) {
                return CamcorderProfile.get(cameraId, CamcorderProfile.QUALITY_720P);
            } else if (CamcorderProfile.hasProfile(cameraId, CamcorderProfile.QUALITY_480P)) {
                return CamcorderProfile.get(cameraId, CamcorderProfile.QUALITY_480P);
            } else {
                return CamcorderProfile.get(cameraId, CamcorderProfile.QUALITY_LOW);
            }
        } else if (mediaQuality == CameraConfiguration.MEDIA_QUALITY_LOW) {
            if (CamcorderProfile.hasProfile(cameraId, CamcorderProfile.QUALITY_480P)) {
                return CamcorderProfile.get(cameraId, CamcorderProfile.QUALITY_480P);
            } else {
                return CamcorderProfile.get(cameraId, CamcorderProfile.QUALITY_LOW);
            }
        } else if (mediaQuality == CameraConfiguration.MEDIA_QUALITY_LOWEST) {
            return CamcorderProfile.get(cameraId, CamcorderProfile.QUALITY_LOW);
        } else {
            return CamcorderProfile.get(cameraId, CamcorderProfile.QUALITY_HIGH);
        }
    } else {
        if (mediaQuality == CameraConfiguration.MEDIA_QUALITY_HIGHEST) {
            return CamcorderProfile.get(cameraId, CamcorderProfile.QUALITY_HIGH);
        } else if (mediaQuality == CameraConfiguration.MEDIA_QUALITY_HIGH) {
            return CamcorderProfile.get(cameraId, CamcorderProfile.QUALITY_HIGH);
        } else if (mediaQuality == CameraConfiguration.MEDIA_QUALITY_MEDIUM) {
            return CamcorderProfile.get(cameraId, CamcorderProfile.QUALITY_LOW);
        } else if (mediaQuality == CameraConfiguration.MEDIA_QUALITY_LOW) {
            return CamcorderProfile.get(cameraId, CamcorderProfile.QUALITY_LOW);
        } else if (mediaQuality == CameraConfiguration.MEDIA_QUALITY_LOWEST) {
            return CamcorderProfile.get(cameraId, CamcorderProfile.QUALITY_LOW);
        } else {
            return CamcorderProfile.get(cameraId, CamcorderProfile.QUALITY_HIGH);
        }
    }
}
 
Example 15
Source File: CameraHelper.java    From phoenix with Apache License 2.0 4 votes vote down vote up
public static CamcorderProfile getCamcorderProfile(@Configuration.MediaQuality int mediaQuality, int cameraId) {
    if (Build.VERSION.SDK_INT > 10) {
        if (mediaQuality == Configuration.MEDIA_QUALITY_HIGHEST) {
            return CamcorderProfile.get(cameraId, CamcorderProfile.QUALITY_HIGH);
        } else if (mediaQuality == Configuration.MEDIA_QUALITY_HIGH) {
            if (CamcorderProfile.hasProfile(cameraId, CamcorderProfile.QUALITY_1080P)) {
                return CamcorderProfile.get(cameraId, CamcorderProfile.QUALITY_1080P);
            } else if (CamcorderProfile.hasProfile(cameraId, CamcorderProfile.QUALITY_720P)) {
                return CamcorderProfile.get(cameraId, CamcorderProfile.QUALITY_720P);
            } else {
                return CamcorderProfile.get(cameraId, CamcorderProfile.QUALITY_HIGH);
            }
        } else if (mediaQuality == Configuration.MEDIA_QUALITY_MEDIUM) {
            if (CamcorderProfile.hasProfile(cameraId, CamcorderProfile.QUALITY_720P)) {
                return CamcorderProfile.get(cameraId, CamcorderProfile.QUALITY_720P);
            } else if (CamcorderProfile.hasProfile(cameraId, CamcorderProfile.QUALITY_480P)) {
                return CamcorderProfile.get(cameraId, CamcorderProfile.QUALITY_480P);
            } else {
                return CamcorderProfile.get(cameraId, CamcorderProfile.QUALITY_LOW);
            }
        } else if (mediaQuality == Configuration.MEDIA_QUALITY_LOW) {
            if (CamcorderProfile.hasProfile(cameraId, CamcorderProfile.QUALITY_480P)) {
                return CamcorderProfile.get(cameraId, CamcorderProfile.QUALITY_480P);
            } else {
                return CamcorderProfile.get(cameraId, CamcorderProfile.QUALITY_LOW);
            }
        } else if (mediaQuality == Configuration.MEDIA_QUALITY_LOWEST) {
            return CamcorderProfile.get(cameraId, CamcorderProfile.QUALITY_LOW);
        } else {
            return CamcorderProfile.get(cameraId, CamcorderProfile.QUALITY_HIGH);
        }
    } else {
        if (mediaQuality == Configuration.MEDIA_QUALITY_HIGHEST) {
            return CamcorderProfile.get(cameraId, CamcorderProfile.QUALITY_HIGH);
        } else if (mediaQuality == Configuration.MEDIA_QUALITY_HIGH) {
            return CamcorderProfile.get(cameraId, CamcorderProfile.QUALITY_HIGH);
        } else if (mediaQuality == Configuration.MEDIA_QUALITY_MEDIUM) {
            return CamcorderProfile.get(cameraId, CamcorderProfile.QUALITY_LOW);
        } else if (mediaQuality == Configuration.MEDIA_QUALITY_LOW) {
            return CamcorderProfile.get(cameraId, CamcorderProfile.QUALITY_LOW);
        } else if (mediaQuality == Configuration.MEDIA_QUALITY_LOWEST) {
            return CamcorderProfile.get(cameraId, CamcorderProfile.QUALITY_LOW);
        } else {
            return CamcorderProfile.get(cameraId, CamcorderProfile.QUALITY_HIGH);
        }
    }
}
 
Example 16
Source File: CameraUtils.java    From phoenix with Apache License 2.0 4 votes vote down vote up
public static CamcorderProfile getCamcorderProfile(@CameraConfig.MediaQuality int mediaQuality, int cameraId) {
    if (Build.VERSION.SDK_INT > 10) {
        if (mediaQuality == CameraConfig.MEDIA_QUALITY_HIGHEST) {
            return CamcorderProfile.get(cameraId, CamcorderProfile.QUALITY_HIGH);
        } else if (mediaQuality == CameraConfig.MEDIA_QUALITY_HIGH) {
            if (CamcorderProfile.hasProfile(cameraId, CamcorderProfile.QUALITY_1080P)) {
                return CamcorderProfile.get(cameraId, CamcorderProfile.QUALITY_1080P);
            } else if (CamcorderProfile.hasProfile(cameraId, CamcorderProfile.QUALITY_720P)) {
                return CamcorderProfile.get(cameraId, CamcorderProfile.QUALITY_720P);
            } else {
                return CamcorderProfile.get(cameraId, CamcorderProfile.QUALITY_HIGH);
            }
        } else if (mediaQuality == CameraConfig.MEDIA_QUALITY_MEDIUM) {
            if (CamcorderProfile.hasProfile(cameraId, CamcorderProfile.QUALITY_720P)) {
                return CamcorderProfile.get(cameraId, CamcorderProfile.QUALITY_720P);
            } else if (CamcorderProfile.hasProfile(cameraId, CamcorderProfile.QUALITY_480P)) {
                return CamcorderProfile.get(cameraId, CamcorderProfile.QUALITY_480P);
            } else {
                return CamcorderProfile.get(cameraId, CamcorderProfile.QUALITY_LOW);
            }
        } else if (mediaQuality == CameraConfig.MEDIA_QUALITY_LOW) {
            if (CamcorderProfile.hasProfile(cameraId, CamcorderProfile.QUALITY_480P)) {
                return CamcorderProfile.get(cameraId, CamcorderProfile.QUALITY_480P);
            } else {
                return CamcorderProfile.get(cameraId, CamcorderProfile.QUALITY_LOW);
            }
        } else if (mediaQuality == CameraConfig.MEDIA_QUALITY_LOWEST) {
            return CamcorderProfile.get(cameraId, CamcorderProfile.QUALITY_LOW);
        } else {
            return CamcorderProfile.get(cameraId, CamcorderProfile.QUALITY_HIGH);
        }
    } else {
        if (mediaQuality == CameraConfig.MEDIA_QUALITY_HIGHEST) {
            return CamcorderProfile.get(cameraId, CamcorderProfile.QUALITY_HIGH);
        } else if (mediaQuality == CameraConfig.MEDIA_QUALITY_HIGH) {
            return CamcorderProfile.get(cameraId, CamcorderProfile.QUALITY_HIGH);
        } else if (mediaQuality == CameraConfig.MEDIA_QUALITY_MEDIUM) {
            return CamcorderProfile.get(cameraId, CamcorderProfile.QUALITY_LOW);
        } else if (mediaQuality == CameraConfig.MEDIA_QUALITY_LOW) {
            return CamcorderProfile.get(cameraId, CamcorderProfile.QUALITY_LOW);
        } else if (mediaQuality == CameraConfig.MEDIA_QUALITY_LOWEST) {
            return CamcorderProfile.get(cameraId, CamcorderProfile.QUALITY_LOW);
        } else {
            return CamcorderProfile.get(cameraId, CamcorderProfile.QUALITY_HIGH);
        }
    }
}
 
Example 17
Source File: VideoOverlay.java    From backgroundvideo with GNU General Public License v3.0 4 votes vote down vote up
public void Start(String filePath) throws Exception {
    if (this.mRecordingState == RecordingState.STARTED) {
        Log.w(TAG, "Already Recording");
        return;
    }

    if (!TextUtils.isEmpty(filePath)) {
        this.mFilePath = filePath;
    }

    attachView();

    if (this.mRecordingState == RecordingState.INITIALIZING) {
        this.mStartWhenInitialized = true;
        return;
    }

    if (TextUtils.isEmpty(mFilePath)) {
        throw new IllegalArgumentException("Filename for recording must be set");
    }

    initializeCamera();

    if (mCamera == null) {
        this.detachView();
        throw new NullPointerException("Cannot start recording, we don't have a camera!");
    }

    // Set camera parameters
    Camera.Parameters cameraParameters = mCamera.getParameters();
    mCamera.stopPreview(); //Apparently helps with freezing issue on some Samsung devices.
    mCamera.unlock();

    try {
        mRecorder = new MediaRecorder();
        mRecorder.setCamera(mCamera);

        CamcorderProfile profile;
        if (CamcorderProfile.hasProfile(mCameraId, CamcorderProfile.QUALITY_LOW)) {
            profile = CamcorderProfile.get(mCameraId, CamcorderProfile.QUALITY_LOW);
        } else {
            profile = CamcorderProfile.get(mCameraId, CamcorderProfile.QUALITY_HIGH);
        }

        Camera.Size lowestRes = CameraHelper.getLowestResolution(cameraParameters);
        profile.videoFrameWidth = lowestRes.width;
        profile.videoFrameHeight = lowestRes.height;

        mRecorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);
        if (mRecordAudio) {
            // With audio
            mRecorder.setAudioSource(MediaRecorder.AudioSource.CAMCORDER);
            mRecorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
            mRecorder.setVideoFrameRate(profile.videoFrameRate);
            mRecorder.setVideoSize(profile.videoFrameWidth, profile.videoFrameHeight);
            mRecorder.setVideoEncodingBitRate(profile.videoBitRate);
            mRecorder.setAudioEncodingBitRate(profile.audioBitRate);
            mRecorder.setAudioChannels(profile.audioChannels);
            mRecorder.setAudioSamplingRate(profile.audioSampleRate);
            mRecorder.setVideoEncoder(profile.videoCodec);
            mRecorder.setAudioEncoder(profile.audioCodec);
        } else {
            // Without audio
            mRecorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
            mRecorder.setVideoFrameRate(profile.videoFrameRate);
            mRecorder.setVideoSize(profile.videoFrameWidth, profile.videoFrameHeight);
            mRecorder.setVideoEncodingBitRate(profile.videoBitRate);
            mRecorder.setVideoEncoder(profile.videoCodec);
        }

        mRecorder.setOutputFile(filePath);
        mRecorder.setOrientationHint(mOrientation);
        mRecorder.prepare();
        Log.d(TAG, "Starting recording");
        mRecorder.start();
    } catch (Exception e) {
        this.releaseCamera();
        Log.e(TAG, "Could not start recording! MediaRecorder Error", e);
        throw e;
    }
}
 
Example 18
Source File: CameraActivity.java    From cordova-plugin-camera-preview with MIT License 4 votes vote down vote up
public void startRecord(final String filePath, final String camera, final int width, final int height, final int quality, final boolean withFlash){
  Log.d(TAG, "CameraPreview startRecord camera: " + camera + " width: " + width + ", height: " + height + ", quality: " + quality);
  Activity activity = getActivity();
  muteStream(true, activity);
  if (this.mRecordingState == RecordingState.STARTED) {
    Log.d(TAG, "Already Recording");
    return;
  }

  this.recordFilePath = filePath;
  int mOrientationHint = calculateOrientationHint();
  int videoWidth = 0;//set whatever
  int videoHeight = 0;//set whatever

  Camera.Parameters cameraParams = mCamera.getParameters();
  if (withFlash) {
    cameraParams.setFlashMode(withFlash ? Camera.Parameters.FLASH_MODE_TORCH : Camera.Parameters.FLASH_MODE_OFF);
    mCamera.setParameters(cameraParams);
    mCamera.startPreview();
  }

  mCamera.unlock();
  mRecorder = new MediaRecorder();

  try {
    mRecorder.setCamera(mCamera);

    CamcorderProfile profile;
    if (CamcorderProfile.hasProfile(defaultCameraId, CamcorderProfile.QUALITY_HIGH)) {
      profile = CamcorderProfile.get(defaultCameraId, CamcorderProfile.QUALITY_HIGH);
    } else {
      if (CamcorderProfile.hasProfile(defaultCameraId, CamcorderProfile.QUALITY_480P)) {
        profile = CamcorderProfile.get(defaultCameraId, CamcorderProfile.QUALITY_480P);
      } else {
        if (CamcorderProfile.hasProfile(defaultCameraId, CamcorderProfile.QUALITY_720P)) {
          profile = CamcorderProfile.get(defaultCameraId, CamcorderProfile.QUALITY_720P);
        } else {
          if (CamcorderProfile.hasProfile(defaultCameraId, CamcorderProfile.QUALITY_1080P)) {
            profile = CamcorderProfile.get(defaultCameraId, CamcorderProfile.QUALITY_1080P);
          } else {
            profile = CamcorderProfile.get(defaultCameraId, CamcorderProfile.QUALITY_LOW);
          }
        }
      }
    }


    mRecorder.setAudioSource(MediaRecorder.AudioSource.VOICE_RECOGNITION);
    mRecorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);
    mRecorder.setProfile(profile);
    mRecorder.setOutputFile(filePath);
    mRecorder.setOrientationHint(mOrientationHint);

    mRecorder.prepare();
    Log.d(TAG, "Starting recording");
    mRecorder.start();
    eventListener.onStartRecordVideo();
  } catch (IOException e) {
    eventListener.onStartRecordVideoError(e.getMessage());
  }
}
 
Example 19
Source File: VideoModule.java    From Camera2 with Apache License 2.0 4 votes vote down vote up
private void readVideoPreferences()
{
    // The preference stores values from ListPreference and is thus string type for all values.
    // We need to convert it to int manually.
    SettingsManager settingsManager = mActivity.getSettingsManager();
    String videoQualityKey = isCameraFrontFacing() ? Keys.KEY_VIDEO_QUALITY_FRONT
            : Keys.KEY_VIDEO_QUALITY_BACK;
    String videoQuality = settingsManager
            .getString(SettingsManager.SCOPE_GLOBAL, videoQualityKey);
    int quality = SettingsUtil.getVideoQuality(videoQuality, mCameraId);
    Log.d(TAG, "Selected video quality for '" + videoQuality + "' is " + quality);

    // Set video quality.
    Intent intent = mActivity.getIntent();
    if (intent.hasExtra(MediaStore.EXTRA_VIDEO_QUALITY))
    {
        int extraVideoQuality =
                intent.getIntExtra(MediaStore.EXTRA_VIDEO_QUALITY, 0);
        if (extraVideoQuality > 0)
        {
            quality = CamcorderProfile.QUALITY_HIGH;
        } else
        {  // 0 is mms.
            quality = CamcorderProfile.QUALITY_LOW;
        }
    }

    // Set video duration limit. The limit is read from the preference,
    // unless it is specified in the intent.
    if (intent.hasExtra(MediaStore.EXTRA_DURATION_LIMIT))
    {
        int seconds =
                intent.getIntExtra(MediaStore.EXTRA_DURATION_LIMIT, 0);
        mMaxVideoDurationInMs = 1000 * seconds;
    } else
    {
        mMaxVideoDurationInMs = SettingsUtil.getMaxVideoDuration(mActivity
                .getAndroidContext());
    }

    // If quality is not supported, request QUALITY_HIGH which is always supported.
    if (CamcorderProfile.hasProfile(mCameraId, quality) == false)
    {
        quality = CamcorderProfile.QUALITY_HIGH;
    }
    mProfile = CamcorderProfile.get(mCameraId, quality);
    mPreferenceRead = true;
}