Skip to content

Commit

Permalink
video strech issue fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
Gowtham committed May 1, 2021
1 parent b4e0616 commit 944bbb6
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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")) {
Expand Down
13 changes: 13 additions & 0 deletions library/src/main/java/com/gowtham/library/utils/TrimmerUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 944bbb6

Please sign in to comment.