For a working implementation, please have a look at the Sample Project
build.gradle
file// replace x.y.z with latest available jitpack version
dependencies {
implementation 'com.github.a914-gowtham:android-video-trimmer:x.y.z'
}
build.gradle
file:
allprojects {
repositories {
maven { url 'https://jitpack.io' }
}
}
//Java
ActivityResultLauncher<Intent> startForResult = registerForActivityResult(
new ActivityResultContracts.StartActivityForResult(),
result -> {
if (result.getResultCode() == Activity.RESULT_OK &&
result.getData() != null) {
Uri uri = Uri.parse(TrimVideo.getTrimmedVideoPath(result.getData()));
Log.d(TAG, "Trimmed path:: " + uri);
} else
LogMessage.v("videoTrimResultLauncher data is null");
});
//Kotlin
val startForResult = registerForActivityResult(ActivityResultContracts.StartActivityForResult()) {
result: ActivityResult ->
if (result.resultCode == Activity.RESULT_OK &&
result.getData() != null) {
Uri uri = Uri.parse(TrimVideo.getTrimmedVideoPath(result.getData()))
Log.d(TAG, "Trimmed path:: " + uri)
}else
LogMessage.v("videoTrimResultLauncher data is null");
}
TrimVideo.activity(String.valueOf(videoUri))
.setHideSeekBar(true)
.start(this,startForResult);
TrimVideo.activity(String.valueOf(videoUri))
.setHideSeekBar(true)
.start(this,startForResult);
TrimVideo.activity(String.valueOf(videoUri))
.setAccurateCut(true)
.setHideSeekBar(true)
.start(this,startForResult);
.setCompressOption(new CompressOption(frameRate,bitRate,width,height)) //pass empty constructor for default compressoption
FrameRate
Recommeded frameRate is 30BitRate
Bitrate Can be between 150k to 1000k or 1M to 10M.Lower bitrate can reduce the quality and size of the video.
Use 1M for decent quality output Width
Width of the video output video. Height
Height of the video output video.Use TrimmerUtils.getVideoWidthHeight(this,Uri.parse(videoUri));
method to get the width and height of the video
TrimVideo.activity(String.valueOf(videoUri))
.setCompressOption(new CompressOption(30,"1M",460,320)) //pass empty constructor for default compress values
.setHideSeekBar(true)
.start(this,startForResult);
//You could divide the width and height by 2. when try to compress a large resolution videos ex:Taken from camera
/*int[] wAndh=TrimmerUtils.getVideoWidthHeight(this,Uri.parse(videoUri));
int width=wAndh[0];
int height=wAndh[1];
if(wAndh[0]>800){
width/=2;
width/=2;
.setCompressOption(new CompressOption(30,"1M",width,height))
}else
.setCompressOption(new CompressOption(30,"400k",width,height))
*/
.setHideSeekBar(true) //default value is false
TrimVideo.activity(videoUri)
.start(this,startForResult);
TrimVideo.activity(videoUri)
.setTrimType(TrimType.FIXED_DURATION)
.setFixedDuration(30) //seconds
.start(this,startForResult);
TrimVideo.activity(videoUri)
.setTrimType(TrimType.MIN_DURATION)
.setMinDuration(30) //seconds
.start(this,startForResult);
TrimVideo.activity(videoUri)
.setTrimType(TrimType.MIN_MAX_DURATION)
.setMinToMax(10, 30) //seconds
.start(this,startForResult);
-dontwarn com.gowtham.library**
-keep class com.gowtham.library** { *; }
-keep interface com.gowtham.library** { *; }
This library is licensed under the MIT License.
This library uses FFmpeg, which is licensed under the LGPL v3.0.
You can obtain the source code for FFmpeg from https://github.com/arthenica/ffmpeg-kit
If you wish to replace or modify the FFmpeg library used in this project, follow these steps:
library/build.gradle
directory.Show your support by giving a star to this repository.
There are many ways of improving and adding more features, so feel free to collaborate with ideas, issues and/or pull requests.