From 86227d805ade08745c26ad6569daebd8d44dc4e7 Mon Sep 17 00:00:00 2001 From: Stu Leak Date: Fri, 2 Jan 2026 04:33:42 -0500 Subject: [PATCH] fix: add automatic bitrate unit conversion MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When switching between Kbps/Mbps/Gbps in the manual bitrate field, automatically convert the numeric value to maintain the same bitrate. Examples: - 8000 Kbps → 8 Mbps - 8000 Kbps → 0.008 Gbps - 8 Mbps → 8000 Kbps Prevents confusion from having nonsensical values like "8000 Mbps" when switching units. --- main.go | 52 +++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 51 insertions(+), 1 deletion(-) diff --git a/main.go b/main.go index 4851aff..caee215 100644 --- a/main.go +++ b/main.go @@ -7388,6 +7388,7 @@ func buildConvertView(state *appState, src *videoSource) fyne.CanvasObject { } var syncingBitrate bool + var previousBitrateUnit = "Kbps" // Track previous unit for conversion updateBitrateState := func() { if syncingBitrate { return @@ -7427,6 +7428,7 @@ func buildConvertView(state *appState, src *videoSource) fyne.CanvasObject { videoBitrateEntry.SetText(num) if unit != "" { videoBitrateUnitSelect.SetSelected(unit) + previousBitrateUnit = unit // Update tracked unit } } else { videoBitrateEntry.SetText(value) @@ -7434,10 +7436,58 @@ func buildConvertView(state *appState, src *videoSource) fyne.CanvasObject { state.convert.VideoBitrate = value } - videoBitrateUnitSelect.OnChanged = func(value string) { + videoBitrateUnitSelect.OnChanged = func(newUnit string) { if manualBitrateRow != nil && manualBitrateRow.Hidden { return } + + // Convert the numeric value when unit changes + if previousBitrateUnit != newUnit { + currentText := strings.TrimSpace(videoBitrateEntry.Text) + if currentText != "" { + if currentValue, err := strconv.ParseFloat(currentText, 64); err == nil { + // Convert from previous unit to new unit + var convertedValue float64 + + // First convert to Kbps (base unit) + var valueInKbps float64 + switch previousBitrateUnit { + case "Kbps": + valueInKbps = currentValue + case "Mbps": + valueInKbps = currentValue * 1000 + case "Gbps": + valueInKbps = currentValue * 1000000 + } + + // Then convert from Kbps to new unit + switch newUnit { + case "Kbps": + convertedValue = valueInKbps + case "Mbps": + convertedValue = valueInKbps / 1000 + case "Gbps": + convertedValue = valueInKbps / 1000000 + } + + // Format the converted value, removing unnecessary decimals + var formattedValue string + if convertedValue == float64(int64(convertedValue)) { + // No decimal part + formattedValue = strconv.FormatInt(int64(convertedValue), 10) + } else { + // Has decimal part - format with precision + formattedValue = strconv.FormatFloat(convertedValue, 'f', -1, 64) + } + + syncingBitrate = true + videoBitrateEntry.SetText(formattedValue) + syncingBitrate = false + } + } + previousBitrateUnit = newUnit + } + updateBitrateState() }