diff --git a/src/main/java/eu/siacs/conversations/services/AttachFileToConversationRunnable.java b/src/main/java/eu/siacs/conversations/services/AttachFileToConversationRunnable.java
index 039f2dcb2..aff46ca1a 100644
--- a/src/main/java/eu/siacs/conversations/services/AttachFileToConversationRunnable.java
+++ b/src/main/java/eu/siacs/conversations/services/AttachFileToConversationRunnable.java
@@ -1,8 +1,10 @@
package eu.siacs.conversations.services;
+import android.content.SharedPreferences;
import android.net.Uri;
import android.os.Build;
import android.os.ParcelFileDescriptor;
+import android.preference.PreferenceManager;
import android.util.Log;
import net.ypresto.androidtranscoder.MediaTranscoder;
@@ -24,7 +26,7 @@ import eu.siacs.conversations.entities.Message;
import eu.siacs.conversations.persistance.FileBackend;
import eu.siacs.conversations.ui.UiCallback;
import eu.siacs.conversations.utils.Android360pFormatStrategy;
-import eu.siacs.conversations.utils.Android480pFormatStrategy;
+import eu.siacs.conversations.utils.Android720pFormatStrategy;
import eu.siacs.conversations.utils.MimeUtils;
public class AttachFileToConversationRunnable implements Runnable, MediaTranscoder.Listener {
@@ -91,8 +93,7 @@ public class AttachFileToConversationRunnable implements Runnable, MediaTranscod
mXmppConnectionService.startForcingForegroundNotification();
message.setRelativeFilePath(message.getUuid() + ".mp4");
final DownloadableFile file = mXmppConnectionService.getFileBackend().getFile(message);
- final int runtime = mXmppConnectionService.getFileBackend().getMediaRuntime(uri);
- final MediaFormatStrategy formatStrategy = runtime >= 20000 ? new Android360pFormatStrategy() : new Android480pFormatStrategy();
+ final MediaFormatStrategy formatStrategy = "720".equals(getVideoCompression()) ? new Android720pFormatStrategy() : new Android360pFormatStrategy();
file.getParentFile().mkdirs();
final ParcelFileDescriptor parcelFileDescriptor = mXmppConnectionService.getContentResolver().openFileDescriptor(uri, "r");
if (parcelFileDescriptor == null) {
@@ -168,4 +169,11 @@ public class AttachFileToConversationRunnable implements Runnable, MediaTranscod
}
}
+ public String getVideoCompression() {
+ return getPreferences().getString("video_compression", mXmppConnectionService.getResources().getString(R.string.video_compression));
+ }
+
+ protected SharedPreferences getPreferences() {
+ return PreferenceManager.getDefaultSharedPreferences(mXmppConnectionService.getApplicationContext());
+ }
}
diff --git a/src/main/java/eu/siacs/conversations/utils/Android360pFormatStrategy.java b/src/main/java/eu/siacs/conversations/utils/Android360pFormatStrategy.java
index a931136a6..50de54b75 100644
--- a/src/main/java/eu/siacs/conversations/utils/Android360pFormatStrategy.java
+++ b/src/main/java/eu/siacs/conversations/utils/Android360pFormatStrategy.java
@@ -14,8 +14,8 @@ public class Android360pFormatStrategy implements MediaFormatStrategy {
private static final int LONGER_LENGTH = 640;
private static final int SHORTER_LENGTH = 360;
- private static final int DEFAULT_VIDEO_BITRATE = 1000 * 1000; // 1000 kbit/s upper range of what YouTube recommends
- private static final int DEFAULT_AUDIO_BITRATE = 96 * 1000;
+ private static final int DEFAULT_VIDEO_BITRATE = 1000 * 1000;
+ private static final int DEFAULT_AUDIO_BITRATE = 128 * 1000;
private final int mVideoBitrate;
private final int mAudioBitrate;
private final int mAudioChannels;
diff --git a/src/main/java/eu/siacs/conversations/utils/Android480pFormatStrategy.java b/src/main/java/eu/siacs/conversations/utils/Android720pFormatStrategy.java
similarity index 87%
rename from src/main/java/eu/siacs/conversations/utils/Android480pFormatStrategy.java
rename to src/main/java/eu/siacs/conversations/utils/Android720pFormatStrategy.java
index 197cc573a..5389c4260 100644
--- a/src/main/java/eu/siacs/conversations/utils/Android480pFormatStrategy.java
+++ b/src/main/java/eu/siacs/conversations/utils/Android720pFormatStrategy.java
@@ -10,17 +10,17 @@ import net.ypresto.androidtranscoder.format.OutputFormatUnavailableException;
import eu.siacs.conversations.Config;
-public class Android480pFormatStrategy implements MediaFormatStrategy {
+public class Android720pFormatStrategy implements MediaFormatStrategy {
- private static final int LONGER_LENGTH = 854;
- private static final int SHORTER_LENGTH = 480;
- private static final int DEFAULT_VIDEO_BITRATE = 2000 * 1000; // 2000 kbit/s upper range of what YouTube recommends
- private static final int DEFAULT_AUDIO_BITRATE = 96 * 1000;
+ private static final int LONGER_LENGTH = 1280;
+ private static final int SHORTER_LENGTH = 720;
+ private static final int DEFAULT_VIDEO_BITRATE = 2000 * 1000;
+ private static final int DEFAULT_AUDIO_BITRATE = 192 * 1000;
private final int mVideoBitrate;
private final int mAudioBitrate;
private final int mAudioChannels;
- public Android480pFormatStrategy() {
+ public Android720pFormatStrategy() {
mVideoBitrate = DEFAULT_VIDEO_BITRATE;
mAudioBitrate = DEFAULT_AUDIO_BITRATE;
mAudioChannels = 2;
@@ -46,7 +46,7 @@ public class Android480pFormatStrategy implements MediaFormatStrategy {
throw new OutputFormatUnavailableException("This video is not 16:9, and is not able to transcode. (" + width + "x" + height + ")");
}
if (shorter <= SHORTER_LENGTH) {
- Log.d(Config.LOGTAG, "This video is less or equal to 360p, pass-through. (" + width + "x" + height + ")");
+ Log.d(Config.LOGTAG, "This video is less or equal to 720p, pass-through. (" + width + "x" + height + ")");
return null;
}
MediaFormat format = MediaFormat.createVideoFormat("video/avc", outWidth, outHeight);
diff --git a/src/main/res/values/arrays.xml b/src/main/res/values/arrays.xml
index 2be34fc4a..d5285e08a 100644
--- a/src/main/res/values/arrays.xml
+++ b/src/main/res/values/arrays.xml
@@ -112,4 +112,14 @@
- @string/medium
- @string/large
+
+
+ - 360
+ - 720
+
+
+
+ - @string/video_360p
+ - @string/video_720p
+
diff --git a/src/main/res/values/defaults.xml b/src/main/res/values/defaults.xml
index 35a3f0995..8e289f9c8 100644
--- a/src/main/res/values/defaults.xml
+++ b/src/main/res/values/defaults.xml
@@ -42,4 +42,5 @@
small
false
false
+ 360
diff --git a/src/main/res/values/strings.xml b/src/main/res/values/strings.xml
index a72a5d3db..9698db8bf 100644
--- a/src/main/res/values/strings.xml
+++ b/src/main/res/values/strings.xml
@@ -740,4 +740,8 @@
Media browser
History export
File omitted due to security violation.
+ Compress Videos
+ Resize and compress videos
+ SD (360p)
+ HD (720p)
diff --git a/src/main/res/xml/preferences.xml b/src/main/res/xml/preferences.xml
index 19035595a..c7f4b159c 100644
--- a/src/main/res/xml/preferences.xml
+++ b/src/main/res/xml/preferences.xml
@@ -137,6 +137,13 @@
android:key="picture_compression"
android:summary="@string/pref_picture_compression_summary"
android:title="@string/pref_picture_compression" />
+