Skip to content

Commit c20d49c

Browse files
authored
Merge pull request #114 from a914-gowtham/master
media3 migration first commit
2 parents aae47cb + d70608d commit c20d49c

File tree

12 files changed

+284
-224
lines changed

12 files changed

+284
-224
lines changed

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@
66
This library is deprecated, it was depended on [ffmpeg-kit](https://github.com/arthenica/ffmpeg-kit?tab=readme-ov-file). Since ffmpeg-kit has been removed, due to ffmpeg license issue.
77
hereafter, users will encounter a "failed to resolve" issue.
88

9-
### Solution:
9+
### Alternates:
10+
1. https://github.com/Hassaan-Javed/gowtham-video-trimmer-fork - instead of FFmpeg, [LiTr library](https://github.com/linkedin/LiTr) is used in this fork.
11+
12+
2. Fork this repo and replace video processing part with [Media3 library](https://android-developers.googleblog.com/2025/03/media-processing-performance-jetpack-media3-transformer.html) or local FFmpeg
1013

11-
Replace video processing part with [Media3 library](https://android-developers.googleblog.com/2025/03/media-processing-performance-jetpack-media3-transformer.html) / [LiTr library](https://github.com/linkedin/LiTr)
12-
or
13-
Use ffmpeg-kit and this library locally
1414

1515
Sorry for the inconvenience.
1616

app/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ android {
55
defaultConfig {
66
applicationId "com.gowtham.videotrimmer"
77
minSdkVersion 24
8-
targetSdkVersion 34
9-
compileSdk = 34
8+
targetSdkVersion 36
9+
compileSdk = 36
1010
versionCode 1
1111
versionName "1.0"
1212
multiDexEnabled true

library/build.gradle

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ android {
1212

1313
defaultConfig {
1414
minSdkVersion 24
15-
targetSdkVersion 34
16-
compileSdk = 34
15+
targetSdkVersion 36
16+
compileSdk = 36
1717
consumerProguardFiles "consumer-rules.pro"
1818

1919
ndkVersion '22.1.7171670'
@@ -46,12 +46,14 @@ dependencies {
4646
implementation 'androidx.appcompat:appcompat:1.4.2'
4747
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
4848
implementation 'com.google.android.exoplayer:exoplayer:2.17.1'
49-
implementation 'com.arthenica:ffmpeg-kit-min:6.0-1'
5049
implementation 'com.github.bumptech.glide:glide:4.15.1'
5150
annotationProcessor 'com.github.bumptech.glide:compiler:4.15.1'
5251
implementation 'com.akexorcist:localization:1.2.9'
5352
implementation 'com.google.code.gson:gson:2.9.0'
5453
implementation "androidx.coordinatorlayout:coordinatorlayout:1.2.0"
54+
55+
implementation("androidx.media3:media3-transformer:1.8.0")
56+
5557
}
5658
repositories {
5759
mavenCentral()

library/src/main/AndroidManifest.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88

99
<application>
1010
<activity android:name=".ui.ActVideoTrimmer"
11-
android:screenOrientation="portrait"
1211
android:launchMode="singleTask"
1312
android:theme="@style/VideoTrimmerTheme"
1413
android:exported="true"/>

library/src/main/java/com/gowtham/library/ui/ActVideoTrimmer.java

Lines changed: 158 additions & 137 deletions
Large diffs are not rendered by default.

library/src/main/java/com/gowtham/library/utils/CompressOption.java

Lines changed: 27 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -2,54 +2,53 @@
22

33
public class CompressOption {
44

5-
private int frameRate=30;
6-
7-
private String bitRate="0k";
8-
9-
private int width=0;
10-
11-
private int height=0;
125

136
public CompressOption() {
147
}
158

16-
public CompressOption(int frameRate, String bitRate, int width, int height) {
17-
this.frameRate = frameRate;
18-
this.bitRate = bitRate;
19-
this.width = width;
20-
this.height = height;
21-
}
9+
private int bitRate= 0;
2210

23-
public void setFrameRate(int frameRate) {
24-
this.frameRate = frameRate;
25-
}
11+
private float compressionScale=0;
2612

27-
public void setBitRate(String bitRate) {
13+
public CompressOption(int bitRate, float compressionScaleForResolution) {
2814
this.bitRate = bitRate;
15+
this.compressionScale = compressionScaleForResolution;
2916
}
3017

31-
public int getWidth() {
32-
return width;
18+
private VideoRes videoRes= null;
19+
20+
public CompressOption(VideoRes videoRes) {
21+
this.videoRes = videoRes;
3322
}
3423

35-
public void setWidth(int width) {
36-
this.width = width;
24+
25+
private boolean isUserSelection;
26+
27+
public CompressOption(boolean isUserSelection) {
28+
this.isUserSelection = isUserSelection;
3729
}
3830

39-
public int getHeight() {
40-
return height;
31+
public void setBitRate(int bitRate) {
32+
this.bitRate = bitRate;
4133
}
4234

43-
public void setHeight(int height) {
44-
this.height = height;
35+
public float getCompressionScale() {
36+
return compressionScale;
4537
}
4638

47-
public int getFrameRate() {
48-
return frameRate;
39+
public void setCompressionScale(float compressionScale) {
40+
this.compressionScale = compressionScale;
4941
}
5042

51-
public String getBitRate() {
43+
public int getBitRate() {
5244
return bitRate;
5345
}
5446

47+
public VideoRes getVideoRes() {
48+
return videoRes;
49+
}
50+
51+
public void setVideoRes(VideoRes videoRes) {
52+
this.videoRes = videoRes;
53+
}
5554
}

library/src/main/java/com/gowtham/library/utils/TrimmerUtils.java

Lines changed: 17 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
import androidx.core.app.ActivityCompat;
1717
import androidx.core.content.ContextCompat;
18+
import androidx.core.util.Pair;
1819

1920
import com.google.gson.Gson;
2021

@@ -26,27 +27,7 @@
2627

2728
public class TrimmerUtils {
2829

29-
public static String formatCSeconds(long timeInSeconds) {
30-
long hours = timeInSeconds / 3600;
31-
long secondsLeft = timeInSeconds - hours * 3600;
32-
long minutes = secondsLeft / 60;
33-
long seconds = secondsLeft - minutes * 60;
3430

35-
String formattedTime = "";
36-
if (hours < 10)
37-
formattedTime += "0";
38-
formattedTime += hours + ":";
39-
40-
if (minutes < 10)
41-
formattedTime += "0";
42-
formattedTime += minutes + ":";
43-
44-
if (seconds < 10)
45-
formattedTime += "0";
46-
formattedTime += seconds;
47-
48-
return formattedTime;
49-
}
5031

5132
public static int getColor(Context context, int color) {
5233
return ContextCompat.getColor(context, color);
@@ -150,24 +131,31 @@ public static int getBitRate(Activity context, Uri videoPath) {
150131
}
151132

152133

153-
public static int[] getVideoWidthHeight(Activity context, Uri videoPath) {
134+
public static Pair<Integer, Integer> getVideoRes(Activity context, Uri videoUri) {
154135
try {
155-
MediaMetadataRetriever retriever = new MediaMetadataRetriever();
156-
retriever.setDataSource(context,videoPath);
157-
int width = Integer.parseInt(retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_VIDEO_WIDTH));
158-
int height = Integer.parseInt(retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_VIDEO_HEIGHT));
159-
retriever.release();
160-
return new int[]{width,height};
136+
MediaMetadataRetriever metaRetriever = new MediaMetadataRetriever();
137+
metaRetriever.setDataSource(context, videoUri);
138+
String height = metaRetriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_VIDEO_HEIGHT);
139+
String width = metaRetriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_VIDEO_WIDTH);
140+
int w = TrimmerUtils.clearNull(width).isEmpty() ? 0 : Integer.parseInt(width);
141+
int h = Integer.parseInt(height);
142+
int rotation = TrimmerUtils.getVideoRotation(context, videoUri);
143+
if (rotation == 90 || rotation == 270) {
144+
// int temp = w;
145+
// w = h;
146+
// h = temp;
147+
}
148+
return new Pair<>(w, h);
161149
} catch (Exception e) {
162150
e.printStackTrace();
163151
}
164152
return null;
165153
}
166154

167-
public static int getVideoRotation(Activity context, Uri videoPath) {
155+
public static int getVideoRotation(Activity context, Uri videoUri) {
168156
try {
169157
MediaMetadataRetriever retriever = new MediaMetadataRetriever();
170-
retriever.setDataSource(context,videoPath);
158+
retriever.setDataSource(context,videoUri);
171159
int rotation = Integer.parseInt(retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_VIDEO_ROTATION));
172160
retriever.release();
173161
return rotation;
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package com.gowtham.library.utils
2+
3+
object VideoRes {
4+
5+
const val SD_LOW= "360p"
6+
const val SD= "480p"
7+
const val HD= "720p"
8+
const val FULL_HD= "1080p"
9+
10+
}

library/src/main/java/com/gowtham/library/utils/ViewUtil.kt

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ package com.gowtham.library.utils
33
import android.content.res.Resources
44
import android.graphics.Rect
55
import android.os.Build
6+
import android.util.Log
67
import android.util.TypedValue
78
import android.view.View
8-
import androidx.core.view.doOnLayout
99

1010
object ViewUtil {
1111

@@ -15,16 +15,33 @@ object ViewUtil {
1515
Resources.getSystem().displayMetrics).toInt()
1616

1717
@JvmStatic
18-
fun systemGestureExclusionRects(viewRoot: View) {
18+
fun dpToPx(dp: Int): Int{
19+
20+
return TypedValue.applyDimension(
21+
TypedValue.COMPLEX_UNIT_DIP,
22+
dp.toFloat(),
23+
Resources.getSystem().displayMetrics).toInt()
24+
}
25+
@JvmStatic
26+
fun systemGestureExclusionRects(viewRoot: View, thumbnailViewer: View) {
27+
var rendered= false
1928
viewRoot.post {
20-
viewRoot.apply {
21-
doOnLayout {
22-
// updating exclusion rect
23-
val rects = mutableListOf<Rect>()
24-
rects.add(Rect(0,resources.displayMetrics.heightPixels-(120.toPx),width,resources.displayMetrics.heightPixels-(55.toPx)))
25-
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
26-
systemGestureExclusionRects = rects
27-
}
29+
viewRoot.addOnLayoutChangeListener { v, left, top, right, bottom, oldLeft, oldTop, oldRight, oldBottom ->
30+
if (rendered){
31+
return@addOnLayoutChangeListener
32+
}
33+
rendered= true
34+
val rects = mutableListOf<Rect>()
35+
rects.add(
36+
Rect(
37+
0,
38+
thumbnailViewer.top-20.toPx,
39+
viewRoot.width,
40+
thumbnailViewer.bottom+ 20.toPx
41+
)
42+
)
43+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
44+
viewRoot.systemGestureExclusionRects = rects
2845
}
2946
}
3047
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<vector xmlns:android="http://schemas.android.com/apk/res/android" android:autoMirrored="true" android:height="24dp" android:tint="#FFFFFF" android:viewportHeight="24" android:viewportWidth="24" android:width="24dp">
2+
3+
<path android:fillColor="@android:color/white" android:pathData="M20,11H7.83l5.59,-5.59L12,4l-8,8 8,8 1.41,-1.41L7.83,13H20v-2z"/>
4+
5+
</vector>

0 commit comments

Comments
 (0)