Calculate video encoding settings based on trimmed duration.

This commit is contained in:
Nicholas Tinsley
2024-01-25 15:21:00 -05:00
committed by Greyson Parrelli
parent a3438d3345
commit 6fc9055221
7 changed files with 33 additions and 21 deletions

View File

@@ -27,6 +27,7 @@ import java.io.FileInputStream;
import java.io.IOException;
import java.text.NumberFormat;
import java.util.Locale;
import java.util.concurrent.TimeUnit;
@RequiresApi(26)
public final class InMemoryTranscoder implements Closeable {
@@ -63,8 +64,13 @@ public final class InMemoryTranscoder implements Closeable {
throw new VideoSourceException("Unable to read datasource", e);
}
if (options != null && options.endTimeUs != 0) {
this.duration = TimeUnit.MICROSECONDS.toMillis(options.endTimeUs - options.startTimeUs);
} else {
this.duration = getDuration(mediaMetadataRetriever);
}
this.inSize = dataSource.getSize();
this.duration = getDuration(mediaMetadataRetriever);
this.inputBitRate = VideoBitRateCalculator.bitRate(inSize, duration);
this.targetQuality = new VideoBitRateCalculator(upperSizeLimit).getTargetQuality(duration, inputBitRate);
this.upperSizeLimit = upperSizeLimit;

View File

@@ -29,10 +29,6 @@ public final class VideoUtil {
return Math.min(duration, VideoConstants.VIDEO_MAX_RECORD_LENGTH_S);
}
public static int getMaxVideoUploadDurationInSeconds() {
return Math.toIntExact(TimeUnit.MINUTES.toSeconds(10));
}
private static Size screenSize() {
DisplayMetrics metrics = Resources.getSystem().getDisplayMetrics();
return new Size(metrics.widthPixels, metrics.heightPixels);