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

Commit

Permalink
Reduce media size restrictions and compression
Browse files Browse the repository at this point in the history
  • Loading branch information
AbandonedCart authored and pixincreate committed Aug 10, 2024
1 parent 2668055 commit 0a6db50
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ public static CameraSelector toCameraSelector(@CameraSelector.LensFacing int cam

public static int getIdealResolution(int displayWidth, int displayHeight) {
int maxDisplay = Math.max(displayWidth, displayHeight);
return Math.max(maxDisplay, 1920);
return Math.max(maxDisplay, 12000);
}

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

if (!bitmap.compress(Bitmap.CompressFormat.JPEG, 80, out)) {
if (!bitmap.compress(Bitmap.CompressFormat.JPEG, 100, out)) {
throw new IOException("Failed to compress bitmap.");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,11 @@ public static MediaConstraints getPushMediaConstraints(@Nullable SentMediaQualit
public abstract int getImageMaxSize(Context context);

public TranscodingPreset getVideoTranscodingSettings() {
return TranscodingPreset.LEVEL_1;
return TranscodingPreset.LEVEL_3;
}

public boolean isHighQuality() {
return false;
return true;
}

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

public @IntRange(from = 0, to = 100) int getImageCompressionQualitySetting(@NonNull Context context) {
return 70;
return 100;
}

public long getUncompressedVideoMaxSize(Context context) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,12 +107,32 @@ public TranscodingPreset getVideoTranscodingSettings() {
return LocaleRemoteConfig.getMediaQualityLevel().orElse(MediaConfig.getDefault(context));
}

private static int[] IMAGE_DIMEN(int n) {
int[] values = { 512 };
for (int i = 768; i <= n; i = i + 64) {
values = Arrays.copyOf(values, values.length + 1);
values[values.length - 1] = i;
}
if (n % 16 != 0) {
values = Arrays.copyOf(values, values.length + 1);
values[values.length - 1] = n;
}
// Reverse the array into descending order
int length = values.length;
for (int i = 0; i < length / 2; i++) {
values[i] = values[i] ^ values[length - i - 1];
values[length - i - 1] = values[i] ^ values[length - i - 1];
values[i] = values[i] ^ values[length - i - 1];
}
return values;
}

public enum MediaConfig {
LEVEL_1_LOW_MEMORY(true, 1, MB, new int[] { 768, 512 }, 70, TranscodingPreset.LEVEL_1),
LEVEL_1_LOW_MEMORY(true, 1, (5 * MB), IMAGE_DIMEN(3000), 75, TranscodingPreset.LEVEL_1),

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

private final boolean isLowMemory;
private final int level;
Expand Down Expand Up @@ -162,7 +182,7 @@ public TranscodingPreset getVideoPreset() {
}

public static @NonNull MediaConfig getDefault(Context context) {
return Util.isLowMemory(context) ? LEVEL_1_LOW_MEMORY : LEVEL_1;
return Util.isLowMemory(context) ? LEVEL_1_LOW_MEMORY : LEVEL_3;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ package org.thoughtcrime.securesms.video.videoconverter.utils

import android.media.MediaFormat
object VideoConstants {
const val AUDIO_BITRATE = 128_000
const val VIDEO_BITRATE_L1 = 1_250_000
const val VIDEO_BITRATE_L2 = VIDEO_BITRATE_L1
const val VIDEO_BITRATE_L3 = 2_500_000
const val AUDIO_BITRATE = 192_000
const val VIDEO_BITRATE_L1 = 3_500_000
const val VIDEO_BITRATE_L2 = 4_500_000
const val VIDEO_BITRATE_L3 = 6_000_000
const val VIDEO_SHORT_EDGE_SD = 480
const val VIDEO_SHORT_EDGE_HD = 720
const val VIDEO_LONG_EDGE_HD = 1280
Expand Down

0 comments on commit 0a6db50

Please sign in to comment.