XVideo
A video recording library that can compress automatically
About me
Characteristics of the
-
You can customize the video quality for small video recording.
-
Supports custom video recording.
-
You can customize the maximum and minimum recording duration.
-
Supports video compression with custom properties.
Demo (star support)
Add Gradle dependencies
1. Add build.gradle repositories to the project root directory:
allprojects {
repositories {
...
maven { url "https://jitpack.io" }
}
}
Copy the code
2. Add dependencies to build. Gradle for the main project.
Dependencies {... implementation 'com. Making. Xuexiangjys: XVideo: 1.0.1'}Copy the code
3. Set the video recording directory address.
Public static void initVideo() {xVide.setVideocachePath (pathUtils.geTextDcimpath () + "/xvideo/"); Xvideo.initialize (false, null); }Copy the code
Video recording
1. Video recording requires CAMERA permission and STORAGE permission. On Android6.0 machines need to dynamically obtain permissions, XAOP is recommended for permission application.
2. Call MediaRecorderActivity. StartVideoRecorder start video recording.
/** * start recording video * @param requestCode requestCode */ @permission ({permissionconsts.camera, PermissionConsts.STORAGE}) public void startVideoRecorder(int requestCode) { MediaRecorderConfig mediaRecorderConfig = MediaRecorderConfig.newInstance(); XVideo.startVideoRecorder(this, mediaRecorderConfig, requestCode); }Copy the code
3.MediaRecorderConfig is a video recording configuration object. You can customize the width, height, duration, and quality of a video.
MediaRecorderConfig config = new MediaRecorderConfig. Builder (). FullScreen (needFull) / / whether the full screen. VideoWidth (needFull? Zero: Integer.valueof (width)) // video width.videoheight (integer.valueof (height)) // videoHeight.recordtimemax (integer.valueof (maxTime)) RecordTimeMin (integer.valueof (minTime)) // Minimum recording time. MaxFrameRate (integer.valueof (maxFrameRate)) // Maximum frame rate .videobitrate (integer.valueof (bitrate)) // videoBitrate.capturethumbnailstime (1).build();Copy the code
Video compression
Use libx264 for video compression. Due to the limited CPU processing capacity of mobile phones, the efficiency of video compression on mobile phones is not very high, and the compression time needs to be longer than the video itself.
LocalMediaConfig.Builder builder = new LocalMediaConfig.Builder(); Final LocalMediaConfig config = Builder.setVideopath (path) // Set the video path to compress the video. CaptureThumbnailsTime (1) .doh264compress (compressMode) // Sets the video compression mode. SetFramerate (iRate) // frame rate.setScale (fScale) // Compression ratio.build(); CompressResult compressResult = XVideo.startCompressVideo(config);Copy the code
Confuse configuration
-keep class com.xuexiang.xvideo.jniinterface.** { *; }
Copy the code
Special thanks to
Github.com/mabeijianxi…
Wechat official account
More information, welcome to wechat search public number: [My Android open source journey]