2
0
Эх сурвалжийг харах

Allow to set sample/bitrate when converting wav to mp3/ogg (#1290)

70/V9 1 сар өмнө
parent
commit
7b02e7946e
1 өөрчлөгдсөн 25 нэмэгдсэн , 3 устгасан
  1. 25 3
      hxd/fs/Convert.hx

+ 25 - 3
hxd/fs/Convert.hx

@@ -249,7 +249,19 @@ class ConvertWAV2MP3 extends Convert {
 	}
 
 	override function convert() {
-		command("lame", ["--resample", "44100", "--silent", "-h", srcPath, dstPath]);
+		var args = ["--silent"];
+		var sampleRate = 44100;
+		if(hasParam("samplerate")) {
+			sampleRate = getParam("samplerate");
+		}
+		if(hasParam("bitrate")) {
+			args = args.concat(["-b", Std.string(getParam("bitrate"))]);
+		} else {
+			args.push("-h");
+		}
+		args = args.concat(["--resample", Std.string(sampleRate)]);
+		args = args.concat([srcPath, dstPath]);
+		command("lame", args);
 	}
 
 	static var _ = Convert.register(new ConvertWAV2MP3());
@@ -262,16 +274,26 @@ class ConvertWAV2OGG extends Convert {
 
 	override function convert() {
 		var cmd = "oggenc";
-		var args = ["--resample", "44100", "-Q", srcPath, "-o", dstPath];
 		if (Sys.systemName() == "Windows")
 			cmd = "oggenc2";
+		var args = ["--quiet"];
+		var sampleRate = 44100;
+		if(hasParam("samplerate")) {
+			sampleRate = getParam("samplerate");
+		}
 		if (hasParam("mono")) {
 			var f = sys.io.File.read(srcPath);
 			var wav = new format.wav.Reader(f).read();
 			f.close();
-			if (wav.header.channels >= 2)
+			if (wav.header.channels >= 2) {
 				args.push("--downmix");
+			}
+		}
+		if(hasParam("bitrate")) {
+			args = args.concat(["-b", Std.string(getParam("bitrate"))]);
 		}
+		args = args.concat(["--resample", Std.string(sampleRate)]);
+		args = args.concat([srcPath, "-o", dstPath]);
 		command(cmd, args);
 	}