@@ -17,6 +17,7 @@ class Master {
1717 private final Options options = new Options ();
1818
1919 // Files
20+ private static String ffmpegPath = "ffmpeg" ;
2021 private static File [] files ;
2122 private static Boolean isSingle ;
2223 private static File saveFile ;
@@ -40,6 +41,7 @@ class Master {
4041 public Options getOptions () {return options ;}
4142
4243 // Files
44+ public String getFFmpegPath () {return ffmpegPath ;}
4345 public File [] getFiles () {return files ;}
4446 public int getFileCount () {return files .length ;}
4547 public Boolean isSingle () {return isSingle ;}
@@ -59,6 +61,7 @@ private String getChain() {
5961 //////////
6062
6163 // Files
64+ public void setFFmpegPath (String ffmpegPath ) {this .ffmpegPath = ffmpegPath ;}
6265 public void setFiles (File [] files ) {
6366 this .files = files ;
6467 chain = "" ;
@@ -75,8 +78,7 @@ public void setFiles(File[] files) {
7578 // Function to wrap FFmpeg
7679 private void ffmpeg (Boolean post , String [] ffmpeg ) {
7780 try {
78- Runtime runtime = Runtime .getRuntime ();
79- Process process = runtime .exec (ffmpeg );
81+ Process process = new ProcessBuilder (ffmpeg ).start ();
8082 InputStream stderr = process .getErrorStream ();
8183 InputStreamReader stderrReader = new InputStreamReader (stderr );
8284 BufferedReader stderrBufferedReader = new BufferedReader (stderrReader );
@@ -175,9 +177,8 @@ private void ffmpeg(Boolean post, String[] ffmpeg) {
175177 public Boolean ffCheck () {
176178 Boolean err = true ;
177179 try {
178- Runtime runtime = Runtime .getRuntime ();
179- String [] ffmpeg = {"ffmpeg" , "-version" };
180- Process process = runtime .exec (ffmpeg );
180+ String [] ffmpeg = {ffmpegPath , "-version" };
181+ Process process = new ProcessBuilder (ffmpeg ).start ();
181182 process .waitFor ();
182183 } catch (Exception exception ) {
183184 new ErrorDialog (exception .getMessage ());
@@ -189,24 +190,24 @@ public Boolean ffCheck() {
189190 // Function to analyze files
190191 public void analyze (File file ) {
191192 audioInfo = new AudioInfo (file , saveFile , isSingle , export .getExtension ());
192- String [] analyze = {"ffmpeg" , "-hide_banner" , "-i" , file .getPath (), "-vn" , "-sn" , "-dn" , "-filter_complex" , "[0:a]aformat=cl=mono," +getChain ()+"asplit[loudnorm],astats=measure_perchannel=none:measure_overall=Noise_floor+Number_of_samples+Peak_level+RMS_level;[loudnorm]loudnorm=print_format=summary" , "-f" , "null" , "" };
193+ String [] analyze = {ffmpegPath , "-hide_banner" , "-i" , file .getPath (), "-vn" , "-sn" , "-dn" , "-filter_complex" , "[0:a]aformat=cl=mono," +getChain ()+"asplit[loudnorm],astats=measure_perchannel=none:measure_overall=Noise_floor+Number_of_samples+Peak_level+RMS_level;[loudnorm]loudnorm=print_format=summary" , "-f" , "null" , "" };
193194 ffmpeg (false , analyze );
194195 }
195196
196197 // Function check files
197198 public void check (File file ) {
198199 audioInfo = new AudioInfo (file );
199- String [] preCheck = {"ffmpeg" , "-hide_banner" , "-i" , file .getPath (), "-vn" , "-sn" , "-dn" , "-frames:a" , "0" , "-f" , "null" , "" };
200+ String [] preCheck = {ffmpegPath , "-hide_banner" , "-i" , file .getPath (), "-vn" , "-sn" , "-dn" , "-frames:a" , "0" , "-f" , "null" , "" };
200201 ffmpeg (false , preCheck );
201202 String end = String .valueOf (audioInfo .getRoughDuration ()-1 );
202- String [] check = {"ffmpeg" , "-hide_banner" , "-i" , file .getPath (), "-vn" , "-sn" , "-dn" , "-filter_complex" , "[0:a]asplit=3[end][astats],atrim=end=1[start];[end]atrim=start=" +end +",[start]concat=2:0:1,astats=measure_perchannel=none:measure_overall=RMS_level;[astats]astats=measure_perchannel=none:measure_overall=Noise_floor+Number_of_samples+Peak_level+RMS_level" , "-f" , "null" , "" };
203+ String [] check = {ffmpegPath , "-hide_banner" , "-i" , file .getPath (), "-vn" , "-sn" , "-dn" , "-filter_complex" , "[0:a]asplit=3[end][astats],atrim=end=1[start];[end]atrim=start=" +end +",[start]concat=2:0:1,astats=measure_perchannel=none:measure_overall=RMS_level;[astats]astats=measure_perchannel=none:measure_overall=Noise_floor+Number_of_samples+Peak_level+RMS_level" , "-f" , "null" , "" };
203204 ffmpeg (true , check );
204205 }
205206
206207 // Function to predict problems
207208 public void predict (File file ) {
208209 String end = String .valueOf (audioInfo .getRoughDuration ()-1 );
209- String [] predict = {"ffmpeg" , "-hide_banner" , "-i" , file .getPath (), "-vn" , "-sn" , "-dn" , "-filter_complex" , "[0:a]aformat=cl=mono," +getChain ()+"loudnorm=i=" +String .valueOf (targets .getI ())+":lra=" +String .valueOf (targets .getLRA ())+":tp=" +String .valueOf (targets .getTP ())+":measured_I=" +String .valueOf (audioInfo .getII ())+":measured_LRA=" +String .valueOf (audioInfo .getILRA ())+":measured_tp=" +String .valueOf (audioInfo .getITP ())+":measured_thresh=" +String .valueOf (audioInfo .getIT ())+":offset=" +String .valueOf (audioInfo .getTO ())+":print_format=summary" +options .getStereoChain ()+",asplit=3[end][astats],atrim=end=1[start];[end]atrim=start=" +end +",[start]concat=2:0:1,astats=measure_perchannel=none:measure_overall=RMS_level;[astats]astats=measure_perchannel=none:measure_overall=Noise_floor+Number_of_samples+Peak_level+RMS_level" , "-f" , "null" , "" };
210+ String [] predict = {ffmpegPath , "-hide_banner" , "-i" , file .getPath (), "-vn" , "-sn" , "-dn" , "-filter_complex" , "[0:a]aformat=cl=mono," +getChain ()+"loudnorm=i=" +String .valueOf (targets .getI ())+":lra=" +String .valueOf (targets .getLRA ())+":tp=" +String .valueOf (targets .getTP ())+":measured_I=" +String .valueOf (audioInfo .getII ())+":measured_LRA=" +String .valueOf (audioInfo .getILRA ())+":measured_tp=" +String .valueOf (audioInfo .getITP ())+":measured_thresh=" +String .valueOf (audioInfo .getIT ())+":offset=" +String .valueOf (audioInfo .getTO ())+":print_format=summary" +options .getStereoChain ()+",asplit=3[end][astats],atrim=end=1[start];[end]atrim=start=" +end +",[start]concat=2:0:1,astats=measure_perchannel=none:measure_overall=RMS_level;[astats]astats=measure_perchannel=none:measure_overall=Noise_floor+Number_of_samples+Peak_level+RMS_level" , "-f" , "null" , "" };
210211 ffmpeg (true , predict );
211212 }
212213
@@ -216,7 +217,7 @@ public void master(File file) {
216217 int sampleRate ;
217218 if (export .getSampleRate () == 0 ) {sampleRate = audioInfo .getSampleRate ();
218219 } else {sampleRate = export .getSampleRate ();}
219- String [] master = {"ffmpeg" , "-hide_banner" , "-y" , "-i" , file .getPath (), "-vn" , "-sn" , "-dn" , "-filter_complex" , "[0:a]aformat=cl=mono," +getChain ()+"loudnorm=i=" +String .valueOf (targets .getI ())+":lra=" +String .valueOf (targets .getLRA ())+":tp=" +String .valueOf (targets .getTP ())+":measured_I=" +String .valueOf (audioInfo .getII ())+":measured_LRA=" +String .valueOf (audioInfo .getILRA ())+":measured_tp=" +String .valueOf (audioInfo .getITP ())+":measured_thresh=" +String .valueOf (audioInfo .getIT ())+":offset=" +String .valueOf (audioInfo .getTO ())+":print_format=summary" +options .getStereoChain ()+",asplit=4[end][astats][master],atrim=end=1[start];[end]atrim=start=" +end +",[start]concat=2:0:1,astats=measure_perchannel=none:measure_overall=RMS_level[null0];[astats]astats=measure_perchannel=none:measure_overall=Noise_floor+Number_of_samples+Peak_level+RMS_level[null1]" , "-map" , "[master]" , "-ar" , String .valueOf (sampleRate ), "-ab" , String .valueOf (export .getBitRate ()), "-c:a" , export .getCodec (), "-sample_fmt" , export .getBitDepth (), "-compression_level" , String .valueOf (export .getCompressionLevel ()), audioInfo .getSaveFileString (), "-map" , "[null0]" , "-map" , "[null1]" , "-f" , "null" , "" };
220+ String [] master = {ffmpegPath , "-hide_banner" , "-y" , "-i" , file .getPath (), "-vn" , "-sn" , "-dn" , "-filter_complex" , "[0:a]aformat=cl=mono," +getChain ()+"loudnorm=i=" +String .valueOf (targets .getI ())+":lra=" +String .valueOf (targets .getLRA ())+":tp=" +String .valueOf (targets .getTP ())+":measured_I=" +String .valueOf (audioInfo .getII ())+":measured_LRA=" +String .valueOf (audioInfo .getILRA ())+":measured_tp=" +String .valueOf (audioInfo .getITP ())+":measured_thresh=" +String .valueOf (audioInfo .getIT ())+":offset=" +String .valueOf (audioInfo .getTO ())+":print_format=summary" +options .getStereoChain ()+",asplit=4[end][astats][master],atrim=end=1[start];[end]atrim=start=" +end +",[start]concat=2:0:1,astats=measure_perchannel=none:measure_overall=RMS_level[null0];[astats]astats=measure_perchannel=none:measure_overall=Noise_floor+Number_of_samples+Peak_level+RMS_level[null1]" , "-map" , "[master]" , "-ar" , String .valueOf (sampleRate ), "-ab" , String .valueOf (export .getBitRate ()), "-c:a" , export .getCodec (), "-sample_fmt" , export .getBitDepth (), "-compression_level" , String .valueOf (export .getCompressionLevel ()), audioInfo .getSaveFileString (), "-map" , "[null0]" , "-map" , "[null1]" , "-f" , "null" , "" };
220221 ffmpeg (true , master );
221222 }
222223}
0 commit comments