From 944bbb6aa940af8dbc874ade3f013e4d2dd85fbf Mon Sep 17 00:00:00 2001 From: Gowtham Date: Sun, 2 May 2021 01:46:15 +0530 Subject: [PATCH] video strech issue fixed --- .../com/gowtham/library/ui/ActVideoTrimmer.java | 11 ++++++++--- .../com/gowtham/library/utils/TrimmerUtils.java | 13 +++++++++++++ 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/library/src/main/java/com/gowtham/library/ui/ActVideoTrimmer.java b/library/src/main/java/com/gowtham/library/ui/ActVideoTrimmer.java index 5f122bb..0ca6edc 100644 --- a/library/src/main/java/com/gowtham/library/ui/ActVideoTrimmer.java +++ b/library/src/main/java/com/gowtham/library/ui/ActVideoTrimmer.java @@ -491,7 +491,7 @@ private void trimVideo() { showProcessingDialog(); String[] complexCommand; if (compressOption != null) - complexCommand = getDefaultCmd(); + complexCommand = getCompressionCmd(); else if (isAccurateCut) { //no changes in video quality //faster trimming command and given duration will be accurate @@ -528,14 +528,19 @@ private String getFileName() { return String.valueOf(newFile); } - private String[] getDefaultCmd() { + private String[] getCompressionCmd() { MediaMetadataRetriever metaRetriever = new MediaMetadataRetriever(); metaRetriever.setDataSource(String.valueOf(uri)); String height = metaRetriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_VIDEO_HEIGHT); String width = metaRetriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_VIDEO_WIDTH); int w = TrimmerUtils.clearNull(width).isEmpty() ? 0 : Integer.parseInt(width); int h = Integer.parseInt(height); - + int rotation=TrimmerUtils.getVideoRotation(this,uri); + if(rotation==90 || rotation==360){ + int temp=w; + w=h; + h=temp; + } //Default compression option if (compressOption.getWidth() != 0 || compressOption.getHeight() != 0 || !compressOption.getBitRate().equals("0k")) { diff --git a/library/src/main/java/com/gowtham/library/utils/TrimmerUtils.java b/library/src/main/java/com/gowtham/library/utils/TrimmerUtils.java index daebb4c..476feb3 100644 --- a/library/src/main/java/com/gowtham/library/utils/TrimmerUtils.java +++ b/library/src/main/java/com/gowtham/library/utils/TrimmerUtils.java @@ -160,6 +160,19 @@ public static int[] getVideoWidthHeight(Activity context, Uri videoPath) { return null; } + public static int getVideoRotation(Activity context, Uri videoPath) { + try { + MediaMetadataRetriever retriever = new MediaMetadataRetriever(); + retriever.setDataSource(context,videoPath); + int rotation = Integer.parseInt(retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_VIDEO_ROTATION)); + retriever.release(); + return rotation; + } catch (Exception e) { + e.printStackTrace(); + } + return 0; + } + public static String formatSeconds(long timeInSeconds) { long hours = timeInSeconds / 3600; long secondsLeft = timeInSeconds - hours * 3600;