a914-gowtham / android-video-trimmer

Helps to trim local videos with compress option on Android applications using Exoplayer 2 and FFmpeg.
Other
362 stars 115 forks source link
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

Android-video-trimmer

Helps to trim local videos with many customizations on Android applications using exoplayer2 and FFmpeg Demo app

How to use

For a working implementation, please have a look at the Sample Project

  1. Include the library as local library project.
    //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");
    }   
  1. Add the code for opening Trim Activity.
    TrimVideo.activity(String.valueOf(videoUri))
          .setHideSeekBar(true)
          .start(this,startForResult);

Using Different Modes (Ordered By Output Speed):

Default Mode:

TrimVideo.activity(String.valueOf(videoUri))
          .setHideSeekBar(true)
          .start(this,startForResult);
  1. Fastest processing, No losses in quality((no compression), will be low accurate(2-3 secs)

Accuracy Mode:

TrimVideo.activity(String.valueOf(videoUri))
          .setAccurateCut(true) 
          .setHideSeekBar(true)
          .start(this,startForResult);
  1. Faster processing, No losses in quality(no compression), accurate trimming.

Video Compress Mode:

.setCompressOption(new CompressOption(frameRate,bitRate,width,height))  //pass empty constructor for default compressoption

Customization

Hide Player Seekbar:

.setHideSeekBar(true) //default value is false 

Custom TrimTypes

TrimType Default:

TrimVideo.activity(videoUri)
          .start(this,startForResult);

TrimType Fixed Duration:

TrimVideo.activity(videoUri)
          .setTrimType(TrimType.FIXED_DURATION)
          .setFixedDuration(30) //seconds
          .start(this,startForResult);

TrimType Minimum Duration:

TrimVideo.activity(videoUri)
          .setTrimType(TrimType.MIN_DURATION)
          .setMinDuration(30) //seconds
          .start(this,startForResult);

TrimType Min-Max Duration:

TrimVideo.activity(videoUri)
          .setTrimType(TrimType.MIN_MAX_DURATION)
          .setMinToMax(10, 30)  //seconds
          .start(this,startForResult);

Proguard Rules

-dontwarn com.gowtham.library**
-keep class com.gowtham.library** { *; }
-keep interface com.gowtham.library** { *; }

Compatibility

License

This library is licensed under the MIT License.

FFmpeg Notice

This library uses FFmpeg, which is licensed under the LGPL v3.0.

Obtaining FFmpeg Source Code

You can obtain the source code for FFmpeg from https://github.com/arthenica/ffmpeg-kit

Relinking Instructions

If you wish to replace or modify the FFmpeg library used in this project, follow these steps:

  1. Obtain the modified version of FFmpeg.
  2. Replace the existing FFmpeg library maven url in the library/build.gradle directory.
  3. Rebuild the project.

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.