Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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

License

NotificationsYou must be signed in to change notification settings

a914-gowtham/android-video-trimmer

Repository files navigation

Deprecated:

This library is deprecated, it was depended onffmpeg-kit. Since ffmpeg-kit has been removed, due to ffmpeg license issue.hereafter, users will encounter a "failed to resolve" issue.

Solution:

Replace video processing part withMedia3 library /LiTr libraryorUse ffmpeg-kit and this library locally

Sorry for the inconvenience.

Android-video-trimmer

Helps to trim local videos with many customizations on Android applications using exoplayer2 and FFmpegDemo 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 versiondependencies {   implementation'com.github.a914-gowtham:android-video-trimmer:x.y.z'}
  • Add to project's rootbuild.gradle file:
allprojects {repositories {maven { url'https://jitpack.io' }}}
  1. Create a global variable for ActivityResultLauncher
//JavaActivityResultLauncher<Intent>startForResult =registerForActivityResult(newActivityResultContracts.StartActivityForResult(),result -> {if (result.getResultCode() ==Activity.RESULT_OK &&result.getData() !=null) {Uriuri =Uri.parse(TrimVideo.getTrimmedVideoPath(result.getData()));Log.d(TAG,"Trimmed path:: " +uri);                                   }elseLogMessage.v("videoTrimResultLauncher data is null");            });
//Kotlinval 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)         }elseLogMessage.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(newCompressOption(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.UseTrimmerUtils.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(newCompressOption(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)

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 fromhttps://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 thelibrary/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.


[8]ページ先頭

©2009-2025 Movatter.jp