diff options
author | Christian Schneppe <christian@pix-art.de> | 2016-09-06 22:54:14 +0200 |
---|---|---|
committer | Christian Schneppe <christian@pix-art.de> | 2016-09-06 22:54:14 +0200 |
commit | 9b20d699b7eaddc03504b85a4f4343612aed0028 (patch) | |
tree | 9de6ad4e971a613cc134efe26fcd1f1398a19a18 /src/main | |
parent | 2fb4c16f86f273775da4fcb828976d2565dea9a2 (diff) |
detect video aspect ratio for compression
Diffstat (limited to 'src/main')
-rw-r--r-- | src/main/java/de/pixart/messenger/Config.java | 3 | ||||
-rw-r--r-- | src/main/java/de/pixart/messenger/utils/video/MediaController.java | 28 |
2 files changed, 24 insertions, 7 deletions
diff --git a/src/main/java/de/pixart/messenger/Config.java b/src/main/java/de/pixart/messenger/Config.java index d9b0cf551..66dd2bfc9 100644 --- a/src/main/java/de/pixart/messenger/Config.java +++ b/src/main/java/de/pixart/messenger/Config.java @@ -78,9 +78,10 @@ public final class Config { public static final Bitmap.CompressFormat AVATAR_FORMAT = Bitmap.CompressFormat.JPEG; public static final int IMAGE_SIZE = 1920; + public static final int VIDEO_SIZE = 640; public static final Bitmap.CompressFormat IMAGE_FORMAT = Bitmap.CompressFormat.JPEG; public static final int IMAGE_QUALITY = 75; - public static final int VIDEO_BITRATE = 250000; + public static final int VIDEO_BITRATE = 500000; public static final int IMAGE_MAX_SIZE = 524288; //512 KiB public static final int VIDEO_MAX_SIZE = 5242880; //5 MiB public static final int FILE_MAX_SIZE = 1048576; //1 MiB diff --git a/src/main/java/de/pixart/messenger/utils/video/MediaController.java b/src/main/java/de/pixart/messenger/utils/video/MediaController.java index 61826f9db..7af113931 100644 --- a/src/main/java/de/pixart/messenger/utils/video/MediaController.java +++ b/src/main/java/de/pixart/messenger/utils/video/MediaController.java @@ -28,6 +28,8 @@ public class MediaController { private final static int PROCESSOR_TYPE_TI = 5; private static volatile MediaController Instance = null; private boolean videoConvertFirstWrite = true; + private int resultHeight = 0; + private int resultWidth = 0; public static MediaController getInstance() { MediaController localInstance = Instance; @@ -191,18 +193,32 @@ public class MediaController { int video_height = Integer.parseInt(height); int video_width = Integer.parseInt(width); - Log.d(Config.LOGTAG, "Video dimensions: height: " + height + " width: " + width + "rotation: " + rotation); - long startTime = -1; long endTime = -1; - int resultWidth = 640; - int resultHeight = 360; - int rotationValue = Integer.valueOf(rotation); int originalWidth = Integer.valueOf(width); int originalHeight = Integer.valueOf(height); - double ratio = video_width/video_height; + float ratio = (float)video_width / (float)video_height; // 16:9 = 1,7778, 4:3 = 1,3333 + + if (video_height > video_width) { + resultHeight = Config.VIDEO_SIZE; + resultWidth = Math.round(resultHeight * ratio); + } else if (video_width > video_height) { + resultWidth = Config.VIDEO_SIZE; + resultHeight = Math.round(resultWidth / ratio); + } + + if (resultHeight > originalHeight) { + resultHeight = originalHeight; + } + + if (resultWidth > originalWidth) { + resultWidth = originalWidth; + } + + Log.d(Config.LOGTAG, "Video dimensions: height: " + video_height + " width: " + video_width + " rotation: " + rotation + " ratio: " + ratio); + Log.d(Config.LOGTAG, "Video dimensions: Result height: " + resultHeight + " Result width: " + resultWidth + " rotation: " + rotation + " ratio: " + ratio); int bitrate = Config.VIDEO_BITRATE; int rotateRender = 0; |