Skip to content
This repository was archived by the owner on Sep 23, 2024. It is now read-only.

Commit 0a6db50

Browse files
AbandonedCartpixincreate
authored andcommitted
Reduce media size restrictions and compression
1 parent 2668055 commit 0a6db50

File tree

4 files changed

+34
-14
lines changed

4 files changed

+34
-14
lines changed

app/src/main/java/org/thoughtcrime/securesms/mediasend/camerax/CameraXUtil.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ public static CameraSelector toCameraSelector(@CameraSelector.LensFacing int cam
129129

130130
public static int getIdealResolution(int displayWidth, int displayHeight) {
131131
int maxDisplay = Math.max(displayWidth, displayHeight);
132-
return Math.max(maxDisplay, 1920);
132+
return Math.max(maxDisplay, 12000);
133133
}
134134

135135
public static @NonNull Size buildResolutionForRatio(int longDimension, @NonNull Rational ratio, boolean isPortrait) {
@@ -190,7 +190,7 @@ private static boolean shouldCropImage(@NonNull ImageProxy image) {
190190
private static byte[] toJpegBytes(@NonNull Bitmap bitmap) throws IOException {
191191
ByteArrayOutputStream out = new ByteArrayOutputStream();
192192

193-
if (!bitmap.compress(Bitmap.CompressFormat.JPEG, 80, out)) {
193+
if (!bitmap.compress(Bitmap.CompressFormat.JPEG, 100, out)) {
194194
throw new IOException("Failed to compress bitmap.");
195195
}
196196

app/src/main/java/org/thoughtcrime/securesms/mms/MediaConstraints.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,11 @@ public static MediaConstraints getPushMediaConstraints(@Nullable SentMediaQualit
3838
public abstract int getImageMaxSize(Context context);
3939

4040
public TranscodingPreset getVideoTranscodingSettings() {
41-
return TranscodingPreset.LEVEL_1;
41+
return TranscodingPreset.LEVEL_3;
4242
}
4343

4444
public boolean isHighQuality() {
45-
return false;
45+
return true;
4646
}
4747

4848
/**
@@ -56,7 +56,7 @@ public boolean isHighQuality() {
5656
public abstract long getVideoMaxSize(Context context);
5757

5858
public @IntRange(from = 0, to = 100) int getImageCompressionQualitySetting(@NonNull Context context) {
59-
return 70;
59+
return 100;
6060
}
6161

6262
public long getUncompressedVideoMaxSize(Context context) {

app/src/main/java/org/thoughtcrime/securesms/mms/PushMediaConstraints.java

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -107,12 +107,32 @@ public TranscodingPreset getVideoTranscodingSettings() {
107107
return LocaleRemoteConfig.getMediaQualityLevel().orElse(MediaConfig.getDefault(context));
108108
}
109109

110+
private static int[] IMAGE_DIMEN(int n) {
111+
int[] values = { 512 };
112+
for (int i = 768; i <= n; i = i + 64) {
113+
values = Arrays.copyOf(values, values.length + 1);
114+
values[values.length - 1] = i;
115+
}
116+
if (n % 16 != 0) {
117+
values = Arrays.copyOf(values, values.length + 1);
118+
values[values.length - 1] = n;
119+
}
120+
// Reverse the array into descending order
121+
int length = values.length;
122+
for (int i = 0; i < length / 2; i++) {
123+
values[i] = values[i] ^ values[length - i - 1];
124+
values[length - i - 1] = values[i] ^ values[length - i - 1];
125+
values[i] = values[i] ^ values[length - i - 1];
126+
}
127+
return values;
128+
}
129+
110130
public enum MediaConfig {
111-
LEVEL_1_LOW_MEMORY(true, 1, MB, new int[] { 768, 512 }, 70, TranscodingPreset.LEVEL_1),
131+
LEVEL_1_LOW_MEMORY(true, 1, (5 * MB), IMAGE_DIMEN(3000), 75, TranscodingPreset.LEVEL_1),
112132

113-
LEVEL_1(false, 1, MB, new int[] { 1600, 1024, 768, 512 }, 70, TranscodingPreset.LEVEL_1),
114-
LEVEL_2(false, 2, (int) (1.5 * MB), new int[] { 2048, 1600, 1024, 768, 512 }, 75, TranscodingPreset.LEVEL_2),
115-
LEVEL_3(false, 3, (int) (3 * MB), new int[] { 4096, 3072, 2048, 1600, 1024, 768, 512 }, 75, TranscodingPreset.LEVEL_3);
133+
LEVEL_1(false, 1, (10 * MB), IMAGE_DIMEN(6000), 80, TranscodingPreset.LEVEL_1),
134+
LEVEL_2(false, 2, (int) (15 * MB), IMAGE_DIMEN(9000), 90, TranscodingPreset.LEVEL_2),
135+
LEVEL_3(false, 3, (int) (20 * MB), IMAGE_DIMEN(12000), 100, TranscodingPreset.LEVEL_3);
116136

117137
private final boolean isLowMemory;
118138
private final int level;
@@ -162,7 +182,7 @@ public TranscodingPreset getVideoPreset() {
162182
}
163183

164184
public static @NonNull MediaConfig getDefault(Context context) {
165-
return Util.isLowMemory(context) ? LEVEL_1_LOW_MEMORY : LEVEL_1;
185+
return Util.isLowMemory(context) ? LEVEL_1_LOW_MEMORY : LEVEL_3;
166186
}
167187
}
168188
}

video/lib/src/main/java/org/thoughtcrime/securesms/video/videoconverter/utils/VideoConstants.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ package org.thoughtcrime.securesms.video.videoconverter.utils
77

88
import android.media.MediaFormat
99
object VideoConstants {
10-
const val AUDIO_BITRATE = 128_000
11-
const val VIDEO_BITRATE_L1 = 1_250_000
12-
const val VIDEO_BITRATE_L2 = VIDEO_BITRATE_L1
13-
const val VIDEO_BITRATE_L3 = 2_500_000
10+
const val AUDIO_BITRATE = 192_000
11+
const val VIDEO_BITRATE_L1 = 3_500_000
12+
const val VIDEO_BITRATE_L2 = 4_500_000
13+
const val VIDEO_BITRATE_L3 = 6_000_000
1414
const val VIDEO_SHORT_EDGE_SD = 480
1515
const val VIDEO_SHORT_EDGE_HD = 720
1616
const val VIDEO_LONG_EDGE_HD = 1280

0 commit comments

Comments
 (0)