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/java/de/pixart/messenger/utils/video | |
parent | 2fb4c16f86f273775da4fcb828976d2565dea9a2 (diff) |
detect video aspect ratio for compression
Diffstat (limited to 'src/main/java/de/pixart/messenger/utils/video')
-rw-r--r-- | src/main/java/de/pixart/messenger/utils/video/MediaController.java | 28 |
1 files changed, 22 insertions, 6 deletions
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; |