Highly flexible Android Camera which offers granular control over the video quality and filesize, while restricting recordings to be landscape only.
There are a number of issues with the default Android intent to capture videos (MediaStore.ACTION_VIDEO_CAPTURE
) which led me to create this library project:
- The default intent only accepts integer quality parameters of 0 (MMS quality) or 1 (highest available quality), using the intent extra
MediaStore.EXTRA_VIDEO_QUALITY
. - The default intent does not return the URI of the recorded file if it was specified when launching the intent.
- The default intent doesn't care wheter users capture their video in portait mode or landscape.
This library provides a full and reusable custom camera, which:
- Forces the users to rotate their device to landscape
- Allows to specify the filename, or have the library generate one for you
- Allows very granular control over the capture settings:
- Resolution
- Bitrate
- Max filesize
- Max video duration
- audio/video codec
- ...
-
Add the Jitpack repository to your project:
repositories { maven { url "https://jitpack.io" } }
-
Add a dependency on the library:
compile 'com.github.JeroenMols:LandscapeVideoCamera:1.1.2'
-
Specify the VideoCaptureActivity in your manifest:
<activity android:name="com.jmolsmobile.landscapevideocapture.VideoCaptureActivity" android:screenOrientation="sensor" > </activity>
-
Request the following permissions in your manifest:
<uses-permission android:name="android.permission.RECORD_AUDIO" /> <uses-permission android:name="android.permission.CAMERA" /> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
-
Create a CaptureConfiguration - object with the desired parameters. (optional)
CaptureConfiguration configuration = CaptureConfiguration(CaptureResolution resolution, CaptureQuality quality); CaptureConfiguration configuration = CaptureConfiguration(CaptureResolution resolution, CaptureQuality quality, int maxDurationSecs, int maxFilesizeMb); CaptureConfiguration configuration = CaptureConfiguration(int videoWidth, int videoHeight, int bitrate); CaptureConfiguration configuration = CaptureConfiguration(int videoWidth, int videoHeight, int bitrate, int maxDurationSecs, int maxFilesizeMb);
Note: When no CaptureConfiguration is specified, a default configuration will be used.
Note 2: Subclass the CaptureConfiguration class to set more advanced configurations. (codecs, audio bitrate,...)
-
Launch the
VideoCaptureActivity
for result, add the CaptureConfiguration as an parcelable extraEXTRA_CAPTURE_CONFIGURATION
and optionally add a String extraEXTRA_OUTPUT_FILENAME
.final Intent intent = new Intent(getActivity(), VideoCaptureActivity.class); intent.putExtra(VideoCaptureActivity.EXTRA_CAPTURE_CONFIGURATION, config); intent.putExtra(VideoCaptureActivity.EXTRA_OUTPUT_FILENAME, filename); startActivityForResult(intent, RESULT_CODE);
-
Check the resultcode (
RESULT_OK
,RESULT_CANCELLED
orVideoCaptureActivity.RESULT_ERROR
) and in case of success get the output filename in the intent extraEXTRA_OUTPUT_FILENAME
.
@molsjeroen