Skip to content

Commit

Permalink
feat: Enhanced Video Bitrate
Browse files Browse the repository at this point in the history
Co-authored-by: dic1911 <[email protected]>
  • Loading branch information
omg-xtao and dic1911 committed Jan 2, 2025
1 parent 605e3c2 commit 60a9208
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@
import tw.nekomimi.nekogram.NekoConfig;
import tw.nekomimi.nekogram.NekoXConfig;
import tw.nekomimi.nekogram.SaveToDownloadReceiver;
import xyz.nextalone.nagram.NaConfig;
import xyz.nextalone.nagram.helper.AudioEnhance;

public class MediaController implements AudioManager.OnAudioFocusChangeListener, NotificationCenter.NotificationCenterDelegate, SensorEventListener {
Expand Down Expand Up @@ -678,6 +679,8 @@ public SearchImage clone() {
}
};

public final static int VIDEO_BITRATE_2160 = 28400_000;
public final static int VIDEO_BITRATE_1440 = 14000_000;
public final static int VIDEO_BITRATE_1080 = 6800_000;
public final static int VIDEO_BITRATE_720 = 2621_440;
public final static int VIDEO_BITRATE_480 = 1000_000;
Expand Down Expand Up @@ -5799,6 +5802,18 @@ public static int makeVideoBitrate(int originalHeight, int originalWidth, int or
compressFactor = 0.6f;
minCompressFactor = 0.7f;
}
if (NaConfig.INSTANCE.getEnhancedVideoBitrate().Bool()) {
int size = Math.min(height, width);
if (size >= 2160) {
maxBitrate = VIDEO_BITRATE_2160;
} else if (size >= 1440) {
maxBitrate = VIDEO_BITRATE_1440;
} else if (size >= 1080) {
maxBitrate = VIDEO_BITRATE_1440;
} else if (size >= 720) {
maxBitrate = VIDEO_BITRATE_1080;
}
}
int remeasuredBitrate = (int) (originalBitrate / (Math.min(originalHeight / (float) (height), originalWidth / (float) (width))));
remeasuredBitrate *= compressFactor;
int minBitrate = (int) (getVideoBitrateWithFactor(minCompressFactor) / (1280f * 720f / (width * height)));
Expand Down
15 changes: 14 additions & 1 deletion TMessagesProj/src/main/java/org/telegram/ui/PhotoViewer.java
Original file line number Diff line number Diff line change
Expand Up @@ -20446,9 +20446,15 @@ private Size calculateResultVideoSize() {
maxSize = 1280.0f;
break;
case 3:
default:
maxSize = 1920.0f;
break;
case 4:
maxSize = 2560.0f;
break;
case 5:
default:
maxSize = 4096.0f;
break;
}
float scale = originalWidth > originalHeight ? maxSize / originalWidth : maxSize / originalHeight;
if (selectedCompression == compressionsCount - 1 && scale >= 1f) {
Expand Down Expand Up @@ -20728,6 +20734,13 @@ private void updateCompressionsCount(int h, int w) {
} else {
compressionsCount = 1;
}
if (NaConfig.INSTANCE.getEnhancedVideoBitrate().Bool()) {
if (maxSize > 2560) {
compressionsCount = 6;
} else if (maxSize > 1920) {
compressionsCount = 5;
}
}
}

private void updateAccessibilityOverlayVisibility() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ public class NekoExperimentalSettingsActivity extends BaseNekoXSettingsActivity
private final AbstractConfigCell fakeHighPerformanceDeviceRow = cellGroup.appendCell(new ConfigCellTextCheck(NaConfig.INSTANCE.getFakeHighPerformanceDevice()));
private final AbstractConfigCell disableEmojiDrawLimitRow = cellGroup.appendCell(new ConfigCellTextCheck(NaConfig.INSTANCE.getDisableEmojiDrawLimit()));
private final AbstractConfigCell sendMp4DocumentAsVideoRow = cellGroup.appendCell(new ConfigCellTextCheck(NaConfig.INSTANCE.getSendMp4DocumentAsVideo()));
private final AbstractConfigCell enhancedVideoBitrateRow = cellGroup.appendCell(new ConfigCellTextCheck(NaConfig.INSTANCE.getEnhancedVideoBitrate()));
private final AbstractConfigCell hideProxySponsorChannelRow = cellGroup.appendCell(new ConfigCellTextCheck(NekoConfig.hideProxySponsorChannel));
private final AbstractConfigCell hideSponsoredMessageRow = cellGroup.appendCell(new ConfigCellTextCheck(NekoConfig.hideSponsoredMessage));
private final AbstractConfigCell ignoreBlockedRow = cellGroup.appendCell(new ConfigCellTextCheck(NekoConfig.ignoreBlocked, LocaleController.getString("IgnoreBlockedAbout")));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -670,6 +670,12 @@ object NaConfig {
ConfigItem.configTypeBool,
false
)
val enhancedVideoBitrate =
addConfig(
"EnhancedVideoBitrate",
ConfigItem.configTypeBool,
false
)

private fun addConfig(
k: String,
Expand Down
1 change: 1 addition & 0 deletions TMessagesProj/src/main/res/values-zh-rCN/strings_na.xml
Original file line number Diff line number Diff line change
Expand Up @@ -168,4 +168,5 @@
<string name="DefaultHlsVideoQuality">默认 Hls 视频质量</string>
<string name="DisableBotOpenButton">禁用 Bot 的打开小程序按钮</string>
<string name="CustomTitleUserName">使用用户昵称作为标题</string>
<string name="EnhancedVideoBitrate">改善上传视频画质</string>
</resources>
1 change: 1 addition & 0 deletions TMessagesProj/src/main/res/values/strings_na.xml
Original file line number Diff line number Diff line change
Expand Up @@ -169,4 +169,5 @@
<string name="DefaultHlsVideoQuality">Default Hls Video Quality</string>
<string name="DisableBotOpenButton">Disable Bot Open Button</string>
<string name="CustomTitleUserName">Use user nickname as Title</string>
<string name="EnhancedVideoBitrate">Enhanced shared video bitrate</string>
</resources>

0 comments on commit 60a9208

Please sign in to comment.