Skip to content

Commit c059a40

Browse files
committed
Target Size Mode: Account for multiple audio tracks
1 parent 958cb23 commit c059a40

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

ff-utils-winforms/UI/Tasks/QuickConvertUi.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -275,14 +275,16 @@ private static int GetVideoBitrate()
275275

276276
if ((QualityMode)Program.mainForm.encQualModeBox.SelectedIndex == QualityMode.TargetMbytes)
277277
{
278-
int audioBps = (int)form.encAudQualUpDown.Value * 1024;
278+
bool aud = !CodecUtils.GetCodec(GetCurrentCodecA()).DoesNotEncode;
279+
int audioTracks = form.streamListBox.CheckedItems.OfType<MediaStreamListEntry>().Where(x => x.Stream.Type == Stream.StreamType.Audio).Count();
280+
int audioBps = aud ? ((int)form.encAudQualUpDown.Value * 1024) * audioTracks : 0;
279281
double durationSecs = TrackList.current.DurationMs / (double)1000;
280282
float targetMbytes = form.encVidQualityBox.Text.GetFloat();
281283
long targetBits = (long)Math.Round(targetMbytes * 8 * 1024 * 1024);
282284
int targetVidBitrate = (int)Math.Floor(targetBits / durationSecs) - audioBps; // Round down since undershooting is better than overshooting here
283285
string brTotal = (((float)targetVidBitrate + audioBps) / 1024).ToString("0.0");
284286
string brVid = ((float)targetVidBitrate / 1024).ToString("0");
285-
string brAud = form.encAudQualUpDown.Value.ToString();
287+
string brAud = ((float)audioBps / 1024).ToString("0");
286288
Logger.Log($"Target Filesize Mode: Using bitrate of {brTotal} kbps ({brVid}k Video, {brAud}k Audio) over {durationSecs.ToString("0.0")} seconds to hit {targetMbytes} megabytes.");
287289
return targetVidBitrate;
288290
}

0 commit comments

Comments
 (0)