From c2105dfe4667426d5b22c107d08a51c51ccccc10 Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Mon, 18 Sep 2017 11:54:14 +0200 Subject: [PATCH] use lower resolution for videos longer than 8s --- .../siacs/conversations/persistance/FileBackend.java | 10 ++++++++++ .../conversations/services/XmppConnectionService.java | 7 +++++-- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/main/java/eu/siacs/conversations/persistance/FileBackend.java b/src/main/java/eu/siacs/conversations/persistance/FileBackend.java index 081d924f0..d74487a34 100644 --- a/src/main/java/eu/siacs/conversations/persistance/FileBackend.java +++ b/src/main/java/eu/siacs/conversations/persistance/FileBackend.java @@ -787,6 +787,16 @@ public class FileBackend { } + public int getMediaRuntime(Uri uri) { + try { + MediaMetadataRetriever mediaMetadataRetriever = new MediaMetadataRetriever(); + mediaMetadataRetriever.setDataSource(mXmppConnectionService,uri); + return Integer.parseInt(mediaMetadataRetriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_DURATION)); + } catch (IllegalArgumentException e) { + return 0; + } + } + private Dimensions getImageDimensions(File file) { BitmapFactory.Options options = new BitmapFactory.Options(); options.inJustDecodeBounds = true; diff --git a/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java b/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java index ae138ffb4..603e40c07 100644 --- a/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java +++ b/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java @@ -41,6 +41,7 @@ import net.java.otr4j.session.SessionID; import net.java.otr4j.session.SessionImpl; import net.java.otr4j.session.SessionStatus; import net.ypresto.androidtranscoder.MediaTranscoder; +import net.ypresto.androidtranscoder.format.MediaFormatStrategy; import net.ypresto.androidtranscoder.format.MediaFormatStrategyPresets; import org.openintents.openpgp.IOpenPgpService2; @@ -518,6 +519,9 @@ public class XmppConnectionService extends Service { Log.d(Config.LOGTAG,"processing file as video"); message.setRelativeFilePath(message.getUuid() + ".mp4"); final DownloadableFile file = getFileBackend().getFile(message); + final int runtime = getFileBackend().getMediaRuntime(uri); + MediaFormatStrategy formatStrategy = runtime >= 8000 ? MediaFormatStrategyPresets.createExportPreset960x540Strategy() : MediaFormatStrategyPresets.createAndroid720pStrategy(); + Log.d(Config.LOGTAG,"runtime "+runtime); file.getParentFile().mkdirs(); ParcelFileDescriptor parcelFileDescriptor = getContentResolver().openFileDescriptor(uri, "r"); FileDescriptor fileDescriptor = parcelFileDescriptor.getFileDescriptor(); @@ -560,8 +564,7 @@ public class XmppConnectionService extends Service { processAsFile(); } }; - MediaTranscoder.getInstance().transcodeVideo(fileDescriptor, file.getAbsolutePath(), - MediaFormatStrategyPresets.createAndroid720pStrategy(), listener); + MediaTranscoder.getInstance().transcodeVideo(fileDescriptor, file.getAbsolutePath(), formatStrategy, listener); } @Override