Skip to content

Commit b77a6e4

Browse files
committed
UI to select codecs based on what FFMPEG supports
1 parent 07d3a97 commit b77a6e4

File tree

4 files changed

+259
-200
lines changed

4 files changed

+259
-200
lines changed

SidWiz/SidWizPlusGUI.Designer.cs

Lines changed: 51 additions & 43 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

SidWiz/SidWizPlusGUI.cs

Lines changed: 51 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
using System.IO;
1010
using System.Linq;
1111
using System.Reflection;
12+
using System.Text.RegularExpressions;
1213
using System.Threading.Tasks;
1314
using System.Windows.Forms;
1415
using System.Windows.Forms.Design;
@@ -95,7 +96,7 @@ private class Settings
9596
public Color BackgroundColor { get; set; } = Color.Black;
9697
public string BackgroundImageFilename { get; set; }
9798
public PreviewSettings Preview { get; } = new() {Enabled = true, Frameskip = 1};
98-
public EncodeSettings EncodeVideo { get; } = new() {Enabled = false, VideoCodec = "h264", AudioCodec = "aac"};
99+
public EncodeSettings EncodeVideo { get; } = new() {Enabled = false, VideoCodec = "libx264", AudioCodec = "aac"};
99100
public int RenderThreads { get; set; } = Environment.ProcessorCount;
100101

101102
public MasterAudioSettings MasterAudio { get; } = new() {IsAutomatic = true, ApplyReplayGain = true};
@@ -140,8 +141,8 @@ public void FromControls(SidWizPlusGui form)
140141
Preview.Enabled = form.PreviewCheckBox.Checked;
141142
Preview.Frameskip = (int) form.PreviewFrameskip.Value;
142143
EncodeVideo.Enabled = form.EncodeCheckBox.Checked;
143-
EncodeVideo.VideoCodec = form.VideoCodec.Text;
144-
EncodeVideo.AudioCodec = form.AudioCodec.Text;
144+
EncodeVideo.VideoCodec = form.VideoCodec.Text.Split([' '], 2).FirstOrDefault() ?? "libx264";
145+
EncodeVideo.AudioCodec = form.AudioCodec.Text.Split([' '], 2).FirstOrDefault() ?? "aac";
145146
MasterAudio.IsAutomatic = form.AutogenerateMasterMix.Checked;
146147
MasterAudio.ApplyReplayGain = form.MasterMixReplayGain.Checked;
147148
MasterAudio.Path = form.MasterAudioPath.Text;
@@ -1225,5 +1226,52 @@ private void PropertyGrid_SelectedObjectsChanged(object sender, EventArgs e)
12251226
PropertyGrid.Visible = PropertyGrid.SelectedObject != null;
12261227
ChannelsHelpLabel.Visible = PropertyGrid.SelectedObject == null;
12271228
}
1229+
1230+
private void VideoCodec_DropDown(object sender, EventArgs e)
1231+
{
1232+
if (!File.Exists(_programSettings.FfmpegPath) || AudioCodec.Items.Count > 0 || VideoCodec.Items.Count > 0)
1233+
{
1234+
return;
1235+
}
1236+
1237+
try
1238+
{
1239+
// We run FFMPEG to find what codecs it supports
1240+
using var process = new ProcessWrapper(_programSettings.FfmpegPath, "-encoders", false, true);
1241+
process.WaitForExit();
1242+
foreach (var grouping in process
1243+
.Lines()
1244+
.Select(x => Regex.Match(x, "^ (?<type>[AV])[^ ]+ (?<name>[^ ]+) +(?<description>.+)$"))
1245+
.Where(m => m.Success && !m.Groups["name"].Value.Contains("="))
1246+
.Select(m => new Codec(m.Groups["type"].Value, m.Groups["description"].Value, m.Groups["name"].Value))
1247+
.GroupBy(c => c.Type))
1248+
{
1249+
var combo = grouping.Key switch
1250+
{
1251+
"A" => AudioCodec,
1252+
"V" => VideoCodec,
1253+
_ => null
1254+
};
1255+
combo?.Items.Clear();
1256+
combo?.Items.AddRange(grouping.OrderBy(x => x.ToString()).ToArray<object>());
1257+
}
1258+
}
1259+
catch (Exception ex)
1260+
{
1261+
MessageBox.Show($"Error querying FFMPEG: {ex.Message}");
1262+
}
1263+
}
1264+
1265+
private record Codec(string Type, string Description, string Name)
1266+
{
1267+
public string Type { get; } = Type;
1268+
public string Description { get; } = Description;
1269+
public string Name { get; } = Name;
1270+
1271+
public override string ToString()
1272+
{
1273+
return $"{Name} {Description}";
1274+
}
1275+
}
12281276
}
12291277
}

0 commit comments

Comments
 (0)