mirror of
https://github.com/ArcaneChat/android.git
synced 2026-07-03 14:05:24 +02:00
do not recode if filesize and bitrate are already reasonable
This commit is contained in:
@@ -790,8 +790,16 @@ public class VideoRecoder {
|
||||
return;
|
||||
}
|
||||
|
||||
// calculate video bitrate
|
||||
int MAX_BYTES = DcHelper.getInt(context, "sys.msgsize_max_recommended");
|
||||
// check if video bitrate is already reasonable
|
||||
final int MAX_KBPS = 1500000;
|
||||
final long MAX_BYTES = DcHelper.getInt(context, "sys.msgsize_max_recommended");
|
||||
long inBytes = new File(inPath).length();
|
||||
if (inBytes > 0 && inBytes <= MAX_BYTES && vei.originalVideoBitrate <= MAX_KBPS*2 /*be tolerant as long the file size matches*/) {
|
||||
Log.i(TAG, String.format("recoding for %s is not needed, %d bytes and %d kbps are ok", inPath, inBytes, vei.originalVideoBitrate));
|
||||
return;
|
||||
}
|
||||
|
||||
// calculate new video bitrate, sth. between 200 kbps and 1500 kbps
|
||||
long resultDurationMs = (long) vei.originalDurationMs;
|
||||
long maxVideoBytes = MAX_BYTES - vei.originalAudioBytes - resultDurationMs /*10 kbps codec overhead*/;
|
||||
vei.resultVideoBitrate = (int) (maxVideoBytes / Math.max(1, resultDurationMs / 1000) * 8);
|
||||
@@ -800,7 +808,7 @@ public class VideoRecoder {
|
||||
vei.resultVideoBitrate = 200000;
|
||||
} else if (vei.resultVideoBitrate > 500000) {
|
||||
if (resultDurationMs < 30 * 1000) {
|
||||
vei.resultVideoBitrate = 1500000; // ~ 12 MB/minute, plus Audio
|
||||
vei.resultVideoBitrate = MAX_KBPS; // ~ 12 MB/minute, plus Audio
|
||||
} else if (resultDurationMs < 60 * 1000) {
|
||||
vei.resultVideoBitrate = 1000000; // ~ 8 MB/minute, plus Audio
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user