9
9
using System . IO ;
10
10
using System . Linq ;
11
11
using System . Reflection ;
12
+ using System . Text . RegularExpressions ;
12
13
using System . Threading . Tasks ;
13
14
using System . Windows . Forms ;
14
15
using System . Windows . Forms . Design ;
@@ -95,7 +96,7 @@ private class Settings
95
96
public Color BackgroundColor { get ; set ; } = Color . Black ;
96
97
public string BackgroundImageFilename { get ; set ; }
97
98
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" } ;
99
100
public int RenderThreads { get ; set ; } = Environment . ProcessorCount ;
100
101
101
102
public MasterAudioSettings MasterAudio { get ; } = new ( ) { IsAutomatic = true , ApplyReplayGain = true } ;
@@ -140,8 +141,8 @@ public void FromControls(SidWizPlusGui form)
140
141
Preview . Enabled = form . PreviewCheckBox . Checked ;
141
142
Preview . Frameskip = ( int ) form . PreviewFrameskip . Value ;
142
143
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" ;
145
146
MasterAudio . IsAutomatic = form . AutogenerateMasterMix . Checked ;
146
147
MasterAudio . ApplyReplayGain = form . MasterMixReplayGain . Checked ;
147
148
MasterAudio . Path = form . MasterAudioPath . Text ;
@@ -1225,5 +1226,52 @@ private void PropertyGrid_SelectedObjectsChanged(object sender, EventArgs e)
1225
1226
PropertyGrid . Visible = PropertyGrid . SelectedObject != null ;
1226
1227
ChannelsHelpLabel . Visible = PropertyGrid . SelectedObject == null ;
1227
1228
}
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
+ }
1228
1276
}
1229
1277
}
0 commit comments