Starting from 1.8.0 this library is using media3 for media transcoding. Previously it was using ffmpeg which is deprecated now.
Helps to trim local videos with many customizations on Android applications using exoplayer2 and FFmpeg Demo app
For a working implementation, please have a look at the Sample Project
- Include the library as local library project.
- Add the dependency to your app
build.gradlefile
// replace x.y.z with latest available jitpack version
dependencies {
implementation 'com.github.a914-gowtham:android-video-trimmer:x.y.z'
}- Add to project's root
build.gradlefile:
allprojects {
repositories {
maven { url 'https://jitpack.io' }
}
}- Create a global variable for ActivityResultLauncher
//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");
} - Add the code for opening Trim Activity.
TrimVideo.activity(String.valueOf(videoUri))
.setHideSeekBar(true)
.disableCompression() // to disable compression ui. enabled by default
.start(this,startForResult);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** { *; }- Currently, compression only reduces the bitRate to reduce the file size. converting video to the selected resolution is in under development.
- Library - Android Nougat 7.0+ (API 24)
- Sample - Android Kitkat 4.4+ (API 19)
This library is licensed under the MIT License.
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.
