Giter VIP home page Giter VIP logo

a914-gowtham / android-video-trimmer Goto Github PK

View Code? Open in Web Editor NEW
356.0 5.0 115.0 191.68 MB

Helps to trim local videos with compress option on Android applications using Exoplayer 2 and FFmpeg.

License: MIT License

Java 97.77% Kotlin 2.23%
video-trim video-trimmer video-trimming ffmpeg ffmpeg-android ffmpeg-wrapper video-editing android-video-trimmer ffmpeg-libraries ffmpegcommand video-cutter video-crop video-cropping trimmer video-edit android-video-editor trim-local-videos videocompressor

android-video-trimmer's Introduction

MIT licensed

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.
// 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:
allprojects {
	repositories {
		maven { url 'https://jitpack.io' }
	}
}
  1. 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");
    }   
  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
  • FrameRate Recommeded frameRate is 30
  • BitRate 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
  1. Video compressing process will take more time and duration will be accurate
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))   
   */

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

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

Thanks to

TanerSener

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.