Step 1. Add the JitPack repository to your build file
Add it in your root settings.gradle at the end of repositories:
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
mavenCentral()
maven { url 'https://jitpack.io' }
}
}
Add it in your settings.gradle.kts at the end of repositories:
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
mavenCentral()
maven { url = uri("https://jitpack.io") }
}
}
Add to pom.xml
<repositories>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>
Add it in your build.sbt at the end of resolvers:
resolvers += "jitpack" at "https://jitpack.io"
Add it in your project.clj at the end of repositories:
:repositories [["jitpack" "https://jitpack.io"]]
Step 2. Add the dependency
dependencies {
implementation 'com.github.xuexiangjys:xvideo:1.0.2'
}
dependencies {
implementation("com.github.xuexiangjys:xvideo:1.0.2")
}
<dependency>
<groupId>com.github.xuexiangjys</groupId>
<artifactId>xvideo</artifactId>
<version>1.0.2</version>
</dependency>
libraryDependencies += "com.github.xuexiangjys" % "xvideo" % "1.0.2"
:dependencies [[com.github.xuexiangjys/xvideo "1.0.2"]]
一个能自动进行压缩的小视频录制库
支持自定义小视频录制时的视频质量。
支持自定义视频录制的界面。
支持自定义最大录制时长和最小录制时长。
支持自定义属性的视频压缩。
1.在项目根目录的 build.gradle 的 repositories 添加:
allprojects {
repositories {
...
maven { url "https://jitpack.io" }
}
}
2.在主项目的 build.gradle 中增加依赖。
dependencies {
···
implementation 'com.github.xuexiangjys:XVideo:1.0.2'
}
3.进行视频录制存储目录地址的设置。
/**
* 初始化xvideo的存放路径
*/
public static void initVideo() {
XVideo.setVideoCachePath(PathUtils.getExtDcimPath() + "/xvideo/");
// 初始化拍摄
XVideo.initialize(false, null);
}
1.视频录制需要CAMERA
权限和STORAGE
权限。在Android6.0机器上需要动态获取权限,推荐使用XAOP进行权限申请。
2.调用MediaRecorderActivity.startVideoRecorder
开始视频录制。
/**
* 开始录制视频
* @param requestCode 请求码
*/
@Permission({PermissionConsts.CAMERA, PermissionConsts.STORAGE})
public void startVideoRecorder(int requestCode) {
MediaRecorderConfig mediaRecorderConfig = MediaRecorderConfig.newInstance();
XVideo.startVideoRecorder(this, mediaRecorderConfig, requestCode);
}
3.MediaRecorderConfig
是视频录制的配置对象,可自定义视频的宽、高、时长以及质量等。
MediaRecorderConfig config = new MediaRecorderConfig.Builder()
.fullScreen(needFull) //是否全屏
.videoWidth(needFull ? 0 : Integer.valueOf(width)) //视频的宽
.videoHeight(Integer.valueOf(height)) //视频的高
.recordTimeMax(Integer.valueOf(maxTime)) //最大录制时间
.recordTimeMin(Integer.valueOf(minTime)) //最小录制时间
.maxFrameRate(Integer.valueOf(maxFrameRate)) //最大帧率
.videoBitrate(Integer.valueOf(bitrate)) //视频码率
.captureThumbnailsTime(1)
.build();
使用libx264进行视频压缩。由于手机本身CPU处理能力有限的问题,在手机上进行视频压缩的效率并不是很高,大约压缩的时间需要比视频拍摄本身的时长还要长一些。
LocalMediaConfig.Builder builder = new LocalMediaConfig.Builder();
final LocalMediaConfig config = builder
.setVideoPath(path) //设置需要进行视频压缩的视频路径
.captureThumbnailsTime(1)
.doH264Compress(compressMode) //设置视频压缩的模式
.setFramerate(iRate) //帧率
.setScale(fScale) //压缩比例
.build();
CompressResult compressResult = XVideo.startCompressVideo(config);
-keep class com.xuexiang.xvideo.jniinterface.** { *; }
https://github.com/mabeijianxi/small-video-record