An open API service indexing awesome lists of open source software.

https://github.com/a914-gowtham/android-video-trimmer

Helps to trim local videos with compress option on Android applications using Exoplayer and media3 libraries
https://github.com/a914-gowtham/android-video-trimmer

android-video-editor android-video-trimmer ffmpeg ffmpeg-android ffmpeg-libraries ffmpeg-wrapper ffmpegcommand trim-local-videos trimmer video-crop video-cropping video-cutter video-edit video-editing video-trim video-trimmer video-trimming videocompressor

Last synced: 4 months ago
JSON representation

Helps to trim local videos with compress option on Android applications using Exoplayer and media3 libraries

Awesome Lists containing this project

README

          

[![](https://jitpack.io/v/jZAIKO/android-video-trimmer.svg)](https://jitpack.io/#jZAIKO/android-video-trimmer)
[![](https://jitpack.io/v/a914-gowtham/android-video-trimmer.svg)](https://jitpack.io/#a914-gowtham/android-video-trimmer)

### Starting from 1.8.0 this library is using [media3](https://developer.android.com/media/media3/transformer/transformations) for media transcoding. Previously it was using [ffmpeg](https://github.com/arthenica/ffmpeg-kit?tab=readme-ov-file) which is deprecated now.

# Android-video-trimmer

##### Helps to trim local videos with many customizations on Android applications using exoplayer2 and FFmpeg [Demo app](https://github.com/a914-gowtham/android-video-trimmer/releases/1.8.1)

![](https://github.com/a914-gowtham/Android-video-trimmer/blob/master/demo.gif)

## How to use
*For a working implementation, please have a look at the Sample Project*

1. Include the library as local library project.

+ Add the dependency to your app `build.gradle` file
```gradle
// 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.gradle` file:
```gradle
allprojects {
repositories {
maven { url 'https://jitpack.io' }
}
}
```
2. Create a global variable for ActivityResultLauncher

```java
//Java
ActivityResultLauncher 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
//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");
}
```

3. Add the code for opening Trim Activity.
```java
TrimVideo.activity(String.valueOf(videoUri))
.setHideSeekBar(true)
.disableCompression() // to disable compression ui. enabled by default
.start(this,startForResult);
```

### Custom TrimTypes

#### TrimType Default:
```java
TrimVideo.activity(videoUri)
.start(this,startForResult);
```

#### TrimType Fixed Duration:
```java
TrimVideo.activity(videoUri)
.setTrimType(TrimType.FIXED_DURATION)
.setFixedDuration(30) //seconds
.start(this,startForResult);
```

#### TrimType Minimum Duration:
```java
TrimVideo.activity(videoUri)
.setTrimType(TrimType.MIN_DURATION)
.setMinDuration(30) //seconds
.start(this,startForResult);
```

#### TrimType Min-Max Duration:
```java
TrimVideo.activity(videoUri)
.setTrimType(TrimType.MIN_MAX_DURATION)
.setMinToMax(10, 30) //seconds
.start(this,startForResult);
```

## Proguard Rules
```pro
-dontwarn com.gowtham.library**
-keep class com.gowtham.library** { *; }
-keep interface com.gowtham.library** { *; }
```

## Development roadmap:

1. Currently, compression only reduces the bitRate to reduce the file size. converting video to the selected resolution is in under development.

## Compatibility

* Library - Android Nougat 7.0+ (API 24)
* Sample - Android Kitkat 4.4+ (API 19)

## License

This library is licensed under the MIT License.

## Support
Show your support by giving a star to this repository.

## Collaboration
There are many ways of improving and adding more features, so feel free to collaborate with ideas, issues and/or pull requests.